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

UtilityMethodTestCase: new usesPhp8NameTokens() method #200

Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Sep 13, 2020

In PHP 8.0 identifier name tokenization will change as outline in the accepted RFC "Treat namespaced names as single token".

When the PHP 8.0 identifier name tokenization is used, the target token to find for some tests will need to be a different token - for instance: T_STRING vs T_FULLY_QUALIFIED_NAME -.
Along the same lines, the expected token positions in the return value of various functions will also be different when the PHP < 8.0 tokenization is used as certain tokens will be "squashed" into one token.

This commit adds a test helper method to allow tests to "know" whether or not to expect the PHP 8.0 identifier name tokenization, so the test setup/expectations can be adjusted based on the expected tokenization.

The method is based on the current reality.
At this time the PHP 8 tokenization should be expected on all PHPCS versions when run on PHP 8.

PHP PHPCS 2.x PHPCS 3.x PHPCS 4.x
PHP 5, 7
PHP >= 8 ✔️ ✔️ ✔️

However, this is expected to change in the near future and the method will be adjusted when it is.

Once the above mentioned PRs have been merged, the matrix of when to expect which tokenization will change to this:

PHP PHPCS 2.x PHPCS 3.x < 3.5.7 PHPCS 3.x >= 3.5.7 PHPCS 4.x
PHP 5, 7 ✔️
PHP >= 8 ✔️ ✔️ ✔️

Refs:

In PHP 8.0 identifier name tokenization will change as outline in the [accepted RFC "Treat namespaced names as single token"](https://wiki.php.net/rfc/namespaced_names_as_token).

When the PHP 8.0 identifier name tokenization is used, the target token to find for some tests will need to be a different token - for instance: `T_STRING` vs `T_FULLY_QUALIFIED_NAME` -.
Along the same lines, the expected token positions in the return value of various functions will also be different when the PHP < 8.0 tokenization is used as certain tokens will be "squashed" into one token.

This adds a test helper method to allow tests to "know" whether or not to expect the PHP 8.0 identifier name tokenization, so the test setup/expectations can be adjusted based on the expected tokenization.

The method is based on the _current reality_.
At this time the PHP 8 tokenization should be expected on all PHPCS versions when run on PHP 8.

Refs:
* https://wiki.php.net/rfc/namespaced_names_as_token
* [Proposal for handling this PHP 8 change in PHPCS](squizlabs/PHP_CodeSniffer#3041)
* [Open PR for the PHPCS 3.x branch to "undo" the PHP 8 tokenization](squizlabs/PHP_CodeSniffer#3063)
@jrfnl jrfnl added this to the 1.0.0-alpha4 milestone Sep 13, 2020
@jrfnl jrfnl merged commit ae73a76 into develop Sep 13, 2020
@jrfnl jrfnl deleted the feature/utilitymethodtestcase-new-usesphp8nametokens-method branch September 13, 2020 14:22
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.

None yet

1 participant