Skip to content

Commit 2c43c17

Browse files
committedJun 26, 2023
PHPUnit: add separate configuration for PHPUnit 10
PHPUnit 10 makes significant changes to the configuration file. 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 of specifying code coverage has changed again. While there is a `--migrate-configuration` option available in PHPUnit, that doesn't get us a well enough converted configuration file, so instead use a separate `phpunit10.xml.dist` file for running the tests on PHPUnit 10 with an optimal configuration. Includes: * Ignoring the new file for package archives. * Adding separate scripts to the `composer.json` file to make how to run the tests on PHPUnit 10 more obvious for contributors. * Updating the GH Actions workflows to take the new configuration file into account when appropriate.
1 parent 5bbef6d commit 2c43c17

File tree

6 files changed

+69
-10
lines changed

6 files changed

+69
-10
lines changed
 

‎.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ tests/ export-ignore
99
.phpcs.xml.dist export-ignore
1010
phpdoc.dist.xml export-ignore
1111
phpunit.xml.dist export-ignore
12+
phpunit10.xml.dist export-ignore

‎.github/workflows/quicktest.yml

+9-3
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,18 @@ jobs:
9090
- name: Access localhost on port 9002
9191
run: curl -i http://localhost:9002
9292

93-
- name: Show PHPUnit version
94-
run: vendor/bin/phpunit --version
93+
- name: Grab PHPUnit version
94+
id: phpunit_version
95+
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT
9596

96-
- name: Run the unit tests
97+
- name: Run the unit tests (PHPUnit < 10)
98+
if: ${{ ! startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
9799
run: composer test
98100

101+
- name: Run the unit tests (PHPUnit 10+)
102+
if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
103+
run: composer test10
104+
99105
- name: Stop proxy server
100106
continue-on-error: true
101107
run: |

‎.github/workflows/test.yml

+16-7
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,25 @@ jobs:
114114
- name: Access localhost on port 9002
115115
run: curl -i http://localhost:9002
116116

117-
- name: Show PHPUnit version
118-
run: vendor/bin/phpunit --version
117+
- name: Grab PHPUnit version
118+
id: phpunit_version
119+
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT
119120

120-
- name: Run the unit tests, no code coverage
121-
if: ${{ matrix.coverage == false }}
121+
- name: Run the unit tests, no code coverage (PHPUnit < 10)
122+
if: ${{ matrix.coverage == false && ! startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
122123
run: composer test
123124

124-
- name: Run the unit tests with code coverage
125-
if: ${{ matrix.coverage == true }}
126-
run: vendor/bin/phpunit --coverage-clover clover.xml
125+
- name: Run the unit tests, no code coverage (PHPUnit 10+)
126+
if: ${{ matrix.coverage == false && startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
127+
run: composer test10
128+
129+
- name: Run the unit tests with code coverage (PHPUnit < 10)
130+
if: ${{ matrix.coverage == true && ! startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
131+
run: composer coverage -- --coverage-clover clover.xml
132+
133+
- name: Run the unit tests with code coverage (PHPUnit 10+)
134+
if: ${{ matrix.coverage == true && startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
135+
run: composer coverage10 -- --coverage-clover clover.xml
127136

128137
- name: Stop proxy server
129138
continue-on-error: true

‎composer.json

+6
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,14 @@
8484
"test": [
8585
"@php ./vendor/phpunit/phpunit/phpunit --no-coverage"
8686
],
87+
"test10": [
88+
"@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist --no-coverage"
89+
],
8790
"coverage": [
8891
"@php ./vendor/phpunit/phpunit/phpunit"
92+
],
93+
"coverage10": [
94+
"@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist"
8995
]
9096
}
9197
}

‎phpunit.xml.dist

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/7.5/phpunit.xsd"
55
backupGlobals="true"
66
bootstrap="tests/bootstrap.php"
7+
beStrictAboutTestsThatDoNotTestAnything="true"
78
convertDeprecationsToExceptions="true"
89
colors="true"
910
verbose="true"

‎phpunit10.xml.dist

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
bootstrap="tests/bootstrap.php"
7+
beStrictAboutTestsThatDoNotTestAnything="true"
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+
>
19+
<testsuites>
20+
<testsuite name="RequestsTests">
21+
<directory suffix="Test.php">tests</directory>
22+
</testsuite>
23+
</testsuites>
24+
25+
<source>
26+
<include>
27+
<directory suffix=".php">./src/</directory>
28+
</include>
29+
</source>
30+
31+
<coverage includeUncoveredFiles="true" ignoreDeprecatedCodeUnits="true">
32+
<report>
33+
<html outputDirectory="tests/coverage" lowUpperBound="35" highLowerBound="90"/>
34+
</report>
35+
</coverage>
36+
</phpunit>

0 commit comments

Comments
 (0)
Please sign in to comment.