Skip to content

Commit b4368d5

Browse files
committed
Tests: allow for PHPUnit 8/9
PHP_CodeSniffer 3.8.0 now allows for running the tests, which are based on the PHPCS native test suite, with PHPUnit 8 and 9. This commit updates the package to take advantage of that. Includes: * Widening the PHPUnit version requirements. * Adding the PHPUnit 8+ cache file to `.gitignore`. * Updating the PHPUnit configuration to make sure that deprecations will always show, even when on a high PHPUnit 9.6 version. * Updating the info in `CONTRIBUTING`. * Simplifications to the `quicktest` and `test` workflows. Also, the code coverage "high" run can now be run against PHP 8.3. * Running PHPStan against PHP `latest` (couldn't previously be done due to the old PHPUnit version). * Minor tweak to the PHPStan config to make sure PHP 8.x specific issues don't get flagged for this codebase. * Removing a no longer needed `--ignore-platform*` argument. * Updating the "setUp" method in one test to call the parent "setUp" method via the new method name. Ref: * PHPCSStandards/PHP_CodeSniffer 59
1 parent 44f3abb commit b4368d5

9 files changed

+28
-50
lines changed

.github/CONTRIBUTING.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ When you introduce new `public` sniff properties, or your sniff extends a class
4242
* PHP_CodeSniffer 3.8.0 or higher
4343
* PHPCSUtils 1.0.9 or higher
4444
* PHPCSExtra 1.2.1 or higher
45-
* PHPUnit 4.x, 5.x, 6.x or 7.x
45+
* PHPUnit 4.x - 9.x
4646

4747
The WordPress Coding Standards use the `PHP_CodeSniffer` native unit test framework for unit testing the sniffs.
4848

@@ -85,9 +85,9 @@ phpunit --filter WordPress /path/to/PHP_CodeSniffer/tests/AllTests.php
8585
8686
Expected output:
8787
```
88-
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
88+
PHPUnit 9.6.15 by Sebastian Bergmann and contributors.
8989
90-
Runtime: PHP 7.4.33
90+
Runtime: PHP 8.3.0
9191
Configuration: /WordPressCS/phpunit.xml.dist
9292
9393
......................................................... 57 / 57 (100%)

.github/workflows/basic-qa.yml

+2-3
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,7 @@ jobs:
127127
custom-cache-suffix: $(date -u "+%Y-%m")
128128

129129
- name: "Set PHPCS version (lowest)"
130-
if: ${{ matrix.phpcs_version == 'lowest' }}
131-
run: composer update squizlabs/php_codesniffer --prefer-lowest --ignore-platform-req=php+ --no-scripts --no-interaction
130+
run: composer update squizlabs/php_codesniffer --prefer-lowest --no-scripts --no-interaction
132131

133132
- name: Test the WordPress-Core ruleset
134133
run: $(pwd)/vendor/bin/phpcs -ps ./Tests/RulesetCheck/class-ruleset-test.inc --standard=WordPress-Core
@@ -180,7 +179,7 @@ jobs:
180179
- name: Install PHP
181180
uses: shivammathur/setup-php@v2
182181
with:
183-
php-version: '7.4'
182+
php-version: 'latest'
184183
coverage: none
185184
tools: phpstan
186185

.github/workflows/quicktest.yml

+7-19
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
runs-on: ubuntu-latest
2424
strategy:
2525
matrix:
26-
php: [ '5.4', '7.4', 'latest' ]
26+
php: [ '5.4', 'latest' ]
2727
phpcs_version: [ 'lowest', 'dev-master' ]
2828

2929
name: QTest - PHP ${{ matrix.php }} on PHPCS ${{ matrix.phpcs_version }}
@@ -54,20 +54,12 @@ jobs:
5454
if: ${{ matrix.phpcs_version != 'lowest' }}
5555
run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction
5656

57-
- name: Install Composer dependencies (PHP < 8.0 )
58-
if: ${{ matrix.php < 8.0 && matrix.php != 'latest' }}
57+
- name: Install Composer dependencies
5958
uses: ramsey/composer-install@v2
6059
with:
6160
# Bust the cache at least once a month - output format: YYYY-MM.
6261
custom-cache-suffix: $(date -u "+%Y-%m")
6362

64-
- name: Install Composer dependencies (PHP >= 8.0)
65-
if: ${{ matrix.php >= 8.0 || matrix.php == 'latest' }}
66-
uses: ramsey/composer-install@v2
67-
with:
68-
composer-options: --ignore-platform-req=php+
69-
custom-cache-suffix: $(date -u "+%Y-%m")
70-
7163
- name: "Set PHPCS version (lowest)"
7264
if: ${{ matrix.phpcs_version == 'lowest' }}
7365
run: composer update squizlabs/php_codesniffer --prefer-lowest --ignore-platform-req=php+ --no-scripts --no-interaction
@@ -76,21 +68,17 @@ jobs:
7668
if: ${{ matrix.phpcs_version == 'dev-master' }}
7769
run: composer lint -- --checkstyle
7870

79-
- name: Run the unit tests without code coverage - PHP 5.4 - 8.0
80-
if: ${{ matrix.php == '5.4' && github.ref_name != 'develop' }}
71+
- name: Run the unit tests without code coverage
72+
if: ${{ github.ref_name != 'develop' }}
8173
run: composer run-tests
8274

8375
# Until PHPCS supports PHPUnit 9, we cannot run code coverage on PHP 8.0+, so run it on PHP 5.4 and 7.4.
84-
- name: Run the unit tests with code coverage - PHP 5.4 - 8.0
85-
if: ${{ matrix.php != 'latest' && github.ref_name == 'develop' }}
76+
- name: Run the unit tests with code coverage
77+
if: ${{ github.ref_name == 'develop' }}
8678
run: composer coverage
8779

88-
- name: Run the unit tests without code coverage - PHP >= 8.1
89-
if: ${{ matrix.php == 'latest' }}
90-
run: composer run-tests -- --no-configuration --bootstrap=./Tests/bootstrap.php --dont-report-useless-tests
91-
9280
- name: Send coverage report to Codecov
93-
if: ${{ success() && github.ref_name == 'develop' && matrix.php != 'latest' }}
81+
if: ${{ success() && github.ref_name == 'develop' }}
9482
uses: codecov/codecov-action@v3
9583
with:
9684
files: ./build/logs/clover.xml

.github/workflows/unit-tests.yml

+8-22
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
runs-on: ubuntu-latest
2222
strategy:
2323
matrix:
24-
php: [ '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '8.0', '8.1', '8.2', '8.3', '8.4' ]
24+
php: [ '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.4' ]
2525
phpcs_version: [ 'lowest', 'dev-master' ]
2626
extensions: [ '' ]
2727
coverage: [false]
@@ -33,7 +33,6 @@ jobs:
3333
coverage: true # Make sure coverage is recorded for this too.
3434

3535
# Run code coverage builds against high/low PHP and high/low PHPCS.
36-
# Note: Until PHPCS supports PHPUnit 9, we cannot run code coverage on PHP 8.0+.
3736
- php: '5.4'
3837
phpcs_version: 'dev-master'
3938
extensions: ''
@@ -42,11 +41,11 @@ jobs:
4241
phpcs_version: 'lowest'
4342
extensions: ''
4443
coverage: true
45-
- php: '7.4'
44+
- php: '8.3'
4645
phpcs_version: 'dev-master'
4746
extensions: ''
4847
coverage: true
49-
- php: '7.4'
48+
- php: '8.3'
5049
phpcs_version: 'lowest'
5150
extensions: ''
5251
coverage: true
@@ -86,20 +85,12 @@ jobs:
8685
if: ${{ matrix.phpcs_version != 'lowest' }}
8786
run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction
8887

89-
- name: Install Composer dependencies (PHP < 8.0 )
90-
if: ${{ matrix.php < 8.0 }}
88+
- name: Install Composer dependencies
9189
uses: ramsey/composer-install@v2
9290
with:
9391
# Bust the cache at least once a month - output format: YYYY-MM.
9492
custom-cache-suffix: $(date -u "+%Y-%m")
9593

96-
- name: Install Composer dependencies (PHP >= 8.0)
97-
if: ${{ matrix.php >= 8.0 }}
98-
uses: ramsey/composer-install@v2
99-
with:
100-
composer-options: --ignore-platform-req=php+
101-
custom-cache-suffix: $(date -u "+%Y-%m")
102-
10394
- name: "Set PHPCS version (lowest)"
10495
if: ${{ matrix.phpcs_version == 'lowest' }}
10596
run: composer update squizlabs/php_codesniffer --prefer-lowest --ignore-platform-req=php+ --no-scripts --no-interaction
@@ -108,19 +99,14 @@ jobs:
10899
if: ${{ matrix.phpcs_version == 'dev-master' }}
109100
run: composer lint -- --checkstyle | cs2pr
110101

111-
- name: Run the unit tests without code coverage - PHP 5.4 - 8.0
112-
if: ${{ matrix.php < '8.1' && matrix.coverage == false }}
102+
- name: Run the unit tests without code coverage
103+
if: ${{ matrix.coverage == false }}
113104
run: composer run-tests
114105

115-
- name: Run the unit tests with code coverage - PHP 5.4 - 8.0
116-
if: ${{ matrix.php < '8.1' && matrix.coverage == true }}
106+
- name: Run the unit tests with code coverage
107+
if: ${{ matrix.coverage == true }}
117108
run: composer coverage
118109

119-
# Until PHPCS supports PHPUnit 9, we cannot run code coverage on PHP 8.0+.
120-
- name: Run the unit tests without code coverage - PHP >= 8.1
121-
if: ${{ matrix.php >= '8.1' && matrix.coverage == false }}
122-
run: composer run-tests -- --no-configuration --bootstrap=./Tests/bootstrap.php --dont-report-useless-tests
123-
124110
- name: Send coverage report to Codecov
125111
if: ${{ success() && matrix.coverage == true }}
126112
uses: codecov/codecov-action@v3

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ phpunit.xml
55
phpcs.xml
66
.phpcs.xml
77
phpstan.neon
8+
.phpunit.result.cache

WordPress/Tests/DB/RestrictedClassesUnitTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ final class RestrictedClassesUnitTest extends AbstractSniffUnitTest {
3737
* @return void
3838
*/
3939
protected function enhanceGroups() {
40-
parent::setUp();
40+
parent::setUpPrerequisites();
4141

4242
AbstractFunctionRestrictionsSniff::$unittest_groups = array(
4343
'test' => array(

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"require-dev": {
2929
"phpcompatibility/php-compatibility": "^9.0",
30-
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0",
30+
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
3131
"phpcsstandards/phpcsdevtools": "^1.2.0",
3232
"php-parallel-lint/php-parallel-lint": "^1.3.2",
3333
"php-parallel-lint/php-console-highlighter": "^1.0.0"

phpstan.neon.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
#phpVersion: 50400 # Needs to be 70100 or higher... sigh...
2+
phpVersion: 70100 # Needs to be 70100 or higher... sigh...
33
level: 5
44
paths:
55
- WordPress

phpunit.xml.dist

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
55
backupGlobals="true"
66
bootstrap="./Tests/bootstrap.php"
7+
convertErrorsToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
convertNoticesToExceptions="true"
10+
convertDeprecationsToExceptions="true"
711
beStrictAboutTestsThatDoNotTestAnything="false"
812
colors="true"
913
forceCoversAnnotation="true">

0 commit comments

Comments
 (0)