Skip to content

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Apr 7, 2025

Description

Other tooling packages will often also polyfill PHP native tokens and are likely to use different values for the token constant (generally an integer above 10.000).

A number of these tools have a habit to autoload the file containing the polyfilled token constants via the Composer autoload - files directives. When this happens, this can interfere with the functioning of PHPCS.

While it will be rare for this to become problematic for normal PHPCS runs (as translation between token constants and their names and visa versa is rarely done in runtime-code), it is definitely something which can cause problems while running the tests for PHPCS itself.

Those type of issues will be hard to debug in the tests as this is a sort of race-condition. So to make it more obvious what is going on if this specific race-condition is happening, I'm going to make it a requirement for all PHP native polyfilled tokens to be tested via the TokenNameTest class.

This will ensure that if the race-condition is happening, that test will fail, providing a valuable clue for solving the other resulting test failure(s).

Suggested changelog entry

N/A

@jrfnl jrfnl added this to the 3.12.2 milestone Apr 7, 2025
@jrfnl
Copy link
Member Author

jrfnl commented Apr 7, 2025

For the record: this race condition is most likely to happen when running the tests using PHPUnit Phar files with the vendor directory not in line with the PHP version + PHPUnit version the tests are being run on.
This is typically a setup used by maintainers of PHPCS, so the chances of anyone else running into are slim, but these extra tests will hopefully safe maintainers some debug time if they do run into it.

Other tooling packages will often also polyfill PHP native tokens and are likely to use different values for the token constant (generally an integer above 10.000).

A number of these tool have a habit to autoload the file containing the polyfilled token constants via the Composer `autoload - files` directives.
When this happens, this can interfere with the functioning of PHPCS.

While it will be rare for this to become problematic for normal PHPCS runs (as translation between token constants and their names and visa versa is rarely done in runtime-code), it is definitely something which can cause problems while running the tests for PHPCS itself.

Those type of issues will be hard to debug in the tests as this is a sort of race-condition. So to make it more obvious what is going on if this specific race-condition is happening, I'm going to make it a requirement for all PHP native polyfilled tokens to be tested via the `TokenNameTest` class.

This will ensure that if the race-condition is happening, that test will fail, providing a valuable clue for solving the other resulting test failure(s).
@jrfnl
Copy link
Member Author

jrfnl commented Apr 7, 2025

Rebased without changes in hopes of finally getting Coveralls to report.

@jrfnl jrfnl force-pushed the feature/tokennametest-always-test-php-native-polyfills branch from 47edd7a to cf0c547 Compare April 7, 2025 16:03
@jrfnl jrfnl merged commit 52651d0 into master Apr 8, 2025
72 checks passed
@jrfnl jrfnl deleted the feature/tokennametest-always-test-php-native-polyfills branch April 8, 2025 03:21
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