@@ -24,13 +24,14 @@ final class YieldTest extends AbstractTokenizerTestCase
2424 /**
2525 * Test that the yield keyword is tokenized as such.
2626 *
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.
2829 *
2930 * @dataProvider dataYieldKeyword
3031 *
3132 * @return void
3233 */
33- public function testYieldKeyword ($ testMarker )
34+ public function testYieldKeyword ($ testMarker, $ expectedContent )
3435 {
3536 $ tokens = $ this ->phpcsFile ->getTokens ();
3637 $ target = $ this ->getTargetToken ($ testMarker , [T_YIELD , T_YIELD_FROM , T_STRING ]);
@@ -47,6 +48,8 @@ public function testYieldKeyword($testMarker)
4748 $ this ->assertSame ('T_YIELD ' , $ tokenArray ['type ' ], 'Token tokenized as ' .$ tokenArray ['type ' ].', not T_YIELD (type) ' );
4849 }
4950
51+ $ this ->assertSame ($ expectedContent , $ tokenArray ['content ' ], 'Token content does not match expectation ' );
52+
5053 }//end testYieldKeyword()
5154
5255
@@ -60,9 +63,18 @@ public function testYieldKeyword($testMarker)
6063 public static function dataYieldKeyword ()
6164 {
6265 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+ ],
6678 ];
6779
6880 }//end dataYieldKeyword()
@@ -72,23 +84,24 @@ public static function dataYieldKeyword()
7284 * Test that the yield from keyword is tokenized as a single token when it in on a single line
7385 * and only has whitespace between the words.
7486 *
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.
7889 *
7990 * @dataProvider dataYieldFromKeywordSingleToken
8091 *
8192 * @return void
8293 */
83- public function testYieldFromKeywordSingleToken ($ testMarker , $ content = null )
94+ public function testYieldFromKeywordSingleToken ($ testMarker , $ expectedContent )
8495 {
8596 $ 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 ]);
8798 $ tokenArray = $ tokens [$ target ];
8899
89100 $ this ->assertSame (T_YIELD_FROM , $ tokenArray ['code ' ], 'Token tokenized as ' .$ tokenArray ['type ' ].', not T_YIELD_FROM (code) ' );
90101 $ this ->assertSame ('T_YIELD_FROM ' , $ tokenArray ['type ' ], 'Token tokenized as ' .$ tokenArray ['type ' ].', not T_YIELD_FROM (type) ' );
91102
103+ $ this ->assertSame ($ expectedContent , $ tokenArray ['content ' ], 'Token content does not match expectation ' );
104+
92105 }//end testYieldFromKeywordSingleToken()
93106
94107
@@ -103,13 +116,16 @@ public static function dataYieldFromKeywordSingleToken()
103116 {
104117 return [
105118 'yield from ' => [
106- 'testMarker ' => '/* testYieldFrom */ ' ,
119+ 'testMarker ' => '/* testYieldFrom */ ' ,
120+ 'expectedContent ' => 'yield from ' ,
107121 ],
108122 'yield from with extra space between ' => [
109- 'testMarker ' => '/* testYieldFromWithExtraSpacesBetween */ ' ,
123+ 'testMarker ' => '/* testYieldFromWithExtraSpacesBetween */ ' ,
124+ 'expectedContent ' => 'Yield From ' ,
110125 ],
111126 'yield from with tab between ' => [
112- 'testMarker ' => '/* testYieldFromWithTabBetween */ ' ,
127+ 'testMarker ' => '/* testYieldFromWithTabBetween */ ' ,
128+ 'expectedContent ' => 'yield from ' ,
113129 ],
114130 ];
115131
0 commit comments