Skip to content

Commit

Permalink
Tests: allow for PHPUnit 8/9
Browse files Browse the repository at this point in the history
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 PHP 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).
* Updating the `unit-tests` script to remove the PHP version based toggle, which is no longer needed.

Ref:
* PHPCSStandards/PHP_CodeSniffer 59
  • Loading branch information
jrfnl committed Feb 11, 2024
1 parent 550ec3c commit 83d152e
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 55 deletions.
6 changes: 3 additions & 3 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ When you introduce new `public` sniff properties, or your sniff extends a class
* WordPress-Coding-Standards
* PHPCSUtils 1.x
* PHP_CodeSniffer 3.x
* PHPUnit 4.x, 5.x, 6.x or 7.x
* PHPUnit 4.x - 9.x

The VIP Coding Standards use the PHP_CodeSniffer native unit test suite for unit testing the sniffs.

Expand All @@ -106,7 +106,7 @@ N.B.: If you installed VIPCS using Composer, make sure you used `--prefer-source
If you already have PHPUnit installed on your system: Congrats, you're all set.

If not, you can navigate to the directory where the `PHP_CodeSniffer` repo is checked out and do `composer install` to install the `dev` dependencies.
Alternatively, you can [install PHPUnit](https://phpunit.readthedocs.io/en/7.5/installation.html) as a PHAR file.
Alternatively, you can [install PHPUnit](https://phpunit.readthedocs.io/en/9.6/installation.html) as a PHAR file.

### Before running the unit tests

Expand Down Expand Up @@ -146,7 +146,7 @@ The easiest way to do this is to add a `phpunit.xml` file to the root of your VI

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

........................................ 40 / 40 (100%)

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/basics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: 'latest'
coverage: none
tools: phpstan

Expand Down
24 changes: 2 additions & 22 deletions .github/workflows/quicktest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,14 @@ jobs:

# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
- name: Install Composer dependencies - normal
if: ${{ startsWith( matrix.php, '8' ) == false && 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")

# PHPUnit 7.x does not allow for installation on PHP 8, so ignore platform
# requirements to get PHPUnit 7.x to install on nightly.
- name: Install Composer dependencies - with ignore platform
if: ${{ startsWith( matrix.php, '8' ) || matrix.php == 'latest' }}
uses: "ramsey/composer-install@v2"
with:
composer-options: --ignore-platform-req=php+
custom-cache-suffix: $(date -u "+%Y-%m")

- name: "Composer: downgrade PHPCS dependencies for tests (lowest)"
if: ${{ matrix.php == '5.4' && matrix.dependencies == 'lowest' }}
if: ${{ matrix.dependencies == 'lowest' }}
run: >
composer update --prefer-lowest --no-scripts --no-interaction
squizlabs/php_codesniffer
Expand All @@ -79,16 +69,6 @@ jobs:
sirbrillig/phpcs-variable-analysis
wp-coding-standards/wpcs
- name: "Composer: downgrade PHPCS dependencies for tests (lowest) - with ignore platform"
if: ${{ matrix.php == 'latest' && matrix.dependencies == 'lowest' }}
run: >
composer update --prefer-lowest --no-scripts --no-interaction --ignore-platform-req=php+
squizlabs/php_codesniffer
phpcsstandards/phpcsutils
phpcsstandards/phpcsextra
sirbrillig/phpcs-variable-analysis
wp-coding-standards/wpcs
- name: Display PHPCS installed standards
run: ./vendor/bin/phpcs -i

Expand Down
24 changes: 2 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,24 +125,14 @@ jobs:
# Install dependencies and handle caching in one go.
# @link https://github.com/marketplace/actions/install-php-dependencies-with-composer
- name: Install Composer dependencies - normal
if: ${{ startsWith( matrix.php, '8' ) == false }}
- 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")

# PHPUnit 7.x does not allow for installation on PHP 8, so ignore platform
# requirements to get PHPUnit 7.x to install on nightly.
- name: Install Composer dependencies - with ignore platform
if: ${{ startsWith( matrix.php, '8' ) }}
uses: "ramsey/composer-install@v2"
with:
composer-options: --ignore-platform-req=php+
custom-cache-suffix: $(date -u "+%Y-%m")

- name: "Composer: downgrade PHPCS dependencies for tests (lowest)"
if: ${{ ! startsWith( matrix.php, '8' ) && matrix.dependencies == 'lowest' }}
if: ${{ matrix.dependencies == 'lowest' }}
run: >
composer update --prefer-lowest --no-scripts --no-interaction
squizlabs/php_codesniffer
Expand All @@ -151,16 +141,6 @@ jobs:
sirbrillig/phpcs-variable-analysis
wp-coding-standards/wpcs
- name: "Composer: downgrade PHPCS dependencies for tests (lowest) - with ignore platform"
if: ${{ startsWith( matrix.php, '8' ) && matrix.dependencies == 'lowest' }}
run: >
composer update --prefer-lowest --no-scripts --no-interaction --ignore-platform-req=php+
squizlabs/php_codesniffer
phpcsstandards/phpcsutils
phpcsstandards/phpcsextra
sirbrillig/phpcs-variable-analysis
wp-coding-standards/wpcs
- name: Run the unit tests
run: ./bin/unit-tests

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ phpcs.xml
phpunit.xml
phpcs.cache
phpstan.neon
.phpunit.result.cache
6 changes: 1 addition & 5 deletions bin/unit-tests
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,4 @@
# ./bin/unit-tests --filter SniffName
#

if [[ $(php -r 'echo PHP_VERSION_ID;') -ge 80100 ]]; then
"$(pwd)/vendor/bin/phpunit" --filter=WordPressVIPMinimum "$(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php" --no-coverage --no-configuration --bootstrap=./tests/bootstrap.php --dont-report-useless-tests $@
else
"$(pwd)/vendor/bin/phpunit" --filter=WordPressVIPMinimum "$(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php" --no-coverage $@
fi
"$(pwd)/vendor/bin/phpunit" --filter WordPressVIPMinimum "$(pwd)/vendor/squizlabs/php_codesniffer/tests/AllTests.php" --no-coverage $@
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"php-parallel-lint/php-console-highlighter": "^1.0.0",
"phpcompatibility/php-compatibility": "^9",
"phpcsstandards/phpcsdevtools": "^1.0",
"phpunit/phpunit": "^4 || ^5 || ^6 || ^7"
"phpunit/phpunit": "^4 || ^5 || ^6 || ^7 || ^8 || ^9"
},
"config": {
"allow-plugins": {
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:
- WordPressVIPMinimum
Expand Down
4 changes: 4 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
backupGlobals="true"
bootstrap="./tests/bootstrap.php"
beStrictAboutTestsThatDoNotTestAnything="false"
convertErrorsToExceptions="true"
convertWarningsToExceptions="true"
convertNoticesToExceptions="true"
convertDeprecationsToExceptions="true"
forceCoversAnnotation="true"
colors="true"
>
Expand Down

0 comments on commit 83d152e

Please sign in to comment.