Yoast / PHPUnit-Polyfills

Set of polyfills for changed PHPUnit functionality to allow for creating PHPUnit cross-version compatible tests
BSD 3-Clause "New" or "Revised" License
173 stars 13 forks source link

2.x | Tests: add attributes for annotations #189

Closed jrfnl closed 2 months ago

jrfnl commented 2 months ago

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.

However, between PHPUnit 10.0 and PHPUnit 11.3.2, if the failOnDeprecation is set to true (which it is for this library as the builds should fail on deprecations in PHP), builds will also fail on deprecation notices from PHPUnit itself.

This behaviour was (finally) changed in PHPUnit 10.5.32 and 11.3.3 (released this week), but that's insufficient for our needs. For this library running the tests on high/low PHPUnit on each PHP version is imperative. It is also not the job of this library to decide the target PHPUnit versions for the consumer projects, so we cannot raise the minimum PHPUnit 11 version to 11.3.3.

This means that without the attributes, the test runs for the package would fail on PHPUnit 11.0.0 - 11.3.2.

As these attributes are already available in PHPUnit 10, it makes sense then to add them for both the 2.x branch, as well as the (upcoming) 3.x branch.

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.

Tests: add Covers* attributes

This commit adds the Covers* attributes in all the appropriate places.

The @covers annotations remain as code coverage also still needs to be measure on PHP 5.6 - 8.0 using PHPUnit 5.x - 9.x. These can be removed once the codebase has a PHP 8.1/PHPUnit 10 minimum requirement.

Tests: add DataProvider attributes

This commit adds the DataProvider attributes in all the appropriate places.

The @dataProvider annotations remain as the tests also still need to run on PHP 5.6 - 8.0 using PHPUnit 5.x - 9.x. These can be removed once the codebase has a PHP 8.1/PHPUnit 10 minimum requirement.

Tests: add Requires* attributes

This commit adds the Requires* attributes in all the appropriate places.

The @requires annotations remain as the tests also still need to run on PHP 5.6 - 8.0 using PHPUnit 5.x - 9.x. These can be removed once the codebase has a PHP 8.1/PHPUnit 10 minimum requirement.

Tests: add Before/After[Class] attributes

This commit adds the Before/After* attributes in all the appropriate places.

The @before/after* annotations remain as the tests also still need to run on PHP 5.6 - 8.0 using PHPUnit 5.x - 9.x. These can be removed once the codebase has a PHP 8.1/PHPUnit 10 minimum requirement.

coveralls commented 2 months ago

Coverage Status

coverage: 95.846% (+0.01%) from 95.833% when pulling 5cecae1437572a8f8e9258723a2e6fa237e41234 on feature/2.x/add-attributes-for-annotations into da0bf11dab44c8768cab9d1c70f4e81cf69741e8 on 2.x.