Skip to content

Commit 3ee3cc8

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. * `composer.json`: remove the script which was specific for PHP 8.1+ * 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`/`quicktest` workflow: removing work-arounds which were in place related to running PHPUnit 7.x on PHP 8.x. * GH Actions `phpstan` workflow: let PHPStan run on the latest PHP version, now there's no need anymore to run it against a lower PHP version to prevent deprecation notices related to the use of an outdated PHPUnit version. * `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. * CONTRIBUTING: remove references to the remove Composer script + instructions which have now become redundant. Related to 3395
1 parent 26384eb commit 3ee3cc8

File tree

7 files changed

+18
-32
lines changed

7 files changed

+18
-32
lines changed

.github/CONTRIBUTING.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ Note: There may be an issue or PR open already. If so, please join the discussio
137137

138138
1. Fork/clone the repository.
139139
2. Run `composer install`.
140-
When installing on PHP >= 8.0, use `composer install --ignore-platform-req=php+`.
141140
3. Create a new branch off the `master` branch to hold your patch.
142141
If there is an open issue associated with your patch, including the issue number in the branch name is good practice.
143142

@@ -152,10 +151,8 @@ To help you with this, a number of convenience scripts are available:
152151
* `composer check-all` will run the `cs` + `test` checks in one go.
153152
* `composer cs` will check for code style violations.
154153
* `composer cbf` will run the autofixers for code style violations.
155-
* `composer test` will run the unit tests (only works when on PHP < 8.1).
156-
* `composer test-php8` will run the unit tests when you are working on PHP 8.1+.
157-
Please note that using a `phpunit.xml` overload config file will not work with this script!
158-
* `composer coverage` will run the unit tests with code coverage (only works when on PHP < 8.1).
154+
* `composer test` will run the unit tests.
155+
* `composer coverage` will run the unit tests with code coverage.
159156
Note: you may want to use a custom `phpunit.xml` overload config file to tell PHPUnit where to place an HTML report.
160157
Alternative run it like so: `composer coverage -- --coverage-html /path/to/report-dir/` to specify the location for the HTML report on the command line.
161158
* `composer build` will build the phpcs.phar and phpcbf.phar files.

.github/workflows/phpstan.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
- name: Install PHP
3131
uses: shivammathur/setup-php@v2
3232
with:
33-
php-version: '7.4'
33+
php-version: 'latest'
3434
coverage: none
3535
tools: phpstan
3636

.github/workflows/test.yml

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,37 +131,20 @@ jobs:
131131
132132
# Install dependencies and handle caching in one go.
133133
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
134-
- name: Install Composer dependencies - normal
135-
if: ${{ matrix.php < '8.0' }}
134+
- name: Install Composer dependencies
136135
uses: "ramsey/composer-install@v2"
137136
with:
138137
# Bust the cache at least once a month - output format: YYYY-MM.
139138
custom-cache-suffix: $(date -u "+%Y-%m")
140139

141-
# For PHP 8.0+, we need to install with ignore platform reqs as PHPUnit 7 is still used.
142-
- name: Install Composer dependencies - with ignore platform
143-
if: ${{ matrix.php >= '8.0' }}
144-
uses: "ramsey/composer-install@v2"
145-
with:
146-
composer-options: --ignore-platform-req=php+
147-
custom-cache-suffix: $(date -u "+%Y-%m")
148-
149140
# Note: The code style check is run multiple times against every PHP version
150141
# as it also acts as an integration test.
151142
- name: 'PHPCS: set the path to PHP'
152143
run: php bin/phpcs --config-set php_path php
153144

154145
- name: 'PHPUnit: run the tests'
155-
if: ${{ matrix.php != '8.1' && matrix.php != '8.2' }}
156146
run: vendor/bin/phpunit tests/AllTests.php
157147

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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/CodeSniffer.conf
22
/phpcs.xml
33
/phpunit.xml
4+
.phpunit.result.cache
45
.idea/*
56
/vendor/
67
composer.lock

composer.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"ext-simplexml": "*"
4141
},
4242
"require-dev": {
43-
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0"
43+
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0"
4444
},
4545
"replace": {
4646
"squizlabs/php_codesniffer": "> 2.0"
@@ -60,10 +60,6 @@
6060
"Composer\\Config::disableProcessTimeout",
6161
"@php ./vendor/phpunit/phpunit/phpunit tests/AllTests.php --no-coverage"
6262
],
63-
"test-php8": [
64-
"Composer\\Config::disableProcessTimeout",
65-
"@php ./vendor/phpunit/phpunit/phpunit tests/AllTests.php --no-configuration --bootstrap=tests/bootstrap.php --dont-report-useless-tests --no-coverage"
66-
],
6763
"coverage": [
6864
"Composer\\Config::disableProcessTimeout",
6965
"@php ./vendor/phpunit/phpunit/phpunit tests/AllTests.php -d max_execution_time=0"
@@ -81,7 +77,6 @@
8177
"cs": "Check for code style violations.",
8278
"cbf": "Fix code style violations.",
8379
"test": "Run the unit tests without code coverage.",
84-
"test-php8": "Run the unit tests without code coverage on PHP 8.1 or higher.",
8580
"coverage": "Run the unit tests with code coverage.",
8681
"build": "Create PHAR files for PHPCS and PHPCBF.",
8782
"check-all": "Run all checks (phpcs, tests)."

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
@@ -18,7 +18,7 @@
1818
$phpunit7 = false;
1919
if (class_exists('\PHPUnit\Runner\Version') === true) {
2020
$version = \PHPUnit\Runner\Version::id();
21-
if ($version[0] === '7') {
21+
if (version_compare($version, '7.0', '>=') === true) {
2222
$phpunit7 = true;
2323
}
2424
}

0 commit comments

Comments
 (0)