Skip to content

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jun 13, 2025

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 as well as 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.
  • Add jobs to test against PHPCS 4.x to all test matrices.
  • Updating the quicktest, test and coverage jobs to use the correct Composer script based on the installed PHPCS version.

This commit also adds a step to all three jobs to remove the PHPCSDevCS dependency. This dependency is not needed in the tests and is currently not (yet) compatible with PHPCS 4.x, so it would block the composer install.

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.

Universal/PrecisionAlignment: deprecate JS/CSS support

As of PHPCS 4.0, PHPCS will no longer support scanning of JS/CSS files.

This is the only sniff in PHPCSExtra which supports JS/CSS and that support is hereby deprecated and will be removed in PHPCSExtra 2.0.

Modernize/Dirname: update for PHPCS 4.0

The tokenization of (namespaced) "names" has changed in PHP 8.0 and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization of fully qualified function calls to dirname() to this sniff.

Universal/NoEchoSprintf: update for PHPCS 4.0

The tokenization of (namespaced) "names" has changed in PHP 8.0 and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization of fully qualified function calls to *sprintf() to this sniff.

Universal/NoFQNTrueFalseNull: update for PHPCS 4.0

The tokenization of (namespaced) "names" has changed in PHP 8.0 and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization of fully qualified true/false/null to this sniff.

Universal/KeywordSpacing: update tests for PHPCS 4.0

Two tests from the KeywordSpacingUnitTest.1.inc file involve code which is interpreted differently in PHP < 8.0 vs 8.0 due to the PHP change to tokenize namespaced names as a single token.
Along the same lines, the code samples in the KeywordSpacingUnitTest.2.inc file will also no longer trigger the sniff.

As this change has been polyfilled in PHPCS 4.0, this invalidates those tests when running the sniff on PHPCS 4.0.

This commit moves the original tests from the KeywordSpacingUnitTest.1.inc file to a new KeywordSpacingUnitTest.5.inc file, which will be skipped on PHPCS 4.0. The KeywordSpacingUnitTest.2.inc file will also be skipped.
It also updates the tests in the KeywordSpacingUnitTest.1.inc file to be tests which are PHPCS cross-version compatible.

Universal/LowercaseFunctionConst: update tests for PHPCS 4.0

Two tests from the LowercaseFunctionConst.inc file involve code which is interpreted differently in PHP < 8.0 vs 8.0 due to the PHP change to tokenize namespaced names as a single token.

As this change has been polyfilled in PHPCS 4.0, this invalidates those tests when running the sniff on PHPCS 4.0.

This commit:

  • Renames the LowercaseFunctionConst.inc test case file to LowercaseFunctionConst.1.inc.
  • Moves the original tests to a new LowercaseFunctionConst.2.inc file, which will be skipped on PHPCS 4.0.
  • And updates the tests in the LowercaseFunctionConst.1.inc file to be tests which are PHPCS cross-version compatible.

Universal/NoLeadingBackslash: update for PHPCS 4.0

One test from the NoLeadingBackslashUnitTest.1.inc file involves code which is interpreted differently in PHP < 8.0 vs 8.0 due to the PHP change to tokenize namespaced names as a single token.

As this change has been polyfilled in PHPCS 4.0, this invalidates those tests when running the sniff on PHPCS 4.0.

This commit:

  • Updates the sniff to be PHPCS cross-version compatible.
  • Moves the original tests to a new NoLeadingBackslashUnitTest.6.inc file, which will be skipped on PHPCS 4.0.
  • And updates the tests in the NoLeadingBackslashUnitTest.1.inc file to be tests which are PHPCS cross-version compatible.

Universal/DisallowUseClass: update for PHPCS 4.0

The token walking this sniff did to find the exact token to report the error on needed to be updated to allow for the PHP 8.0 namespaced name as single token change as applied in PHPCS 4.0.

Fixed now.

Universal/DisallowUseConst: update for PHPCS 4.0

The token walking this sniff did to find the exact token to report the error on needed to be updated to allow for the PHP 8.0 namespaced name as single token change as applied in PHPCS 4.0.

Fixed now.

Includes some additional tests.
Includes updating one test to make it cross-version compatible as the original code was not valid since PHP 8.0.

Universal/DisallowUseFunction: update for PHPCS 4.0

The token walking this sniff did to find the exact token to report the error on needed to be updated to allow for the PHP 8.0 namespaced name as single token change as applied in PHPCS 4.0.

Fixed now.

Includes updating one test to make it cross-version compatible as the original code was not valid since PHP 8.0.

Universal/NoUselessAliases: update for PHPCS 4.0

The tokenization of (namespaced) "names" has changed in PHP 8.0 and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for this new tokenization to this sniff.

Includes some additional tests.

Make PHPCS 4 support official

jrfnl added 13 commits June 14, 2025 04:14
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 as well as 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.
* Add jobs to test against PHPCS 4.x to all `test` matrices.
* Updating the `quicktest`, `test` and `coverage` jobs to use the correct Composer script based on the installed PHPCS version.

This commit also adds a step to all three jobs to remove the `PHPCSDevCS` dependency. This dependency is not needed in the tests and is currently not (yet) compatible with PHPCS 4.x, so it would block the `composer install`.

_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._
As of PHPCS 4.0, PHPCS will no longer support scanning of JS/CSS files.

This is the only sniff in PHPCSExtra which supports JS/CSS and that support is hereby deprecated and will be removed in PHPCSExtra 2.0.
The tokenization of (namespaced) "names" has changed in PHP 8.0 and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization of fully qualified function calls to `dirname()` to this sniff.
The tokenization of (namespaced) "names" has changed in PHP 8.0 and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization of fully qualified function calls to `*sprintf()` to this sniff.
The tokenization of (namespaced) "names" has changed in PHP 8.0 and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for the new tokenization of fully qualified `true`/`false`/`null` to this sniff.
Two tests from the `KeywordSpacingUnitTest.1.inc` file involve code which is interpreted differently in PHP < 8.0 vs 8.0 due to the PHP change to tokenize namespaced names as a single token.
Along the same lines, the code samples in the `KeywordSpacingUnitTest.2.inc` file will also no longer trigger the sniff.

As this change has been polyfilled in PHPCS 4.0, this invalidates those tests when running the sniff on PHPCS 4.0.

This commit moves the original tests from the `KeywordSpacingUnitTest.1.inc` file to a new `KeywordSpacingUnitTest.5.inc` file, which will be skipped on PHPCS 4.0. The `KeywordSpacingUnitTest.2.inc` file will also be skipped.
It also updates the tests in the `KeywordSpacingUnitTest.1.inc` file to be tests which are PHPCS cross-version compatible.
Two tests from the `LowercaseFunctionConst.inc` file involve code which is interpreted differently in PHP < 8.0 vs 8.0 due to the PHP change to tokenize namespaced names as a single token.

As this change has been polyfilled in PHPCS 4.0, this invalidates those tests when running the sniff on PHPCS 4.0.

This commit:
* Renames the `LowercaseFunctionConst.inc` test case file to `LowercaseFunctionConst.1.inc`.
* Moves the original tests to a new `LowercaseFunctionConst.2.inc` file, which will be skipped on PHPCS 4.0.
* And updates the tests in the `LowercaseFunctionConst.1.inc` file to be tests which are PHPCS cross-version compatible.
One test from the `NoLeadingBackslashUnitTest.1.inc` file involves code which is interpreted differently in PHP < 8.0 vs 8.0 due to the PHP change to tokenize namespaced names as a single token.

As this change has been polyfilled in PHPCS 4.0, this invalidates those tests when running the sniff on PHPCS 4.0.

This commit:
* Updates the sniff to be PHPCS cross-version compatible.
* Moves the original tests to a new `NoLeadingBackslashUnitTest.6.inc` file, which will be skipped on PHPCS 4.0.
* And updates the tests in the `NoLeadingBackslashUnitTest.1.inc` file to be tests which are PHPCS cross-version compatible.
The token walking this sniff did to find the exact token to report the error on needed to be updated to allow for the PHP 8.0 namespaced name as single token change as applied in PHPCS 4.0.

Fixed now.
The token walking this sniff did to find the exact token to report the error on needed to be updated to allow for the PHP 8.0 namespaced name as single token change as applied in PHPCS 4.0.

Fixed now.

Includes some additional tests.
Includes updating one test to make it cross-version compatible as the original code was not valid since PHP 8.0.
The token walking this sniff did to find the exact token to report the error on needed to be updated to allow for the PHP 8.0 namespaced name as single token change as applied in PHPCS 4.0.

Fixed now.

Includes updating one test to make it cross-version compatible as the original code was not valid since PHP 8.0.
The tokenization of (namespaced) "names" has changed in PHP 8.0 and this new tokenization will come into effect for PHP_CodeSniffer as of version 4.0.0.

This commit adds handling for this new tokenization to this sniff.

Includes some additional tests.
@jrfnl jrfnl force-pushed the feature/phpcs-4.x-compatibility branch from cc72a1a to 881942a Compare June 14, 2025 03:29
@jrfnl jrfnl merged commit 86c3041 into develop Jun 14, 2025
74 checks passed
@jrfnl jrfnl deleted the feature/phpcs-4.x-compatibility branch June 14, 2025 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant