@@ -101,28 +101,6 @@ public function testComments()
101101 }//end testComments()
102102
103103
104- /**
105- * Test a function called fn.
106- *
107- * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
108- *
109- * @return void
110- */
111- public function testFunctionName ()
112- {
113- $ tokens = self ::$ phpcsFile ->getTokens ();
114-
115- $ token = $ this ->getTargetToken ('/* testFunctionName */ ' , T_FN );
116- $ this ->assertFalse (array_key_exists ('scope_condition ' , $ tokens [$ token ]), 'Scope condition is set ' );
117- $ this ->assertFalse (array_key_exists ('scope_opener ' , $ tokens [$ token ]), 'Scope opener is set ' );
118- $ this ->assertFalse (array_key_exists ('scope_closer ' , $ tokens [$ token ]), 'Scope closer is set ' );
119- $ this ->assertFalse (array_key_exists ('parenthesis_owner ' , $ tokens [$ token ]), 'Parenthesis owner is set ' );
120- $ this ->assertFalse (array_key_exists ('parenthesis_opener ' , $ tokens [$ token ]), 'Parenthesis opener is set ' );
121- $ this ->assertFalse (array_key_exists ('parenthesis_closer ' , $ tokens [$ token ]), 'Parenthesis closer is set ' );
122-
123- }//end testFunctionName()
124-
125-
126104 /**
127105 * Test nested arrow functions.
128106 *
@@ -553,27 +531,85 @@ public function testTernary()
553531
554532
555533 /**
556- * Test that the backfill presumes T_FN during live coding, but doesn't set the additional index keys .
534+ * Test arrow function nested within a method declaration .
557535 *
558536 * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
559537 *
560538 * @return void
561539 */
562- public function testLiveCoding ()
540+ public function testNestedInMethod ()
541+ {
542+ $ tokens = self ::$ phpcsFile ->getTokens ();
543+
544+ $ token = $ this ->getTargetToken ('/* testNestedInMethod */ ' , T_FN );
545+ $ this ->backfillHelper ($ token );
546+
547+ $ this ->assertSame ($ tokens [$ token ]['scope_opener ' ], ($ token + 5 ), 'Scope opener is not the arrow token ' );
548+ $ this ->assertSame ($ tokens [$ token ]['scope_closer ' ], ($ token + 17 ), 'Scope closer is not the semicolon token ' );
549+
550+ $ opener = $ tokens [$ token ]['scope_opener ' ];
551+ $ this ->assertSame ($ tokens [$ opener ]['scope_opener ' ], ($ token + 5 ), 'Opener scope opener is not the arrow token ' );
552+ $ this ->assertSame ($ tokens [$ opener ]['scope_closer ' ], ($ token + 17 ), 'Opener scope closer is not the semicolon token ' );
553+
554+ $ closer = $ tokens [$ token ]['scope_opener ' ];
555+ $ this ->assertSame ($ tokens [$ closer ]['scope_opener ' ], ($ token + 5 ), 'Closer scope opener is not the arrow token ' );
556+ $ this ->assertSame ($ tokens [$ closer ]['scope_closer ' ], ($ token + 17 ), 'Closer scope closer is not the semicolon token ' );
557+
558+ }//end testNestedInMethod()
559+
560+
561+ /**
562+ * Verify that "fn" keywords which are not arrow functions get tokenized as T_STRING and don't
563+ * have the extra token array indexes.
564+ *
565+ * @param string $testMarker The comment prefacing the target token.
566+ *
567+ * @dataProvider dataNotAnArrowFunction
568+ * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
569+ *
570+ * @return void
571+ */
572+ public function testNotAnArrowFunction ($ testMarker )
563573 {
564574 $ tokens = self ::$ phpcsFile ->getTokens ();
565575
566- $ token = $ this ->getTargetToken ('/* testLiveCoding */ ' , [T_STRING , T_FN ]);
567- $ this ->assertSame ($ tokens [$ token ]['code ' ], T_FN , 'Token not tokenized as T_FN ' );
576+ $ token = $ this ->getTargetToken ('/* testFunctionName */ ' , [T_STRING , T_FN ], 'fn ' );
577+ $ tokenArray = $ tokens [$ token ];
578+
579+ $ this ->assertSame ('T_STRING ' , $ tokenArray ['type ' ], 'Token tokenized as ' .$ tokenArray ['type ' ].', not T_STRING ' );
580+
581+ $ this ->assertArrayNotHasKey ('scope_condition ' , $ tokenArray , 'Scope condition is set ' );
582+ $ this ->assertArrayNotHasKey ('scope_opener ' , $ tokenArray , 'Scope opener is set ' );
583+ $ this ->assertArrayNotHasKey ('scope_closer ' , $ tokenArray , 'Scope closer is set ' );
584+ $ this ->assertArrayNotHasKey ('parenthesis_owner ' , $ tokenArray , 'Parenthesis owner is set ' );
585+ $ this ->assertArrayNotHasKey ('parenthesis_opener ' , $ tokenArray , 'Parenthesis opener is set ' );
586+ $ this ->assertArrayNotHasKey ('parenthesis_closer ' , $ tokenArray , 'Parenthesis closer is set ' );
568587
569- $ this ->assertArrayNotHasKey ('scope_condition ' , $ tokens [$ token ], 'Scope condition is set ' );
570- $ this ->assertArrayNotHasKey ('scope_opener ' , $ tokens [$ token ], 'Scope opener is set ' );
571- $ this ->assertArrayNotHasKey ('scope_closer ' , $ tokens [$ token ], 'Scope closer is set ' );
572- $ this ->assertArrayNotHasKey ('parenthesis_owner ' , $ tokens [$ token ], 'Parenthesis owner is set ' );
573- $ this ->assertArrayNotHasKey ('parenthesis_opener ' , $ tokens [$ token ], 'Parenthesis opener is set ' );
574- $ this ->assertArrayNotHasKey ('parenthesis_closer ' , $ tokens [$ token ], 'Parenthesis closer is set ' );
588+ }//end testNotAnArrowFunction()
589+
590+
591+ /**
592+ * Data provider.
593+ *
594+ * @see testNotAnArrowFunction()
595+ *
596+ * @return array
597+ */
598+ public function dataNotAnArrowFunction ()
599+ {
600+ return [
601+ ['/* testFunctionName */ ' ],
602+ ['/* testStaticMethodName */ ' ],
603+ ['/* testAnonClassMethodName */ ' ],
604+ ['/* testNonArrowStaticMethodCall */ ' ],
605+ ['/* testNonArrowStaticMethodCallWithChaining */ ' ],
606+ ['/* testNonArrowObjectMethodCall */ ' ],
607+ ['/* testNonArrowNamespacedFunctionCall */ ' ],
608+ ['/* testNonArrowNamespaceOperatorFunctionCall */ ' ],
609+ ['/* testLiveCoding */ ' ],
610+ ];
575611
576- }//end testLiveCoding ()
612+ }//end dataNotAnArrowFunction ()
577613
578614
579615 /**
0 commit comments