Allow for running the tests on PHPUnit 11 #1825
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.
Composer: update the PHPUnit Polyfills to v 3.0 and allow for PHPUnit 11
A PHPUnit 11 compatible version of the PHPUnit Polyfills has been released and the
UtilityMethodTestCase
from PHPCSUtils is also fully compatible with PHPUnit 11, so let's start using it.Mind: PHPUnit 11 throws (~1000) deprecation notices about the use of annotations instead of attributes.
On PHPUnit < 10.5.32 and PHPUnit < 11.3.3, these deprecation notices would fail the test run.
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 now default tofalse
, which means the test runs will no longer fail, making the update viable.These options have been added to the PHPUnit configuration for PHPUnit 10/11 to safeguard them against changes in the default value.
Includes updating the GitHub Actions workflows to use the correct PHPUnit config file based on the PHPUnit version (and allowing for PHPUnit 11).
Ref:
GH Actions/PHPUnit config: deal with removed --coverage-cache CLI option
The
--coverage-cache
flag was silently deprecated in PHPUnit 10 and has been removed in PHPUnit 11.The
--cache-directory
flag replaces it and can also be set in the XML file.This commit removes the outdated flag from the commands used in GH Actions and adds the attribute to the PHPUnit config file.
Ref:
BaseSniffTestCase: add Before/After[Class] attributes
PHPUnit 10 introduced attributes as replacements for docblock annotations.
PHPUnit 11 deprecates the use of docblock annotations in favour of attributes.
If both an attribute as well as an annotation are found, no PHPUnit deprecation warning will be thrown.
While not strictly necessary yet, this commit adds the
Before/After*
attributes in theBaseSniffTestCase
class to reduce the amount of deprecation notices somewhat (Before: > 1050, after: ~694).The rest of the "annotations to attributes" conversion for the test suite is left for the update to PHPUnit 12 (if and when).
Note: The
@before/after*
annotations remain as the tests also still need to run on PHP 5.4 - 8.0 using PHPUnit 4.x - 9.x.These can be removed once the codebase has a PHP 8.1/PHPUnit 10 minimum requirement.
Alternatively, once support for PHP < 7.2 / PHPUnit < 8.0 is dropped, the fixture methods can be reverted to use the canonical
setUp/tearDown[BeforeClass|AfterClass]
names again.Note: due to the syntax for attributes, these can be safely added as they are ignored as comments on PHP < 8.0.
Along the same line, if there is no "listener" for the attributes (PHP 8.0/PHPUnit 9.x), they are ignored by PHP as well.