Repository navigation
UtilityMethodTestCase::getTargetToken(): throw a custom exception when target token not found - #371
Merged
jrfnl merged 1 commit intoOct 17, 2022
Conversation
…n target token not found 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: * The new parameter `$failTest` has been removed. * A new, PHPCSUtils native `PHPCSUtils\Exceptions\TestTargetNotFound` exception is introduced, which extends the PHP native `OutOfBoundsException`. * If the target token is not found, the test will now always throw a `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: 1. The test run will still be marked as unsuccessful, so in that sense, there is no change. 2. Marking the test as "errored" is semantically more correct as a basic condition for the test to be able to run (having a token to examine) has not been fulfilled. 3. If a test would need to look for different token (contents) depending on PHP/PHPCS versions, they can choose to `catch` the exception and do a second token search. This means that the benefits of the change from 248 are still in place. Includes perfunctory tests for the new `TestTargetNotFound` exception. Includes updating the related test in the `GetTargetTokenTest` class to expect the new exception.
jrfnl
deleted the
testutils/utilitymethodtestcase-gettargettoken-throw-instead-of-fail
branch
October 17, 2022 12:27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
$failTesthas been removed.PHPCSUtils\Exceptions\TestTargetNotFoundexception is introduced, which extends the PHP nativeOutOfBoundsException.TestTargetNotFoundexception.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:
catchthe 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
TestTargetNotFoundexception. Includes updating the related test in theGetTargetTokenTestclass to expect the new exception.