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::getTargetToken(): add option to throw an exception... #248

Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented May 12, 2021

… instead of failing the test

By default, if the target token cannot be found, the UtilityMethodTestCase::getTargetToken() method will automatically fail the test.

In a limited set of circumstances, however, it can be preferred for the method to throw a (catchable) exception instead.

Case in point: finding a token which - depending on the PHPCS version used - may have a slightly different token content which could inhibit finding the target token in one go.

In that case, it would be preferable for the method to throw a catchable exception, allowing the test to catch the exception and then to try finding the target token again with a slightly different content.

To that end, a new $failTest parameter has been added which, when set to false, will direct the UtilityMethodTestCase::getTargetToken() method to throw a PHP native RuntimeException instead of marking the test as failed.

Includes a test covering this new functionality.

…tion instead of failing the test

By default, if the target token cannot be found, the `UtilityMethodTestCase::getTargetToken()` method will automatically fail the test.

In a limited set of circumstances, however, it can be preferred for the method to throw a (catchable) exception instead.

Case in point: finding a token which - depending on the PHPCS version used - may have a slightly different token content which could inhibit finding the target token in one go.

In that case, it would be preferable for the method to throw a catchable exception, allowing the test to catch the exception and then to try finding the target token again with a slightly different content.

To that end, a new `$failTest` parameter has been added which, when set to `false`, will direct the `UtilityMethodTestCase::getTargetToken()` method to throw a PHP native `RuntimeException` instead of marking the test as failed.

Includes a test covering this new functionality.
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