Tests: allow for running on PHPUnit 10/11 #328
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
UnusedFollowedByRequire: fix up test class name
PHPUnit 10+ is stricter about naming conventions, so the test class name must now match the file name and the class should end on
Test
.Tests: allow for running on PHPUnit 10/11
Until now, the tests would run on PHPUnit 9 for PHP 7.3 and higher.
PHPUnit 10 (PHP 8.1+) was released in February 2023, PHPUnit 11 (PHP 8.2+) in February 2024 and the update for this test suite is quite painless, so let's allow for running the tests on PHPUnit 10 and 11.
This commit actions this.
Things to be aware of:
Handling of PHPUnit deprecations
Prior to PHPUnit 10.5.32 and PHPUnit 11.3.3, if the
failOnDeprecation
attribute was set (previously:convertDeprecationsToExceptions
), tests runs would not only fail on PHP deprecation notices, but also on PHPUnit native deprecation notices when running on PHPUnit 10/11.This undesireable behaviour has now (finally) been reverted, which makes updating test suites for compatibility with PHPUnit 10/11 a lot more straight-forward.
This is the reason that the minimum PHPUnit 10/11 versions in the
composer.json
file are set to such specific versions.As part of this change, PHPUnit 10.5.32 and 11.3.3 introduce two new options for both the configuration file and as CLI arguments:
displayDetailsOnPhpunitDeprecations
andfailOnPhpunitDeprecation
, both of which will default tofalse
.These options have been added to the PHPUnit configuration for PHPUnit 10/11 to safeguard them against changes in the default value.
Test configuration file changes
The configuration file specification has undergone changes in PHPUnit 9.3 and 10.0.
Most notably:
<phpunit>
element were removed or renamed.While the
--migrate-configuration
command can upgrade a configuration for the changes in the format made in PHPUnit 9.3, some of the changes in the configuration format in PHPUnit 10 don't have one-on-one replacements and/or are not taken into account.With that in mind, I deem it more appropriate to have a dedicated PHPUnit configuration file for PHPUnit 10+ to ensure the test run will behave as intended.
To that end:
phpunit.xml.dist
file has been renamed tophpunitlte9.xml.dist
(for PHPUnit <= 9) and a newphpunit.xml.dist
file has been added for PHPUnit 10+..gitattributes
and a potential local overload file for it is set to be ignored by default via the.gitignore
file.composer.json
file to run the tests either with the new or the old configuration file.test
workflow has been updated to select the correct configuration file based on the PHPUnit version on which the tests are being run.Other command/config changes
Also note that the
--coverage-cache <dir>
CLI flag was deprecated in PHPUnit 10 and removed in PHPUnit 11. A genericcacheDirectory
attribute is the recommended replacement (though a CLI option is also available).The new attribute has been added to the PHPUnit 10+ config file, while for PHPUnit 9.3 - 9.5, the flag is still added to the command in CI (as adding the PHPUnit 9.3 equivalent to the config file would make the config incompatible with PHPUnit < 9.3).
Composer will not install PHPUnit 11
Psalm 5 has a dependency on PHP-Parser 4, while PHPUnit 11 requires PHP-Parser 5, so Psalm currently effectively blocks the installation of PHPUnit 11 via Composer.
Running the tests on PHPUnit 11 will work fine though (tested with a PHAR file).
Ref: