Skip to content

Commit

Permalink
Tests/NamedFunctionCallArgumentsTest: activate two test cases
Browse files Browse the repository at this point in the history
These test cases already existed in the test case file, but were not being run as tests.

Fixed now.
  • Loading branch information
jrfnl committed Jan 14, 2024
1 parent 34bdfaa commit 3a61598
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/Core/Tokenizer/NamedFunctionCallArgumentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,73 @@ public function testParseErrorVariableLabel()
}//end testParseErrorVariableLabel()


/**
* Verify whether the colons are tokenized correctly when a return type is used for an inline
* closure/arrow function declaration in a ternary.
*
* @param string $testMarker The comment prefacing the target token.
*
* @dataProvider dataOtherColonsInTernary
* @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize
*
* @return void
*/
public function testOtherColonsInTernary($testMarker)
{
$tokens = self::$phpcsFile->getTokens();

$startOfStatement = $this->getTargetToken($testMarker, T_VARIABLE);

/*
* Walk the statement and check the tokenization.
* There should be no T_PARAM_NAME tokens.
* First colon should be T_COLON for the return type.
* Second colon should be T_INLINE_ELSE for the ternary.
* Third colon should be T_COLON for the return type.
*/
$colonCount = 0;
for ($i = ($startOfStatement + 1); $tokens[$i]['line'] === $tokens[$startOfStatement]['line']; $i++) {
$this->assertNotEquals(T_PARAM_NAME, $tokens[$i]['code'], "Token $i is tokenized as parameter label");

if ($tokens[$i]['content'] === ':') {
++$colonCount;

if ($colonCount === 1) {
$this->assertSame(T_COLON, $tokens[$i]['code'], 'First colon is not tokenized as T_COLON');
} else if ($colonCount === 2) {
$this->assertSame(T_INLINE_ELSE, $tokens[$i]['code'], 'Second colon is not tokenized as T_INLINE_ELSE');
} else if ($colonCount === 3) {
$this->assertSame(T_COLON, $tokens[$i]['code'], 'Third colon is not tokenized as T_COLON');
} else {
$this->fail('Unexpected colon encountered in statement');
}
}
}

}//end testOtherColonsInTernary()


/**
* Data provider.
*
* @see testOtherColonsInTernary()
*
* @return array<string, array<string, string>>
*/
public static function dataOtherColonsInTernary()
{
return [
'closures with return types in ternary' => [
'testMarker' => '/* testTernaryWithClosuresAndReturnTypes */',
],
'arrow functions with return types in ternary' => [
'testMarker' => '/* testTernaryWithArrowFunctionsAndReturnTypes */',
],
];

}//end dataOtherColonsInTernary()


/**
* Verify that reserved keywords used as a parameter label are tokenized as T_PARAM_NAME
* and that the colon after it is tokenized as a T_COLON.
Expand Down

0 comments on commit 3a61598

Please sign in to comment.