Skip to content

Tests/Tokenizer: make failure messages more descriptive #310

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

Merged
merged 1 commit into from
Jan 28, 2024

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jan 28, 2024

Description

Most Tokenizer tests first assert that the token 'code' is correct and after that, that the token 'type' is correct. When the first assertion fails, an error message like this will be displayed:
Failed asserting that 357 is identical to 313.

That's because the PHP native token constants are integers. And even if someone would memorize all token constant integers, the integer values are different depending on the PHP version being used. All in all, that makes error messages like the above hard to decipher.

To mitigate this, a number of the Tokenizer tests already used the $msg parameter for the assertSame() call.

This commit adds this $msg parameter to more assertions to make the failure messages actually useful.

Includes introducing an interim $tokenArray variable in a lot of these tests to keep the line length in check.

Suggested changelog entry

N/A

Most Tokenizer tests first assert that the token `'code'` is correct and after that, that the token `'type'` is correct.
When the first assertion fails, an error message like this will be displayed:
`Failed asserting that 357 is identical to 313.`

That's because the PHP native token constants are integers. And even if someone would memorize all token constant integers, the integer values are different depending on the PHP version being used. All in all, that makes error messages like the above hard to decipher.

To mitigate this, a number of the Tokenizer tests already used the `$msg` parameter for the `assertSame()` call.

This commit adds this `$msg` parameter to more assertions to make the failure messages actually useful.

Includes introducing an interim `$tokenArray` variable in a lot of these tests to keep the line length in check.
@jrfnl jrfnl added this to the 3.9.0 milestone Jan 28, 2024
@jrfnl jrfnl merged commit 50a5645 into master Jan 28, 2024
@jrfnl jrfnl deleted the feature/tests-tokenizer-use-failure-msgs branch January 28, 2024 03:46
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