-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The PHP 7.4 T_FN token has been made available for older versions (ref …
- Loading branch information
Showing
5 changed files
with
127 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
/* testStandard */ | ||
$fn1 = fn($x) => $x + $y; | ||
|
||
/* testMixedCase */ | ||
$fn1 = Fn($x) => $x + $y; | ||
|
||
/* testWhitespace */ | ||
$fn1 = fn ($x) => $x + $y; | ||
|
||
/* testComment */ | ||
$fn1 = fn /* comment here */ ($x) => $x + $y; | ||
|
||
/* testFunctionName */ | ||
function fn() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* Tests the backfilling of the T_FN token to PHP < 7.4. | ||
* | ||
* @author Greg Sherwood <gsherwood@squiz.net> | ||
* @copyright 2019 Squiz Pty Ltd (ABN 77 084 670 600) | ||
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence | ||
*/ | ||
|
||
namespace PHP_CodeSniffer\Tests\Core\Tokenizer; | ||
|
||
use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; | ||
|
||
class BackfillFnTokenTest extends AbstractMethodUnitTest | ||
{ | ||
|
||
|
||
/** | ||
* Data provider. | ||
* | ||
* @see testBackill() | ||
* | ||
* @return array | ||
*/ | ||
public function dataBackfill() | ||
{ | ||
return [ | ||
['/* testStandard */'], | ||
['/* testMixedCase */'], | ||
['/* testWhitespace */'], | ||
['/* testComment */'], | ||
['/* testFunctionName */'], | ||
]; | ||
|
||
}//end dataAnonClassNoParentheses() | ||
|
||
|
||
/** | ||
* Test that anonymous class tokens without parenthesis do not get assigned a parenthesis owner. | ||
* | ||
* @param string $testMarker The comment which prefaces the target token in the test file. | ||
* | ||
* @dataProvider dataBackfill | ||
* @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional | ||
* | ||
* @return void | ||
*/ | ||
public function testBackfill($testMarker) | ||
{ | ||
$tokens = self::$phpcsFile->getTokens(); | ||
|
||
$token = $this->getTargetToken($testMarker, T_FN); | ||
$this->assertTrue(array_key_exists('parenthesis_owner', $tokens[$token]), 'Parenthesis owner is not set'); | ||
$this->assertTrue(array_key_exists('parenthesis_opener', $tokens[$token]), 'Parenthesis opener is not set'); | ||
$this->assertTrue(array_key_exists('parenthesis_closer', $tokens[$token]), 'Parenthesis closer is not set'); | ||
$this->assertSame($tokens[$token]['parenthesis_owner'], $token, 'Parenthesis owner is not the T_FN token'); | ||
|
||
$opener = $tokens[$token]['parenthesis_opener']; | ||
$this->assertTrue(array_key_exists('parenthesis_owner', $tokens[$opener]), 'Opening parenthesis owner is not set'); | ||
$this->assertSame($tokens[$opener]['parenthesis_owner'], $token, 'Opening parenthesis owner is not the T_FN token'); | ||
|
||
$closer = $tokens[$token]['parenthesis_closer']; | ||
$this->assertTrue(array_key_exists('parenthesis_owner', $tokens[$closer]), 'Closing parenthesis owner is not set'); | ||
$this->assertSame($tokens[$closer]['parenthesis_owner'], $token, 'Closing parenthesis owner is not the T_FN token'); | ||
|
||
}//end testAnonClassNoParentheses() | ||
|
||
|
||
}//end class |