Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: allow for PHPUnit 8/9 #2414

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ When you introduce new `public` sniff properties, or your sniff extends a class
* PHP_CodeSniffer 3.8.0 or higher
* PHPCSUtils 1.0.9 or higher
* PHPCSExtra 1.2.1 or higher
* PHPUnit 4.x, 5.x, 6.x or 7.x
* PHPUnit 4.x - 9.x

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

Expand Down Expand Up @@ -85,9 +85,9 @@ phpunit --filter WordPress /path/to/PHP_CodeSniffer/tests/AllTests.php

Expected output:
```
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
PHPUnit 9.6.15 by Sebastian Bergmann and contributors.

Runtime: PHP 7.4.33
Runtime: PHP 8.3.0
Configuration: /WordPressCS/phpunit.xml.dist

......................................................... 57 / 57 (100%)
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/basic-qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ jobs:
custom-cache-suffix: $(date -u "+%Y-%m")

- name: "Set PHPCS version (lowest)"
if: ${{ matrix.phpcs_version == 'lowest' }}
Copy link
Member Author

@jrfnl jrfnl Dec 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shoot! This condition shouldn't have been removed... Must have accidentally happened during one of the rebases....

I will fix this up.

run: composer update squizlabs/php_codesniffer --prefer-lowest --ignore-platform-req=php+ --no-scripts --no-interaction
run: composer update squizlabs/php_codesniffer --prefer-lowest --no-scripts --no-interaction

- name: Test the WordPress-Core ruleset
run: $(pwd)/vendor/bin/phpcs -ps ./Tests/RulesetCheck/class-ruleset-test.inc --standard=WordPress-Core
Expand Down Expand Up @@ -178,7 +177,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: 'latest'
coverage: none
tools: phpstan

Expand Down
27 changes: 7 additions & 20 deletions .github/workflows/quicktest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '5.4', '7.4', 'latest' ]
php: [ '5.4', 'latest' ]
phpcs_version: [ 'lowest', 'dev-master' ]

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

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

- name: Install Composer dependencies (PHP >= 8.0)
if: ${{ matrix.php >= 8.0 || matrix.php == 'latest' }}
uses: ramsey/composer-install@v2
with:
composer-options: --ignore-platform-req=php+
custom-cache-suffix: $(date -u "+%Y-%m")

- name: "Set PHPCS version (lowest)"
if: ${{ matrix.phpcs_version == 'lowest' }}
run: composer update squizlabs/php_codesniffer --prefer-lowest --ignore-platform-req=php+ --no-scripts --no-interaction
Expand All @@ -76,21 +68,16 @@ jobs:
if: ${{ matrix.phpcs_version == 'dev-master' }}
run: composer lint -- --checkstyle

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

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

- name: Run the unit tests without code coverage - PHP >= 8.1
if: ${{ matrix.php == 'latest' }}
run: composer run-tests -- --no-configuration --bootstrap=./Tests/bootstrap.php --dont-report-useless-tests

- name: Send coverage report to Codecov
if: ${{ success() && github.ref_name == 'develop' && matrix.php != 'latest' }}
if: ${{ success() && github.ref_name == 'develop' }}
uses: codecov/codecov-action@v3
with:
files: ./build/logs/clover.xml
Expand Down
30 changes: 8 additions & 22 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '8.0', '8.1', '8.2', '8.3', '8.4' ]
php: [ '5.5', '5.6', '7.0', '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.4' ]
phpcs_version: [ 'lowest', 'dev-master' ]
extensions: [ '' ]
coverage: [false]
Expand All @@ -33,7 +33,6 @@ jobs:
coverage: true # Make sure coverage is recorded for this too.

# Run code coverage builds against high/low PHP and high/low PHPCS.
# Note: Until PHPCS supports PHPUnit 9, we cannot run code coverage on PHP 8.0+.
- php: '5.4'
phpcs_version: 'dev-master'
extensions: ''
Expand All @@ -42,11 +41,11 @@ jobs:
phpcs_version: 'lowest'
extensions: ''
coverage: true
- php: '7.4'
- php: '8.3'
phpcs_version: 'dev-master'
extensions: ''
coverage: true
- php: '7.4'
- php: '8.3'
phpcs_version: 'lowest'
extensions: ''
coverage: true
Expand Down Expand Up @@ -86,20 +85,12 @@ jobs:
if: ${{ matrix.phpcs_version != 'lowest' }}
run: composer require squizlabs/php_codesniffer:"${{ matrix.phpcs_version }}" --no-update --no-scripts --no-interaction

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

- name: Install Composer dependencies (PHP >= 8.0)
if: ${{ matrix.php >= 8.0 }}
uses: ramsey/composer-install@v2
with:
composer-options: --ignore-platform-req=php+
custom-cache-suffix: $(date -u "+%Y-%m")

- name: "Set PHPCS version (lowest)"
if: ${{ matrix.phpcs_version == 'lowest' }}
run: composer update squizlabs/php_codesniffer --prefer-lowest --ignore-platform-req=php+ --no-scripts --no-interaction
Expand All @@ -108,19 +99,14 @@ jobs:
if: ${{ matrix.phpcs_version == 'dev-master' }}
run: composer lint -- --checkstyle | cs2pr

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

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

# Until PHPCS supports PHPUnit 9, we cannot run code coverage on PHP 8.0+.
- name: Run the unit tests without code coverage - PHP >= 8.1
if: ${{ matrix.php >= '8.1' && matrix.coverage == false }}
run: composer run-tests -- --no-configuration --bootstrap=./Tests/bootstrap.php --dont-report-useless-tests

- name: Send coverage report to Codecov
if: ${{ success() && matrix.coverage == true }}
uses: codecov/codecov-action@v3
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 @@ phpunit.xml
phpcs.xml
.phpcs.xml
phpstan.neon
.phpunit.result.cache
2 changes: 1 addition & 1 deletion WordPress/Tests/DB/RestrictedClassesUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class RestrictedClassesUnitTest extends AbstractSniffUnitTest {
* @return void
*/
protected function enhanceGroups() {
parent::setUp();
parent::setUpPrerequisites();

AbstractFunctionRestrictionsSniff::$unittest_groups = array(
'test' => array(
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"require-dev": {
"phpcompatibility/php-compatibility": "^9.0",
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0",
"phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0 || ^8.0 || ^9.0",
"phpcsstandards/phpcsdevtools": "^1.2.0",
"php-parallel-lint/php-parallel-lint": "^1.3.2",
"php-parallel-lint/php-console-highlighter": "^1.0.0"
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
parameters:
#phpVersion: 50400 # Needs to be 70100 or higher... sigh...
phpVersion: 70100 # Needs to be 70100 or higher... sigh...
level: 5
paths:
- WordPress
Expand Down
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
backupGlobals="true"
bootstrap="./Tests/bootstrap.php"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
convertDeprecationsToExceptions="true"
beStrictAboutTestsThatDoNotTestAnything="false"
colors="true"
forceCoversAnnotation="true">
Expand Down
Loading