@@ -16,21 +16,43 @@ final class BackfillFnTokenTest extends AbstractTokenizerTestCase
16
16
/**
17
17
* Test simple arrow functions.
18
18
*
19
- * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
19
+ * @param string $testMarker The comment prefacing the target token.
20
+ *
21
+ * @dataProvider dataSimple
22
+ * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
20
23
*
21
24
* @return void
22
25
*/
23
- public function testSimple ()
26
+ public function testSimple ($ testMarker )
24
27
{
25
- foreach (['/* testStandard */ ' , '/* testMixedCase */ ' ] as $ comment ) {
26
- $ token = $ this ->getTargetToken ($ comment , T_FN );
27
- $ this ->backfillHelper ($ token );
28
- $ this ->scopePositionTestHelper ($ token , 5 , 12 );
29
- }
28
+ $ token = $ this ->getTargetToken ($ testMarker , T_FN );
29
+ $ this ->backfillHelper ($ token );
30
+ $ this ->scopePositionTestHelper ($ token , 5 , 12 );
30
31
31
32
}//end testSimple()
32
33
33
34
35
+ /**
36
+ * Data provider.
37
+ *
38
+ * @see testSimple()
39
+ *
40
+ * @return array<string, array<string, string>>
41
+ */
42
+ public static function dataSimple ()
43
+ {
44
+ return [
45
+ 'standard ' => [
46
+ 'testMarker ' => '/* testStandard */ ' ,
47
+ ],
48
+ 'mixed case ' => [
49
+ 'testMarker ' => '/* testMixedCase */ ' ,
50
+ ],
51
+ ];
52
+
53
+ }//end dataSimple()
54
+
55
+
34
56
/**
35
57
* Test whitespace inside arrow function definitions.
36
58
*
@@ -426,44 +448,54 @@ public function testNamespaceOperatorInTypes()
426
448
427
449
428
450
/**
429
- * Test arrow functions that use self/parent/callable/array/static return types.
451
+ * Test arrow functions that use keyword return types.
430
452
*
431
- * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
453
+ * @param string $testMarker The comment prefacing the target token.
454
+ *
455
+ * @dataProvider dataKeywordReturnTypes
456
+ * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional
432
457
*
433
458
* @return void
434
459
*/
435
- public function testKeywordReturnTypes ()
460
+ public function testKeywordReturnTypes ($ testMarker )
436
461
{
437
462
$ tokens = $ this ->phpcsFile ->getTokens ();
438
463
439
- $ testMarkers = [
440
- 'Self ' ,
441
- 'Parent ' ,
442
- 'Callable ' ,
443
- 'Array ' ,
444
- 'Static ' ,
445
- ];
446
-
447
- foreach ($ testMarkers as $ marker ) {
448
- $ token = $ this ->getTargetToken ('/* test ' .$ marker .'ReturnType */ ' , T_FN );
449
- $ this ->backfillHelper ($ token );
450
-
451
- $ expectedScopeOpener = ($ token + 11 );
452
- $ expectedScopeCloser = ($ token + 14 );
464
+ $ token = $ this ->getTargetToken ($ testMarker , T_FN );
465
+ $ this ->backfillHelper ($ token );
466
+ $ this ->scopePositionTestHelper ($ token , 11 , 14 );
453
467
454
- $ this ->assertSame ($ expectedScopeOpener , $ tokens [$ token ]['scope_opener ' ], "Scope opener is not the arrow token (for $ marker) " );
455
- $ this ->assertSame ($ expectedScopeCloser , $ tokens [$ token ]['scope_closer ' ], "Scope closer is not the semicolon token(for $ marker) " );
468
+ }//end testKeywordReturnTypes()
456
469
457
- $ opener = $ tokens [$ token ]['scope_opener ' ];
458
- $ this ->assertSame ($ expectedScopeOpener , $ tokens [$ opener ]['scope_opener ' ], "Opener scope opener is not the arrow token(for $ marker) " );
459
- $ this ->assertSame ($ expectedScopeCloser , $ tokens [$ opener ]['scope_closer ' ], "Opener scope closer is not the semicolon token(for $ marker) " );
460
470
461
- $ closer = $ tokens [$ token ]['scope_closer ' ];
462
- $ this ->assertSame ($ expectedScopeOpener , $ tokens [$ closer ]['scope_opener ' ], "Closer scope opener is not the arrow token(for $ marker) " );
463
- $ this ->assertSame ($ expectedScopeCloser , $ tokens [$ closer ]['scope_closer ' ], "Closer scope closer is not the semicolon token(for $ marker) " );
464
- }
471
+ /**
472
+ * Data provider.
473
+ *
474
+ * @see testKeywordReturnTypes()
475
+ *
476
+ * @return array<string, array<string, string>>
477
+ */
478
+ public static function dataKeywordReturnTypes ()
479
+ {
480
+ return [
481
+ 'self ' => [
482
+ 'testMarker ' => '/* testSelfReturnType */ ' ,
483
+ ],
484
+ 'parent ' => [
485
+ 'testMarker ' => '/* testParentReturnType */ ' ,
486
+ ],
487
+ 'callable ' => [
488
+ 'testMarker ' => '/* testCallableReturnType */ ' ,
489
+ ],
490
+ 'array ' => [
491
+ 'testMarker ' => '/* testArrayReturnType */ ' ,
492
+ ],
493
+ 'static ' => [
494
+ 'testMarker ' => '/* testStaticReturnType */ ' ,
495
+ ],
496
+ ];
465
497
466
- }//end testKeywordReturnTypes ()
498
+ }//end dataKeywordReturnTypes ()
467
499
468
500
469
501
/**
0 commit comments