|  | 
|  | 1 | +<?php | 
|  | 2 | +/** | 
|  | 3 | + * Tests the backfilling of the T_FN token to PHP < 7.4 for a specific parse error. | 
|  | 4 | + * | 
|  | 5 | + * @author    Juliette Reinders Folmer <[email protected]> | 
|  | 6 | + * @copyright 2024 PHPCSStandards and contributors | 
|  | 7 | + * @license   https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence | 
|  | 8 | + */ | 
|  | 9 | + | 
|  | 10 | +namespace PHP_CodeSniffer\Tests\Core\Tokenizers\PHP; | 
|  | 11 | + | 
|  | 12 | +use PHP_CodeSniffer\Tests\Core\Tokenizers\AbstractTokenizerTestCase; | 
|  | 13 | + | 
|  | 14 | +final class BackfillFnTokenParseErrorTest extends AbstractTokenizerTestCase | 
|  | 15 | +{ | 
|  | 16 | + | 
|  | 17 | + | 
|  | 18 | +    /** | 
|  | 19 | +     * Verify that un unfinished arrow function during live coding doesn't cause a "Undefined array key "parenthesis_closer"" error. | 
|  | 20 | +     * | 
|  | 21 | +     * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional | 
|  | 22 | +     * | 
|  | 23 | +     * @return void | 
|  | 24 | +     */ | 
|  | 25 | +    public function testUnfinishedArrowFunction() | 
|  | 26 | +    { | 
|  | 27 | +        $tokens = $this->phpcsFile->getTokens(); | 
|  | 28 | + | 
|  | 29 | +        $token      = $this->getTargetToken('/* testLiveCoding */', [T_STRING, T_FN], 'fn'); | 
|  | 30 | +        $tokenArray = $tokens[$token]; | 
|  | 31 | + | 
|  | 32 | +        $this->assertSame('T_STRING', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING'); | 
|  | 33 | + | 
|  | 34 | +        $this->assertArrayNotHasKey('scope_condition', $tokenArray, 'Scope condition is set'); | 
|  | 35 | +        $this->assertArrayNotHasKey('scope_opener', $tokenArray, 'Scope opener is set'); | 
|  | 36 | +        $this->assertArrayNotHasKey('scope_closer', $tokenArray, 'Scope closer is set'); | 
|  | 37 | +        $this->assertArrayNotHasKey('parenthesis_owner', $tokenArray, 'Parenthesis owner is set'); | 
|  | 38 | +        $this->assertArrayNotHasKey('parenthesis_opener', $tokenArray, 'Parenthesis opener is set'); | 
|  | 39 | +        $this->assertArrayNotHasKey('parenthesis_closer', $tokenArray, 'Parenthesis closer is set'); | 
|  | 40 | + | 
|  | 41 | +    }//end testUnfinishedArrowFunction() | 
|  | 42 | + | 
|  | 43 | + | 
|  | 44 | +}//end class | 
0 commit comments