WordPress-Coding-Standards/.github/workflows/quicktest.yml
Rodrigo Primo e3da696385
Tests: update to allow for running the tests on PHPCS 4.x
As of PHPCS 4.0, the base sniff test class has been renamed from `AbstractSniffUnitTest` to `AbstractSniffTestCase`. Additionally, the PHPCS test setup no longer uses the outdated custom test suite creation.

This means that to allow for the tests to run on both PHPCS 3.x and 4.x, some changes are needed.

This commit handles this by:
* Changing all test files to `extend` the new test case class and adding a class alias to the test bootstrap for compatibility with PHPCS 3.x.
* Adding separate scripts to the `composer.json` file for invoking the tests on PHPCS 3.x vs 4.x.
* Updating the minimum PHPUnit 9 version to 9.3.4 as required by the PHPCS 4.x native test framework.
* Add GH Actions jobs to test against PHPCS 4.x to all `test` matrices.
* Updating the `quicktest` and `unit-tests` GH Actions jobs to use the correct Composer script based on the installed PHPCS version.
* Run the `basic-qa` code-sniff and ruleset-test jobs against both PHPCS 3.x-dev and 4.x-dev.
* Update `basic-qa` to accept the phpcbf NON_FIXABLE exit code (2) on PHPCS 4.x in the fixer-conflict check. PHPCS 4.0 reworked the phpcbf exit codes into a bitmask.

_Note: even though PHPCS 4.x supports PHPUnit 10 and 11, we cannot widen the version restrictions for PHPUnit (yet) while PHPCS 3.x is also supported as it would lead to PHPUnit 10/11 being installed for PHPCS 3.x on PHP >= 8.1, which would break the test runs._

---------

Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com>
2026-07-17 16:25:20 -03:00

96 lines
3.9 KiB
YAML

name: Quick Tests
on:
push:
branches-ignore:
- main
paths-ignore:
- '**.md'
# Allow manually triggering the workflow.
workflow_dispatch:
# Cancels all previous workflow runs for the same branch that have not yet completed.
concurrency:
# The concurrency group contains the workflow name and the branch name.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
# Performs some quick tests.
# This is a much quicker test suite which only runs the unit tests and linting
# against the low/high supported PHP/PHPCS combinations.
quick-tests:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '7.2', 'latest' ]
dependencies: [ 'lowest', 'stable' ]
name: QTest - PHP ${{ matrix.php }} on PHPCS ${{ matrix.dependencies }}
steps:
- name: Checkout repository
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false
- name: Set up PHP
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2
with:
php-version: ${{ matrix.php }}
# With stable PHPCS dependencies, allow for PHP deprecation notices.
# Unit tests don't need to fail on those for stable releases where those issues won't get fixed anymore.
ini-values: error_reporting=-1, display_errors=On, display_startup_errors=On
coverage: ${{ github.ref_name == 'develop' && 'xdebug' || 'none' }}
- name: Enable creation of `composer.lock` file
if: ${{ matrix.dependencies == 'lowest' }}
run: composer config --unset lock
- name: Install Composer dependencies
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
with:
# Bust the cache at least once a month - output format: YYYY-MM.
custom-cache-suffix: $(date -u "+%Y-%m")
- name: "Composer: downgrade PHPCS dependencies for tests (lowest)"
if: ${{ matrix.dependencies == 'lowest' }}
run: >
composer update --prefer-lowest --no-scripts --no-interaction
squizlabs/php_codesniffer
phpcsstandards/phpcsutils
phpcsstandards/phpcsextra
- name: Lint PHP files against parse errors
if: ${{ matrix.dependencies == 'stable' }}
run: composer lint
- name: Grab PHPCS version
id: phpcs_version
run: echo "VERSION=$(vendor/bin/phpcs --version | grep --only-matching --max-count=1 --extended-regexp '\b[0-9]+\.[0-9]+')" >> "$GITHUB_OUTPUT"
- name: Run the unit tests without code coverage (PHPCS 3.x)
if: ${{ (github.event.repository.fork == true || github.ref_name != 'develop') && startsWith( steps.phpcs_version.outputs.VERSION, '3.' ) }}
run: composer run-tests-phpcs3
- name: Run the unit tests without code coverage (PHPCS 4.x)
if: ${{ (github.event.repository.fork == true || github.ref_name != 'develop') && startsWith( steps.phpcs_version.outputs.VERSION, '4.' ) }}
run: composer run-tests-phpcs4
- name: Run the unit tests with code coverage (PHPCS 3.x)
if: ${{ github.event.repository.fork == false && github.ref_name == 'develop' && startsWith( steps.phpcs_version.outputs.VERSION, '3.' ) }}
run: composer coverage-phpcs3
- name: Run the unit tests with code coverage (PHPCS 4.x)
if: ${{ github.event.repository.fork == false && github.ref_name == 'develop' && startsWith( steps.phpcs_version.outputs.VERSION, '4.' ) }}
run: composer coverage-phpcs4
- name: Send coverage report to Codecov
if: ${{ success() && github.event.repository.fork == false && github.ref_name == 'develop' }}
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f # v7.0.0
with:
files: ./build/logs/clover.xml
fail_ci_if_error: true
verbose: true
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}