Skip to content

Commit 1960b45

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 8d0de0e commit 1960b45

File tree

5 files changed

+67
-4
lines changed

5 files changed

+67
-4
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33
.gitattributes export-ignore
44
.gitignore export-ignore
55
phpunit.xml.dist export-ignore
6+
phpunit10.xml.dist export-ignore
67
phpcs.xml.dist export-ignore

.github/workflows/test.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,18 @@ jobs:
7878
- name: Lint
7979
run: composer phplint -- --checkstyle | cs2pr
8080

81-
- name: Run unit tests
81+
- name: Grab PHPUnit version
82+
id: phpunit_version
83+
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT
84+
85+
- name: "Run unit tests (PHPUnit < 10)"
86+
if: ${{ ! startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
8287
run: composer phpunit
8388

89+
- name: "Run unit tests (PHPUnit 10+)"
90+
if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
91+
run: composer phpunit10
92+
8493
coverage:
8594
needs: test
8695
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ build
22
vendor
33
composer.lock
44
phpunit.xml
5+
phpunit10.xml
56
.phpunit.result.cache
67
.phpcs.xml
78
phpcs.xml

composer.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"php": ">=5.3.2"
2323
},
2424
"require-dev": {
25-
"phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
25+
"phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.1",
2626
"php-parallel-lint/php-parallel-lint": "^1.0",
2727
"php-parallel-lint/php-var-dump-check": "0.*",
2828
"php-parallel-lint/php-code-style": "^2.0"
@@ -51,9 +51,15 @@
5151
"phpunit": [
5252
"@php ./vendor/phpunit/phpunit/phpunit --no-coverage"
5353
],
54+
"phpunit10": [
55+
"@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist --no-coverage"
56+
],
5457
"coverage": [
5558
"@php ./vendor/phpunit/phpunit/phpunit"
5659
],
60+
"coverage10": [
61+
"@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist"
62+
],
5763
"build": [
5864
"@phplint",
5965
"@vardumpcheck",
@@ -66,8 +72,10 @@
6672
"vardumpcheck": "Check PHP files for forgotten variable dumps",
6773
"phpcs": "Check PHP code style",
6874
"fixcs": "Auto-fix PHP code style",
69-
"phpunit": "PHP unit",
70-
"coverage": "PHP unit with code coverage",
75+
"phpunit": "Run the unit tests on PHPUnit 4.x - 9.x without code coverage.",
76+
"phpunit10": "Run the unit tests on PHPUnit 10.x without code coverage.",
77+
"coverage": "Run the unit tests on PHPUnit 4.x - 9.x with code coverage.",
78+
"coverage10": "Run the unit tests on PHPUnit 10.x with code coverage.",
7179
"build": "Run all checks"
7280
}
7381
}

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-Color">
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)