Skip to content

Commit 01b17ae

Browse files
committed
Tests: allow the test suite to run on PHPUnit 8.x and 9.x
Includes: * `composer.json`: widening the PHPUnit requirement to allow for PHPUnit 8.x and PHPUnit 9.x. Note: The recently released PHPUnit 10.x is not (yet) supported as it no longer supports the old-style test suite runner setup. It also would require for the abstract base test cases to be renamed as those classes are no longer allowed to end on `Test`. Refactoring the test suite to allow for PHPUnit 10.x is for a future PR. * Adjusting the PHPUnit configuration to ensure the tests are run in the same way and show all notices/warnings/deprecations on all PHPUnit versions. The default value for a number of configuration options has changed over time. This makes sure they are consistently set to values which are sensible for this codebase, independently of the PHPUnit version on which the tests are run. Includes adding a schema annotation (set to PHPUnit 9.2 as the schema has changed in PHPUnit 9.3, though that won't prevent the tests from running correctly). * GH Actions `test` workflow: removing work-arounds which were in place related to running PHPUnit 7.x on PHP 8.x. * `AllTests`: Adjusting the condition which determines which `TestSuite` file to load to allow for PHPUnit 8.x and 9.x. * Adding the `.phpunit.result.cache` file to `.gitignore`. PHPUnit has a caching feature build in as of PHPUnit 8, so ignore the file that generates to prevent it from being committed. Related to 3395
1 parent 0421e80 commit 01b17ae

File tree

5 files changed

+15
-21
lines changed

5 files changed

+15
-21
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -114,37 +114,20 @@ jobs:
114114

115115
# Install dependencies and handle caching in one go.
116116
# @link https://github.com/marketplace/actions/install-composer-dependencies
117-
- name: Install Composer dependencies - normal
118-
if: ${{ matrix.php < '8.0' }}
117+
- name: Install Composer dependencies
119118
uses: "ramsey/composer-install@v2"
120119
with:
121120
# Bust the cache at least once a month - output format: YYYY-MM.
122121
custom-cache-suffix: $(date -u "+%Y-%m")
123122

124-
# For PHP 8.0+, we need to install with ignore platform reqs as PHPUnit 7 is still used.
125-
- name: Install Composer dependencies - with ignore platform
126-
if: ${{ matrix.php >= '8.0' }}
127-
uses: "ramsey/composer-install@v2"
128-
with:
129-
composer-options: --ignore-platform-reqs
130-
custom-cache-suffix: $(date -u "+%Y-%m")
131-
132123
# Note: The code style check is run multiple times against every PHP version
133124
# as it also acts as an integration test.
134125
- name: 'PHPCS: set the path to PHP'
135126
run: php bin/phpcs --config-set php_path php
136127

137128
- name: 'PHPUnit: run the tests'
138-
if: ${{ matrix.php != '8.1' && matrix.php != '8.2' }}
139129
run: vendor/bin/phpunit tests/AllTests.php
140130

141-
# We need to ignore the config file so that PHPUnit doesn't try to read it.
142-
# The config file causes an error on PHP 8.1+ with PHPunit 7, but it's not needed here anyway
143-
# as we can pass all required settings in the phpunit command.
144-
- name: 'PHPUnit: run the tests on PHP > 8.0'
145-
if: ${{ matrix.php == '8.1' || matrix.php == '8.2' }}
146-
run: vendor/bin/phpunit tests/AllTests.php --no-configuration --bootstrap=tests/bootstrap.php --dont-report-useless-tests
147-
148131
- name: 'PHPCS: check code style without cache, no parallel'
149132
if: ${{ matrix.custom_ini == false && matrix.php != '7.4' }}
150133
run: php bin/phpcs --no-cache --parallel=1

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
.idea/*
55
/vendor/
66
composer.lock
7+
.phpunit.result.cache

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"ext-simplexml": "*"
3333
},
3434
"require-dev": {
35-
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
35+
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0"
3636
},
3737
"bin": [
3838
"bin/phpcs",

phpunit.xml.dist

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit beStrictAboutTestsThatDoNotTestAnything="false" bootstrap="tests/bootstrap.php">
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.2/phpunit.xsd"
5+
backupGlobals="true"
6+
beStrictAboutTestsThatDoNotTestAnything="false"
7+
bootstrap="tests/bootstrap.php"
8+
convertErrorsToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
convertNoticesToExceptions="true"
11+
convertDeprecationsToExceptions="true"
12+
>
313
<testsuites>
414
<testsuite name="PHP_CodeSniffer Test Suite">
515
<file>tests/AllTests.php</file>

tests/AllTests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
$phpunit7 = false;
2525
if (class_exists('\PHPUnit\Runner\Version') === true) {
2626
$version = \PHPUnit\Runner\Version::id();
27-
if ($version[0] === '7') {
27+
if (version_compare($version, '7.0', '>=') === true) {
2828
$phpunit7 = true;
2929
}
3030
}

0 commit comments

Comments
 (0)