Follow up to #3594028: PHPUnit 13.2 - Replace expectExceptionMessage() with expectExceptionMessageIs*()
Problem/Motivation
PHPUnit 13.2 deprecates TestCase::expectExceptionMessage() in favor of TestCase::expectExceptionMessageIs() (stricter) or TestCase::expectExceptionMessageIsOrContains() (equivalent to TestCase::expectExceptionMessage()).
See Improved API for exception message expectations
Proposed resolution
In #3594028: PHPUnit 13.2 - Replace expectExceptionMessage() with expectExceptionMessageIs*() we replaced instances of TestCase::expectExceptionMessage() in core with a forward-compatibility implementation of TestCase::expectExceptionMessageIs().
That is OK on PHPUnit 12, but for PHPUnit 13 there are a number of cases where that is too strict and we should either make the expected message exact, of use the more permissive TestCase::expectExceptionMessageIsOrContains().
Exclude tests from the unit-component test suite and for tests extending directly from TestCase for the moment.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Issue fork drupal-3611073
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3611073-main
changes, plain diff MR !16333
- 3611073-phpunit-13.2--
changes, plain diff MR !16332
Comments
Comment #2
mondrakeComment #6
mondrakeComment #7
quietone commentedSurely this should be on 'main', and the MR is against 'main.
Comment #8
mondrake#7 yes, and that’s the reason I completely messed up the first MR. I cloned the issue from the parent and did not fix the version field.
Comment #9
dcam commentedTo test this MR I upgraded PHPUnit to 13.2 on my local environment, removed the
expectExceptionMessageIs()andexpectExceptionMessageIs()overrides fromDrupalTestCaseTrait, and with the main branch checked out I executed all of the tests changed by the MR. They failed with 84 total failures all of which were related to incorrect exception messages. After applying the MR they passed with no failures.The only aberrant test was
Drupal\Tests\Core\Test\TestDiscoveryTest. That test did not fail on the main branch. But those two edited lines did fail after applying the MR. The same thing happened on multiple test runs. But all of the tests passed on GitLab CI. I haven't been able to figure out the cause for this discrepancy. Do you mind trying to replicate my results? Here's my test output:For what it's worth, all of the changes look OK to me. I didn't see anything to comment about.
Comment #10
mondrake#9 thank you. Yeah the changes in that test seem wrong, at least for PHPUnit 12. Reverted here. Let's check again on PHPUnit 13 when the supporting MR is rebased after this one merged.
Comment #11
dcam commentedGreat, thank you for double-checking it. Now all of the tests pass on the MR. This looks good to me.