Skip to content

UtilityMethodTestCase::getTargetToken(): add option to throw an exception... - #248

Merged
jrfnl merged 1 commit into
developfrom
feature/utilitymethodtestcase-gettergettoken-extra-param
May 12, 2021
Merged

UtilityMethodTestCase::getTargetToken(): add option to throw an exception...#248
jrfnl merged 1 commit into
developfrom
feature/utilitymethodtestcase-gettergettoken-extra-param

Conversation

@jrfnl

@jrfnl jrfnl commented May 12, 2021

Copy link
Copy Markdown
Member

… 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

Development

Successfully merging this pull request may close these issues.

1 participant