@@ -24,13 +24,14 @@ final class YieldTest extends AbstractTokenizerTestCase
24
24
/**
25
25
* Test that the yield keyword is tokenized as such.
26
26
*
27
- * @param string $testMarker The comment which prefaces the target token in the test file.
27
+ * @param string $testMarker The comment which prefaces the target token in the test file.
28
+ * @param string $expectedContent Expected token content.
28
29
*
29
30
* @dataProvider dataYieldKeyword
30
31
*
31
32
* @return void
32
33
*/
33
- public function testYieldKeyword ($ testMarker )
34
+ public function testYieldKeyword ($ testMarker, $ expectedContent )
34
35
{
35
36
$ tokens = $ this ->phpcsFile ->getTokens ();
36
37
$ target = $ this ->getTargetToken ($ testMarker , [T_YIELD , T_YIELD_FROM , T_STRING ]);
@@ -47,6 +48,8 @@ public function testYieldKeyword($testMarker)
47
48
$ this ->assertSame ('T_YIELD ' , $ tokenArray ['type ' ], 'Token tokenized as ' .$ tokenArray ['type ' ].', not T_YIELD (type) ' );
48
49
}
49
50
51
+ $ this ->assertSame ($ expectedContent , $ tokenArray ['content ' ], 'Token content does not match expectation ' );
52
+
50
53
}//end testYieldKeyword()
51
54
52
55
@@ -60,9 +63,18 @@ public function testYieldKeyword($testMarker)
60
63
public static function dataYieldKeyword ()
61
64
{
62
65
return [
63
- 'yield ' => ['/* testYield */ ' ],
64
- 'yield followed by comment ' => ['/* testYieldFollowedByComment */ ' ],
65
- 'yield at end of file, live coding ' => ['/* testYieldLiveCoding */ ' ],
66
+ 'yield ' => [
67
+ 'testMarker ' => '/* testYield */ ' ,
68
+ 'expectedContent ' => 'yield ' ,
69
+ ],
70
+ 'yield followed by comment ' => [
71
+ 'testMarker ' => '/* testYieldFollowedByComment */ ' ,
72
+ 'expectedContent ' => 'YIELD ' ,
73
+ ],
74
+ 'yield at end of file, live coding ' => [
75
+ 'testMarker ' => '/* testYieldLiveCoding */ ' ,
76
+ 'expectedContent ' => 'yield ' ,
77
+ ],
66
78
];
67
79
68
80
}//end dataYieldKeyword()
@@ -72,23 +84,24 @@ public static function dataYieldKeyword()
72
84
* Test that the yield from keyword is tokenized as a single token when it in on a single line
73
85
* and only has whitespace between the words.
74
86
*
75
- * @param string $testMarker The comment which prefaces the target token in the test file.
76
- * @param string $content Optional. The test token content to search for.
77
- * Defaults to null.
87
+ * @param string $testMarker The comment which prefaces the target token in the test file.
88
+ * @param string $expectedContent Expected token content.
78
89
*
79
90
* @dataProvider dataYieldFromKeywordSingleToken
80
91
*
81
92
* @return void
82
93
*/
83
- public function testYieldFromKeywordSingleToken ($ testMarker , $ content = null )
94
+ public function testYieldFromKeywordSingleToken ($ testMarker , $ expectedContent )
84
95
{
85
96
$ tokens = $ this ->phpcsFile ->getTokens ();
86
- $ target = $ this ->getTargetToken ($ testMarker , [T_YIELD , T_YIELD_FROM , T_STRING ], $ content );
97
+ $ target = $ this ->getTargetToken ($ testMarker , [T_YIELD , T_YIELD_FROM , T_STRING ]);
87
98
$ tokenArray = $ tokens [$ target ];
88
99
89
100
$ this ->assertSame (T_YIELD_FROM , $ tokenArray ['code ' ], 'Token tokenized as ' .$ tokenArray ['type ' ].', not T_YIELD_FROM (code) ' );
90
101
$ this ->assertSame ('T_YIELD_FROM ' , $ tokenArray ['type ' ], 'Token tokenized as ' .$ tokenArray ['type ' ].', not T_YIELD_FROM (type) ' );
91
102
103
+ $ this ->assertSame ($ expectedContent , $ tokenArray ['content ' ], 'Token content does not match expectation ' );
104
+
92
105
}//end testYieldFromKeywordSingleToken()
93
106
94
107
@@ -103,13 +116,16 @@ public static function dataYieldFromKeywordSingleToken()
103
116
{
104
117
return [
105
118
'yield from ' => [
106
- 'testMarker ' => '/* testYieldFrom */ ' ,
119
+ 'testMarker ' => '/* testYieldFrom */ ' ,
120
+ 'expectedContent ' => 'yield from ' ,
107
121
],
108
122
'yield from with extra space between ' => [
109
- 'testMarker ' => '/* testYieldFromWithExtraSpacesBetween */ ' ,
123
+ 'testMarker ' => '/* testYieldFromWithExtraSpacesBetween */ ' ,
124
+ 'expectedContent ' => 'Yield From ' ,
110
125
],
111
126
'yield from with tab between ' => [
112
- 'testMarker ' => '/* testYieldFromWithTabBetween */ ' ,
127
+ 'testMarker ' => '/* testYieldFromWithTabBetween */ ' ,
128
+ 'expectedContent ' => 'yield from ' ,
113
129
],
114
130
];
115
131
0 commit comments