Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5b45d93

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 deprecatios/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 1142c60 commit 5b45d93

File tree

5 files changed

+69
-14
lines changed

5 files changed

+69
-14
lines changed

‎.gitattributes‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@
55
# https://www.reddit.com/r/PHP/comments/2jzp6k/i_dont_need_your_tests_in_my_production
66
# https://blog.madewithlove.be/post/gitattributes/
77
#
8-
.gitattributes export-ignore
9-
.gitignore export-ignore
10-
appveyor.yml export-ignore
11-
box.json export-ignore
12-
phpcs.xml.dist export-ignore
13-
phpunit.xml.dist export-ignore
14-
/.github/ export-ignore
15-
/doc/ export-ignore
16-
/tests/ export-ignore
8+
.gitattributes export-ignore
9+
.gitignore export-ignore
10+
appveyor.yml export-ignore
11+
box.json export-ignore
12+
phpcs.xml.dist export-ignore
13+
phpunit.xml.dist export-ignore
14+
phpunit10.xml.dist export-ignore
15+
/.github/ export-ignore
16+
/doc/ export-ignore
17+
/tests/ export-ignore
1718

1819
#
1920
# Auto detect text files and perform LF normalization

‎.github/workflows/test.yml‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,18 @@ jobs:
152152
- name: 'Integration test 2 - linting own code'
153153
run: ./parallel-lint --exclude vendor --exclude tests/fixtures .
154154

155-
- name: 'Run unit tests'
155+
- name: Grab PHPUnit version
156+
id: phpunit_version
157+
run: echo "VERSION=$(vendor/bin/phpunit --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> $GITHUB_OUTPUT
158+
159+
- name: "Run unit tests (PHPUnit < 10)"
160+
if: ${{ ! startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
156161
run: composer test
157162

163+
- name: "Run unit tests (PHPUnit < 10)"
164+
if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
165+
run: composer test10
166+
158167
- uses: actions/download-artifact@v4
159168
with:
160169
name: parallel-lint-phar

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ composer.lock
55
phpcs.xml
66
.phpunit.result.cache
77
phpunit.xml
8+
phpunit10.xml

‎composer.json‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"jakub-onderka/php-parallel-lint": "*"
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-console-highlighter": "0.* || ^1.0",
3131
"php-parallel-lint/php-code-style": "^2.0"
3232
},
@@ -54,10 +54,14 @@
5454
],
5555
"scripts": {
5656
"test": "@php ./vendor/phpunit/phpunit/phpunit --no-coverage",
57-
"coverage": "@php ./vendor/phpunit/phpunit/phpunit"
57+
"test10": "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist --no-coverage",
58+
"coverage": "@php ./vendor/phpunit/phpunit/phpunit",
59+
"coverage10": "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist"
5860
},
5961
"scripts-descriptions": {
60-
"test": "Run all tests!",
61-
"coverage": "Run all tests *with code coverage*"
62+
"test": "Run all tests! ( PHPUnit < 10)",
63+
"test10": "Run all tests! ( PHPUnit 10+)",
64+
"coverage": "Run all tests *with code coverage* ( PHPUnit < 10)",
65+
"coverage10": "Run all tests *with code coverage* ( PHPUnit 10+)"
6266
}
6367
}

‎phpunit10.xml.dist‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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/10.1/phpunit.xsd"
5+
backupGlobals="true"
6+
beStrictAboutTestsThatDoNotTestAnything="true"
7+
bootstrap="./tests/bootstrap.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+
stopOnFailure="false"
19+
>
20+
21+
<testsuites>
22+
<testsuite name="Unittests">
23+
<directory suffix="Test.php">tests/Unit</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+
<text outputFile="php://stdout" showOnlySummary="true"/>
37+
</report>
38+
</coverage>
39+
40+
</phpunit>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /