UtilityMethodTestCase::getTargetToken(): throw a custom exception when target token not found #371
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR #248 introduced the option to throw an exception when the target token couldn't be found (instead of failing the test). In that initial implementation, the exception thrown would be the PHP native
RuntimeException
.This commit changes the principle:
$failTest
has been removed.PHPCSUtils\Exceptions\TestTargetNotFound
exception is introduced, which extends the PHP nativeOutOfBoundsException
.TestTargetNotFound
exception.As the change from PR #248 has not been in a release yet, the removal of the parameter is non-breaking.
All the same, this is a functional change as an uncaught exception will result in a test being marked as "errored", while previously, the test would be marked as "failed" when the target token could not be found.
The reason for making this change anyway are as follows:
catch
the exception and do a second token search. This means that the benefits of the change from UtilityMethodTestCase::getTargetToken(): add option to throw an exception... #248 are still in place.Includes perfunctory tests for the new
TestTargetNotFound
exception. Includes updating the related test in theGetTargetTokenTest
class to expect the new exception.