Skip to content

Commit e8ec9a6

Browse files
jrfnlgrogy
authored andcommitted
PHPUnit: allow for PHPUnit 10 + add separate configuration
The PHPunit 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, there is another change related to the code coverage configuration + the ability to fail builds on deprecations/warnings/notices is brought back. 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. As this package is used in the CI pipeline for other packages, it is important for this package to be ready for new PHP releases _early_, so failing the test suite on deprecations/notices and warnings is appropriate. 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. This commit adds this dedicated configuration file for PHPUnit 10.1+. Includes: * Ignoring the new file for package archives. * Allowing for a local override file. * Adding scripts to the `composer.json` file to run the tests using this new configuration file and make the use of the separate config make more obvious for contributors. * Updating the GH Actions `test` workflow to trigger the tests on PHPUnit 10 with this configuration file. Ref: * https://github.com/sebastianbergmann/phpunit/blob/main/ChangeLog-10.0.md#1000---2023-02-03 * sebastianbergmann/phpunit 5196 * sebastianbergmann/phpunit@fb6673f
1 parent 769f5ac commit e8ec9a6

File tree

5 files changed

+77
-5
lines changed

5 files changed

+77
-5
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@
44
.gitignore export-ignore
55
/.github export-ignore
66
phpunit.xml.dist export-ignore
7+
phpunit10.xml.dist export-ignore
78
phpcs.xml.dist export-ignore

.github/workflows/test.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,18 @@ jobs:
7373
- name: Lint
7474
run: composer phplint -- --checkstyle | cs2pr
7575

76-
- name: Run unit tests
76+
- name: Grab PHPUnit version
77+
id: phpunit_version
78+
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT
79+
80+
- name: "Run unit tests (PHPUnit < 10)"
81+
if: ${{ ! startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
7782
run: composer phpunit
7883

84+
- name: "Run unit tests (PHPUnit 10+)"
85+
if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
86+
run: composer phpunit10
87+
7988
coverage:
8089
needs: test
8190
# Don't run on forks.
@@ -124,9 +133,18 @@ jobs:
124133
- name: Lint
125134
run: composer phplint -- --checkstyle | cs2pr
126135

127-
- name: Run the unit tests with code coverage
136+
- name: Grab PHPUnit version
137+
id: phpunit_version
138+
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT
139+
140+
- name: "Run the unit tests with code coverage (PHPUnit < 10)"
141+
if: ${{ ! startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
128142
run: composer coverage
129143

144+
- name: "Run the unit tests with code coverage (PHPUnit 10+)"
145+
if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
146+
run: composer coverage10
147+
130148
- name: Upload coverage results to Coveralls
131149
if: ${{ success() }}
132150
uses: coverallsapp/github-action@v2

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/vendor/
44
/composer.lock
55
phpunit.xml
6+
phpunit10.xml
67
.phpunit.result.cache
78
.phpcs.xml
89
phpcs.xml

composer.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"php-parallel-lint/php-console-color": "^1.0.1"
2727
},
2828
"require-dev": {
29-
"phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
29+
"phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.1",
3030
"php-parallel-lint/php-parallel-lint": "^1.0",
3131
"php-parallel-lint/php-var-dump-check": "0.*",
3232
"php-parallel-lint/php-code-style": "^2.0"
@@ -55,9 +55,15 @@
5555
"phpunit": [
5656
"@php ./vendor/phpunit/phpunit/phpunit --no-coverage"
5757
],
58+
"phpunit10": [
59+
"@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist --no-coverage"
60+
],
5861
"coverage": [
5962
"@php ./vendor/phpunit/phpunit/phpunit"
6063
],
64+
"coverage10": [
65+
"@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist"
66+
],
6167
"build": [
6268
"@phplint",
6369
"@vardumpcheck",
@@ -70,8 +76,10 @@
7076
"vardumpcheck": "Check PHP files for forgotten variable dumps",
7177
"phpcs": "Check PHP code style",
7278
"fixcs": "Auto-fix PHP code style",
73-
"phpunit": "PHP unit",
74-
"coverage": "PHP unit with code coverage",
79+
"phpunit": "Run the unit tests on PHPUnit 4.x - 9.x without code coverage.",
80+
"phpunit10": "Run the unit tests on PHPUnit 10.x without code coverage.",
81+
"coverage": "Run the unit tests on PHPUnit 4.x - 9.x with code coverage.",
82+
"coverage10": "Run the unit tests on PHPUnit 10.x with code coverage.",
7583
"build": "Run all checks"
7684
}
7785
}

phpunit10.xml.dist

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/10.1/phpunit.xsd"
5+
backupGlobals="true"
6+
beStrictAboutTestsThatDoNotTestAnything="true"
7+
bootstrap="./vendor/autoload.php"
8+
colors="true"
9+
displayDetailsOnTestsThatTriggerErrors="true"
10+
displayDetailsOnTestsThatTriggerWarnings="true"
11+
displayDetailsOnTestsThatTriggerNotices="true"
12+
displayDetailsOnTestsThatTriggerDeprecations="true"
13+
displayDetailsOnIncompleteTests="true"
14+
displayDetailsOnSkippedTests="true"
15+
failOnWarning="true"
16+
failOnNotice="true"
17+
failOnDeprecation="true"
18+
requireCoverageMetadata="true"
19+
>
20+
21+
<testsuites>
22+
<testsuite name="PHP-Console-Highlighter">
23+
<directory suffix="Test.php">tests</directory>
24+
</testsuite>
25+
</testsuites>
26+
27+
<source>
28+
<include>
29+
<directory suffix=".php">./src/</directory>
30+
</include>
31+
</source>
32+
33+
<coverage includeUncoveredFiles="true" ignoreDeprecatedCodeUnits="true">
34+
<report>
35+
<clover outputFile="build/logs/clover.xml"/>
36+
<html outputDirectory="build/coverage/"/>
37+
<text outputFile="php://stdout" showOnlySummary="true"/>
38+
</report>
39+
</coverage>
40+
41+
<php>
42+
<ini name="memory_limit" value="256M"/>
43+
</php>
44+
</phpunit>

0 commit comments

Comments
 (0)