Skip to content

Commit

Permalink
Merge pull request #531 from PHPCSStandards/feature/abstractmethoduni…
Browse files Browse the repository at this point in the history
…ttest-stricter-check

AbstractMethodUnitTest: improve finding of target token
  • Loading branch information
jrfnl authored Jul 4, 2024
2 parents e245088 + e715707 commit 71326b4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tests/Core/AbstractMethodUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);

Expand All @@ -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;
Expand Down

0 comments on commit 71326b4

Please sign in to comment.