diff --git a/tests/Core/AbstractMethodUnitTest.php b/tests/Core/AbstractMethodUnitTest.php index b933be17b4..c6dec9b008 100644 --- a/tests/Core/AbstractMethodUnitTest.php +++ b/tests/Core/AbstractMethodUnitTest.php @@ -9,6 +9,7 @@ namespace PHP_CodeSniffer\Tests\Core; +use Exception; use PHP_CodeSniffer\Files\DummyFile; use PHP_CodeSniffer\Files\File; use PHP_CodeSniffer\Ruleset; @@ -110,6 +111,9 @@ public function getTargetToken($commentString, $tokenType, $tokenContent=null) * @param string $tokenContent Optional. The token content for the target token. * * @return int + * + * @throws Exception When the test delimiter comment is not found. + * @throws Exception When the test target token is not found. */ public static function getTargetTokenFromFile(File $phpcsFile, $commentString, $tokenType, $tokenContent=null) { @@ -122,6 +126,12 @@ public static function getTargetTokenFromFile(File $phpcsFile, $commentString, $ $commentString ); + if ($comment === false) { + throw new Exception( + sprintf('Failed to find the test marker: %s in test case file %s', $commentString, $phpcsFile->getFilename()) + ); + } + $tokens = $phpcsFile->getTokens(); $end = ($start + 1); @@ -148,10 +158,10 @@ public static function getTargetTokenFromFile(File $phpcsFile, $commentString, $ if ($target === false) { $msg = 'Failed to find test target token for comment string: '.$commentString; if ($tokenContent !== null) { - $msg .= ' With token content: '.$tokenContent; + $msg .= ' with token content: '.$tokenContent; } - self::assertFalse(true, $msg); + throw new Exception($msg); } return $target;