Skip to content

Commit

Permalink
PHPUnit: allow for PHPUnit 10 + add separate configuration
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jrfnl committed Mar 27, 2024
1 parent 05bb345 commit 57f97e5
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 14 deletions.
19 changes: 10 additions & 9 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
# https://www.reddit.com/r/PHP/comments/2jzp6k/i_dont_need_your_tests_in_my_production
# https://blog.madewithlove.be/post/gitattributes/
#
.gitattributes export-ignore
.gitignore export-ignore
appveyor.yml export-ignore
box.json export-ignore
phpcs.xml.dist export-ignore
phpunit.xml.dist export-ignore
/.github/ export-ignore
/doc/ export-ignore
/tests/ export-ignore
.gitattributes export-ignore
.gitignore export-ignore
appveyor.yml export-ignore
box.json export-ignore
phpcs.xml.dist export-ignore
phpunit.xml.dist export-ignore
phpunit10.xml.dist export-ignore
/.github/ export-ignore
/doc/ export-ignore
/tests/ export-ignore

#
# Auto detect text files and perform LF normalization
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,18 @@ jobs:
- name: 'Integration test 2 - linting own code'
run: ./parallel-lint --exclude vendor --exclude tests/fixtures .

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

- name: "Run unit tests (PHPUnit < 10)"
if: ${{ ! startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
run: composer test

- name: "Run unit tests (PHPUnit < 10)"
if: ${{ startsWith( steps.phpunit_version.outputs.VERSION, '10.' ) }}
run: composer test10

- uses: actions/download-artifact@v4
with:
name: parallel-lint-phar
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ composer.lock
phpcs.xml
.phpunit.result.cache
phpunit.xml
phpunit10.xml
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"jakub-onderka/php-parallel-lint": "*"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
"phpunit/phpunit": "^4.8.36 || ^5.7.21 || ^6.0 || ^7.0 || ^8.0 || ^9.0 || ^10.1",
"php-parallel-lint/php-console-highlighter": "0.* || ^1.0",
"php-parallel-lint/php-code-style": "^2.0"
},
Expand Down Expand Up @@ -50,10 +50,14 @@
],
"scripts": {
"test": "@php ./vendor/phpunit/phpunit/phpunit --no-coverage",
"coverage": "@php ./vendor/phpunit/phpunit/phpunit"
"test10": "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist --no-coverage",
"coverage": "@php ./vendor/phpunit/phpunit/phpunit",
"coverage10": "@php ./vendor/phpunit/phpunit/phpunit -c phpunit10.xml.dist"
},
"scripts-descriptions": {
"test": "Run all tests!",
"coverage": "Run all tests *with code coverage*"
"test": "Run all tests! ( PHPUnit < 10)",
"test10": "Run all tests! ( PHPUnit 10+)",
"coverage": "Run all tests *with code coverage* ( PHPUnit < 10)",
"coverage10": "Run all tests *with code coverage* ( PHPUnit 10+)"
}
}
40 changes: 40 additions & 0 deletions phpunit10.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
backupGlobals="true"
beStrictAboutTestsThatDoNotTestAnything="true"
bootstrap="./tests/bootstrap.php"
colors="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerWarnings="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
failOnWarning="true"
failOnNotice="true"
failOnDeprecation="true"
stopOnFailure="false"
>

<testsuites>
<testsuite name="Unittests">
<directory suffix="Test.php">tests/Unit</directory>
</testsuite>
</testsuites>

<source>
<include>
<directory suffix=".php">./src/</directory>
</include>
</source>

<coverage includeUncoveredFiles="true" ignoreDeprecatedCodeUnits="true">
<report>
<clover outputFile="build/logs/clover.xml"/>
<text outputFile="php://stdout" showOnlySummary="true"/>
</report>
</coverage>

</phpunit>

0 comments on commit 57f97e5

Please sign in to comment.