Skip to content

Commit 2adcb64

Browse files
committed
Tokenizer arrow functions backfill tests: fix it ;-)
Follow up on 2860. This fixes the tests. #### Test case file: * Adds tests with mixed case `fn` keyword. * Removes a few redundant tests (weren't testing anything which wasn't covered already). #### Test file: * Adds a couple of tests which were missing from the data provider. * Updates the test itself to use a `$testContent` parameter to allow for the `fn` in the tests being non-lowercase.
1 parent ea810a2 commit 2adcb64

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

tests/Core/Tokenizer/BackfillFnTokenTest.inc

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ fn(array $a) : array => $a;
7474
$fn = fn($a) => $a ? /* testTernaryThen */ fn() : string => 'a' : /* testTernaryElse */ fn() : string => 'b';
7575

7676
/* testConstantDeclaration */
77-
const fn = 'a';
77+
const FN = 'a';
7878

7979
class Foo {
8080
/* testStaticMethodName */
@@ -91,27 +91,21 @@ class Foo {
9191

9292
$anon = new class() {
9393
/* testAnonClassMethodName */
94-
protected function fn($param) {
94+
protected function fN($param) {
9595
}
9696
}
9797

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

101-
/* testNonArrowStaticMethodCallWithChaining */
102-
$a = Foo::fn($param)->another();
103-
104-
/* testNonArrowStaticConstant */
105-
$a = MyClass::fn;
106-
107-
/* testNonArrowStaticConstantDeref */
108-
$a = MyClass::fn[$a];
101+
/* testNonArrowConstantAccess */
102+
$a = MyClass::FN;
109103

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

113107
/* testNonArrowNamespacedFunctionCall */
114-
$a = MyNS\Sub\fn($param);
108+
$a = MyNS\Sub\Fn($param);
115109

116110
/* testNonArrowNamespaceOperatorFunctionCall */
117111
$a = namespace\fn($param);

tests/Core/Tokenizer/BackfillFnTokenTest.php

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -562,18 +562,19 @@ public function testNestedInMethod()
562562
* Verify that "fn" keywords which are not arrow functions get tokenized as T_STRING and don't
563563
* have the extra token array indexes.
564564
*
565-
* @param string $testMarker The comment prefacing the target token.
565+
* @param string $testMarker The comment prefacing the target token.
566+
* @param string $testContent The token content to look for.
566567
*
567568
* @dataProvider dataNotAnArrowFunction
568569
* @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
569570
*
570571
* @return void
571572
*/
572-
public function testNotAnArrowFunction($testMarker)
573+
public function testNotAnArrowFunction($testMarker, $testContent='fn')
573574
{
574575
$tokens = self::$phpcsFile->getTokens();
575576

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

579580
$this->assertSame('T_STRING', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING');
@@ -598,16 +599,27 @@ public function testNotAnArrowFunction($testMarker)
598599
public function dataNotAnArrowFunction()
599600
{
600601
return [
601-
['/* testConstantDeclaration */'],
602602
['/* testFunctionName */'],
603+
[
604+
'/* testConstantDeclaration */',
605+
'FN',
606+
],
603607
['/* testStaticMethodName */'],
604-
['/* testAnonClassMethodName */'],
608+
['/* testPropertyAssignment */'],
609+
[
610+
'/* testAnonClassMethodName */',
611+
'fN',
612+
],
605613
['/* testNonArrowStaticMethodCall */'],
606-
['/* testNonArrowStaticMethodCallWithChaining */'],
607-
['/* testNonArrowStaticConstant */'],
608-
['/* testNonArrowStaticConstantDeref */'],
614+
[
615+
'/* testNonArrowConstantAccess */',
616+
'FN',
617+
],
609618
['/* testNonArrowObjectMethodCall */'],
610-
['/* testNonArrowNamespacedFunctionCall */'],
619+
[
620+
'/* testNonArrowNamespacedFunctionCall */',
621+
'Fn',
622+
],
611623
['/* testNonArrowNamespaceOperatorFunctionCall */'],
612624
['/* testLiveCoding */'],
613625
];

0 commit comments

Comments
 (0)