Skip to content

Commit 71326b4

Browse files
authored
Merge pull request #531 from PHPCSStandards/feature/abstractmethodunittest-stricter-check
AbstractMethodUnitTest: improve finding of target token
2 parents e245088 + e715707 commit 71326b4

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

tests/Core/AbstractMethodUnitTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace PHP_CodeSniffer\Tests\Core;
1111

12+
use Exception;
1213
use PHP_CodeSniffer\Files\DummyFile;
1314
use PHP_CodeSniffer\Files\File;
1415
use PHP_CodeSniffer\Ruleset;
@@ -110,6 +111,9 @@ public function getTargetToken($commentString, $tokenType, $tokenContent=null)
110111
* @param string $tokenContent Optional. The token content for the target token.
111112
*
112113
* @return int
114+
*
115+
* @throws Exception When the test delimiter comment is not found.
116+
* @throws Exception When the test target token is not found.
113117
*/
114118
public static function getTargetTokenFromFile(File $phpcsFile, $commentString, $tokenType, $tokenContent=null)
115119
{
@@ -122,6 +126,12 @@ public static function getTargetTokenFromFile(File $phpcsFile, $commentString, $
122126
$commentString
123127
);
124128

129+
if ($comment === false) {
130+
throw new Exception(
131+
sprintf('Failed to find the test marker: %s in test case file %s', $commentString, $phpcsFile->getFilename())
132+
);
133+
}
134+
125135
$tokens = $phpcsFile->getTokens();
126136
$end = ($start + 1);
127137

@@ -148,10 +158,10 @@ public static function getTargetTokenFromFile(File $phpcsFile, $commentString, $
148158
if ($target === false) {
149159
$msg = 'Failed to find test target token for comment string: '.$commentString;
150160
if ($tokenContent !== null) {
151-
$msg .= ' With token content: '.$tokenContent;
161+
$msg .= ' with token content: '.$tokenContent;
152162
}
153163

154-
self::assertFalse(true, $msg);
164+
throw new Exception($msg);
155165
}
156166

157167
return $target;

0 commit comments

Comments
 (0)