Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 29 additions & 13 deletions tests/Core/Tokenizers/PHP/YieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ final class YieldTest extends AbstractTokenizerTestCase
/**
* Test that the yield keyword is tokenized as such.
*
* @param string $testMarker The comment which prefaces the target token in the test file.
* @param string $testMarker The comment which prefaces the target token in the test file.
* @param string $expectedContent Expected token content.
*
* @dataProvider dataYieldKeyword
*
* @return void
*/
public function testYieldKeyword($testMarker)
public function testYieldKeyword($testMarker, $expectedContent)
{
$tokens = $this->phpcsFile->getTokens();
$target = $this->getTargetToken($testMarker, [T_YIELD, T_YIELD_FROM, T_STRING]);
Expand All @@ -47,6 +48,8 @@ public function testYieldKeyword($testMarker)
$this->assertSame('T_YIELD', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_YIELD (type)');
}

$this->assertSame($expectedContent, $tokenArray['content'], 'Token content does not match expectation');

}//end testYieldKeyword()


Expand All @@ -60,9 +63,18 @@ public function testYieldKeyword($testMarker)
public static function dataYieldKeyword()
{
return [
'yield' => ['/* testYield */'],
'yield followed by comment' => ['/* testYieldFollowedByComment */'],
'yield at end of file, live coding' => ['/* testYieldLiveCoding */'],
'yield' => [
'testMarker' => '/* testYield */',
'expectedContent' => 'yield',
],
'yield followed by comment' => [
'testMarker' => '/* testYieldFollowedByComment */',
'expectedContent' => 'YIELD',
],
'yield at end of file, live coding' => [
'testMarker' => '/* testYieldLiveCoding */',
'expectedContent' => 'yield',
],
];

}//end dataYieldKeyword()
Expand All @@ -72,23 +84,24 @@ public static function dataYieldKeyword()
* Test that the yield from keyword is tokenized as a single token when it in on a single line
* and only has whitespace between the words.
*
* @param string $testMarker The comment which prefaces the target token in the test file.
* @param string $content Optional. The test token content to search for.
* Defaults to null.
* @param string $testMarker The comment which prefaces the target token in the test file.
* @param string $expectedContent Expected token content.
*
* @dataProvider dataYieldFromKeywordSingleToken
*
* @return void
*/
public function testYieldFromKeywordSingleToken($testMarker, $content=null)
public function testYieldFromKeywordSingleToken($testMarker, $expectedContent)
{
$tokens = $this->phpcsFile->getTokens();
$target = $this->getTargetToken($testMarker, [T_YIELD, T_YIELD_FROM, T_STRING], $content);
$target = $this->getTargetToken($testMarker, [T_YIELD, T_YIELD_FROM, T_STRING]);
$tokenArray = $tokens[$target];

$this->assertSame(T_YIELD_FROM, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_YIELD_FROM (code)');
$this->assertSame('T_YIELD_FROM', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_YIELD_FROM (type)');

$this->assertSame($expectedContent, $tokenArray['content'], 'Token content does not match expectation');

}//end testYieldFromKeywordSingleToken()


Expand All @@ -103,13 +116,16 @@ public static function dataYieldFromKeywordSingleToken()
{
return [
'yield from' => [
'testMarker' => '/* testYieldFrom */',
'testMarker' => '/* testYieldFrom */',
'expectedContent' => 'yield from',
],
'yield from with extra space between' => [
'testMarker' => '/* testYieldFromWithExtraSpacesBetween */',
'testMarker' => '/* testYieldFromWithExtraSpacesBetween */',
'expectedContent' => 'Yield From',
],
'yield from with tab between' => [
'testMarker' => '/* testYieldFromWithTabBetween */',
'testMarker' => '/* testYieldFromWithTabBetween */',
'expectedContent' => 'yield from',
],
];

Expand Down