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

AbstractMethodUnitTest: improve finding of target token #531

Merged
merged 1 commit into from
Jul 4, 2024

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 4, 2024

Description

These changes are similar to changes previously made in the same method in PHPCSUtils.

As things were, there could be a situation where the getTargetTokenFromFile() method did not find the delimiter comment. In that case, the method would search for the target token starting at token 0, which would generally lead to an incorrect token being identified as the target token.

This has now been fixed by verifying the outcome of the findPrevious() call and throwing an exception (causing the test to fail) when the delimiter comment was not found.

Along the same lines, when the target token would not be found, an exception will now be thrown as well.

Suggested changelog entry

N/A (this is an internal use class, if external standards want to use a base class for testing utility methods, they should use the PHPCSUtils UtilityMethodTestCase).

Related issues/external references

These changes are similar to changes previously made in the same method in PHPCSUtils.

As things were, there could be a situation where the `getTargetTokenFromFile()` method did not find the delimiter comment. In that case, the method would search for the target token starting at token 0, which would generally lead to an incorrect token being identified as the target token.

This has now been fixed by verifying the outcome of the `findPrevious()` call and throwing an exception (causing the test to fail) when the delimiter comment was not found.

Along the same lines, when the target token would not be found, an exception will now be thrown as well.
@jrfnl jrfnl added this to the 3.10.x Next milestone Jul 4, 2024
@jrfnl jrfnl merged commit 71326b4 into master Jul 4, 2024
50 checks passed
@jrfnl jrfnl deleted the feature/abstractmethodunittest-stricter-check branch July 4, 2024 21:25
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