Skip to content

Allow for running the tests on PHPUnit 11 #1825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 6, 2025

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 11, 2025

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 and failOnPhpunitDeprecation, both of which will now default to false, 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 the BaseSniffTestCase 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.

jrfnl added 3 commits July 11, 2025 05:38
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` and `failOnPhpunitDeprecation`, both of which will now default to `false`, 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:
* https://github.com/Yoast/PHPUnit-Polyfills/releases/tag/3.0.0
* https://phpunit.de/announcements/phpunit-11.html
* sebastianbergmann/phpunit 5937
…ption

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:
* sebastianbergmann/phpunit 4599
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 the `BaseSniffTestCase` 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.
@jrfnl jrfnl added this to the 10.0.0 milestone Jul 11, 2025
@jrfnl jrfnl requested a review from wimg July 11, 2025 03:50
@jrfnl jrfnl added chores/QA PR: quick merge PR only contains relatively simple changes PR: ready for review labels Jul 11, 2025
@wimg wimg merged commit 9d4f74a into develop Aug 6, 2025
48 checks passed
@wimg wimg deleted the feature/update-for-phpunit-11 branch August 6, 2025 19:38
@github-actions github-actions bot removed PR: quick merge PR only contains relatively simple changes PR: ready for review labels Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants