Skip to content

Commit dce691a

Browse files
committed
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 undesirable 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` and `failOnPhpunitDeprecation`, both of which will default to `false`. 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, 10.0 and 10.1. Most notably: * In PHPUnit 9.3, the manner of specifying the code coverage configuration has changed. * In PHPUnit 10.0, a significant number of attributes of the `<phpunit>` element were removed or renamed. * In PHPUnit 10.1, the manner for specifying the code coverage configuration was changed again. While the `--migrate-configuration` command can upgrade a configuration for the changes in the format made in PHPUnit 9.3 and 10.1, 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: * The `phpunit.xml.dist` file has been renamed to `phpunitlte9.xml.dist` (for PHPUnit <= 9) and a new `phpunit.xml.dist` file has been added for PHPUnit 10+. * The renamed file is set to be excluded from release archives via `.gitattributes` and a potential local overload file for it is set to be ignored by default via the `.gitignore` file. * Additional scripts have been added to the `composer.json` file to run the tests either with the new or the old configuration file. * The GH Actions `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 generic `cacheDirectory` attribute is the recommended replacement (though a CLI option is also available). The new attribute has been added to the PHPUnit 10+ config file and the directory it points to has been added to `.gitignore`. Ref: * https://phpunit.de/announcements/phpunit-11.html * https://phpunit.de/announcements/phpunit-10.html
1 parent 74778f8 commit dce691a

File tree

7 files changed

+86
-16
lines changed

7 files changed

+86
-16
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
/phpcs.xml.dist export-ignore
1212
/phpstan.neon.dist export-ignore
1313
/phpunit.xml.dist export-ignore
14+
/phpunitlte9.xml.dist export-ignore
1415
/phpunit-bootstrap.php export-ignore
1516
/PHPCSDebug/Tests export-ignore
1617
/Tests export-ignore

.github/workflows/quicktest.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,22 @@ jobs:
9696
if: ${{ matrix.phpcs_version == 'dev-master' }}
9797
run: composer check-complete
9898

99+
- name: Grab PHPUnit version
100+
id: phpunit_version
101+
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT
102+
103+
- name: Determine PHPUnit composer script to use
104+
id: phpunit_script
105+
run: |
106+
if [ "${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) || startsWith( steps.phpunit_version.outputs.VERSION, '11.' ) }}" == "true" ]; then
107+
echo 'SUFFIX=' >> $GITHUB_OUTPUT
108+
else
109+
echo 'SUFFIX=-lte9' >> $GITHUB_OUTPUT
110+
fi
111+
99112
- name: Run the unit tests for the PHPCSDebug sniff
100-
run: composer test-sniff
113+
run: composer test-sniff${{ steps.phpunit_script.outputs.SUFFIX }}
101114

102115
- name: Run the unit tests for the DevTools
103116
if: ${{ matrix.phpcs_version == 'dev-master' }}
104-
run: composer test-tools
117+
run: composer test-tools${{ steps.phpunit_script.outputs.SUFFIX }}

.github/workflows/test.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,22 @@ jobs:
150150
if: matrix.phpcs_version == 'dev-master'
151151
run: composer check-complete
152152

153+
- name: Grab PHPUnit version
154+
id: phpunit_version
155+
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT
156+
157+
- name: Determine PHPUnit composer script to use
158+
id: phpunit_script
159+
run: |
160+
if [ "${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) || startsWith( steps.phpunit_version.outputs.VERSION, '11.' ) }}" == "true" ]; then
161+
echo 'SUFFIX=' >> $GITHUB_OUTPUT
162+
else
163+
echo 'SUFFIX=-lte9' >> $GITHUB_OUTPUT
164+
fi
165+
153166
- name: Run the unit tests for the PHPCSDebug sniff
154-
run: composer test-sniff
167+
run: composer test-sniff${{ steps.phpunit_script.outputs.SUFFIX }}
155168

156169
- name: Run the unit tests for the DevTools
157170
if: ${{ matrix.phpcs_version == 'dev-master' }}
158-
run: composer test-tools
171+
run: composer test-tools${{ steps.phpunit_script.outputs.SUFFIX }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
build/
12
deploy/
23
vendor/
34
composer.lock
45
.phpcs.xml
56
phpcs.xml
67
phpunit.xml
8+
phpunitlte9.xml
79
.phpunit.result.cache
810
phpstan.neon

composer.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@
2828
},
2929
"require-dev" : {
3030
"roave/security-advisories" : "dev-master",
31-
"phpunit/phpunit" : "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
31+
"phpunit/phpunit" : "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.5.32 || ^11.3.3",
3232
"php-parallel-lint/php-parallel-lint": "^1.4.0",
3333
"php-parallel-lint/php-console-highlighter": "^1.0.0",
3434
"phpcsstandards/phpcsdevcs": "^1.1.6",
3535
"phpcsstandards/phpcsutils" : "^1.0",
36-
"yoast/phpunit-polyfills": "^1.1"
36+
"yoast/phpunit-polyfills": "^1.1 || ^2.0 || ^3.0"
3737
},
3838
"config": {
3939
"allow-plugins": {
@@ -73,6 +73,15 @@
7373
"test-tools": [
7474
"@php ./vendor/phpunit/phpunit/phpunit --testsuite DevTools"
7575
],
76+
"test-lte9": [
77+
"@php ./vendor/phpunit/phpunit/phpunit -c phpunitlte9.xml.dist"
78+
],
79+
"test-sniff-lte9": [
80+
"@php ./vendor/phpunit/phpunit/phpunit -c phpunitlte9.xml.dist --testsuite DebugSniff"
81+
],
82+
"test-tools-lte9": [
83+
"@php ./vendor/phpunit/phpunit/phpunit -c phpunitlte9.xml.dist --testsuite DevTools"
84+
],
7685
"check-complete": [
7786
"@php ./bin/phpcs-check-feature-completeness ./PHPCSDebug"
7887
]

phpunit.xml.dist

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
5-
backupGlobals="true"
6-
bootstrap="./phpunit-bootstrap.php"
7-
beStrictAboutTestsThatDoNotTestAnything="false"
8-
convertErrorsToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
convertNoticesToExceptions="true"
11-
convertDeprecationsToExceptions="true"
12-
colors="true"
13-
forceCoversAnnotation="true">
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
5+
backupGlobals="true"
6+
bootstrap="./phpunit-bootstrap.php"
7+
beStrictAboutTestsThatDoNotTestAnything="false"
8+
cacheDirectory="build/phpunit-cache"
9+
colors="true"
10+
displayDetailsOnTestsThatTriggerErrors="true"
11+
displayDetailsOnTestsThatTriggerWarnings="true"
12+
displayDetailsOnTestsThatTriggerNotices="true"
13+
displayDetailsOnTestsThatTriggerDeprecations="true"
14+
displayDetailsOnIncompleteTests="true"
15+
displayDetailsOnSkippedTests="true"
16+
displayDetailsOnPhpunitDeprecations="false"
17+
failOnWarning="true"
18+
failOnNotice="true"
19+
failOnDeprecation="true"
20+
failOnPhpunitDeprecation="false"
21+
requireCoverageMetadata="true"
22+
>
1423

1524
<testsuites>
1625
<testsuite name="DebugSniff">

phpunitlte9.xml.dist

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
5+
backupGlobals="true"
6+
bootstrap="./phpunit-bootstrap.php"
7+
beStrictAboutTestsThatDoNotTestAnything="false"
8+
convertErrorsToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
convertNoticesToExceptions="true"
11+
convertDeprecationsToExceptions="true"
12+
colors="true"
13+
forceCoversAnnotation="true">
14+
15+
<testsuites>
16+
<testsuite name="DebugSniff">
17+
<directory suffix="Test.php">./PHPCSDebug/Tests/</directory>
18+
</testsuite>
19+
<testsuite name="DevTools">
20+
<directory suffix="Test.php">./Tests/DocsXsd/</directory>
21+
</testsuite>
22+
</testsuites>
23+
</phpunit>

0 commit comments

Comments
 (0)