Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tokenizer arrow functions backfill tests: fix it ;-) #2863

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions tests/Core/Tokenizer/BackfillFnTokenTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fn(array $a) : array => $a;
$fn = fn($a) => $a ? /* testTernaryThen */ fn() : string => 'a' : /* testTernaryElse */ fn() : string => 'b';

/* testConstantDeclaration */
const fn = 'a';
const FN = 'a';

class Foo {
/* testStaticMethodName */
Expand All @@ -91,27 +91,21 @@ class Foo {

$anon = new class() {
/* testAnonClassMethodName */
protected function fn($param) {
protected function fN($param) {
}
}

/* testNonArrowStaticMethodCall */
$a = Foo::fn($param);

/* testNonArrowStaticMethodCallWithChaining */
$a = Foo::fn($param)->another();

/* testNonArrowStaticConstant */
$a = MyClass::fn;

/* testNonArrowStaticConstantDeref */
$a = MyClass::fn[$a];
/* testNonArrowConstantAccess */
$a = MyClass::FN;

/* testNonArrowObjectMethodCall */
$a = $obj->fn($param);

/* testNonArrowNamespacedFunctionCall */
$a = MyNS\Sub\fn($param);
$a = MyNS\Sub\Fn($param);

/* testNonArrowNamespaceOperatorFunctionCall */
$a = namespace\fn($param);
Expand Down
30 changes: 21 additions & 9 deletions tests/Core/Tokenizer/BackfillFnTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -562,18 +562,19 @@ public function testNestedInMethod()
* Verify that "fn" keywords which are not arrow functions get tokenized as T_STRING and don't
* have the extra token array indexes.
*
* @param string $testMarker The comment prefacing the target token.
* @param string $testMarker The comment prefacing the target token.
* @param string $testContent The token content to look for.
*
* @dataProvider dataNotAnArrowFunction
* @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
*
* @return void
*/
public function testNotAnArrowFunction($testMarker)
public function testNotAnArrowFunction($testMarker, $testContent='fn')
{
$tokens = self::$phpcsFile->getTokens();

$token = $this->getTargetToken($testMarker, [T_STRING, T_FN], 'fn');
$token = $this->getTargetToken($testMarker, [T_STRING, T_FN], $testContent);
$tokenArray = $tokens[$token];

$this->assertSame('T_STRING', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING');
Expand All @@ -598,16 +599,27 @@ public function testNotAnArrowFunction($testMarker)
public function dataNotAnArrowFunction()
{
return [
['/* testConstantDeclaration */'],
['/* testFunctionName */'],
[
'/* testConstantDeclaration */',
'FN',
],
['/* testStaticMethodName */'],
['/* testAnonClassMethodName */'],
['/* testPropertyAssignment */'],
[
'/* testAnonClassMethodName */',
'fN',
],
['/* testNonArrowStaticMethodCall */'],
['/* testNonArrowStaticMethodCallWithChaining */'],
['/* testNonArrowStaticConstant */'],
['/* testNonArrowStaticConstantDeref */'],
[
'/* testNonArrowConstantAccess */',
'FN',
],
['/* testNonArrowObjectMethodCall */'],
['/* testNonArrowNamespacedFunctionCall */'],
[
'/* testNonArrowNamespacedFunctionCall */',
'Fn',
],
['/* testNonArrowNamespaceOperatorFunctionCall */'],
['/* testLiveCoding */'],
];
Expand Down