|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Tests the backfilling of the T_FN token to PHP < 7.4. |
| 4 | + * |
| 5 | + * @author Greg Sherwood <gsherwood@squiz.net> |
| 6 | + * @copyright 2019 Squiz Pty Ltd (ABN 77 084 670 600) |
| 7 | + * @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence |
| 8 | + */ |
| 9 | + |
| 10 | +namespace PHP_CodeSniffer\Tests\Core\Tokenizer; |
| 11 | + |
| 12 | +use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; |
| 13 | + |
| 14 | +class BackfillFnTokenTest extends AbstractMethodUnitTest |
| 15 | +{ |
| 16 | + |
| 17 | + |
| 18 | + /** |
| 19 | + * Data provider. |
| 20 | + * |
| 21 | + * @see testBackill() |
| 22 | + * |
| 23 | + * @return array |
| 24 | + */ |
| 25 | + public function dataBackfill() |
| 26 | + { |
| 27 | + return [ |
| 28 | + ['/* testStandard */'], |
| 29 | + ['/* testMixedCase */'], |
| 30 | + ['/* testWhitespace */'], |
| 31 | + ['/* testComment */'], |
| 32 | + ['/* testFunctionName */'], |
| 33 | + ]; |
| 34 | + |
| 35 | + }//end dataAnonClassNoParentheses() |
| 36 | + |
| 37 | + |
| 38 | + /** |
| 39 | + * Test that anonymous class tokens without parenthesis do not get assigned a parenthesis owner. |
| 40 | + * |
| 41 | + * @param string $testMarker The comment which prefaces the target token in the test file. |
| 42 | + * |
| 43 | + * @dataProvider dataBackfill |
| 44 | + * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional |
| 45 | + * |
| 46 | + * @return void |
| 47 | + */ |
| 48 | + public function testBackfill($testMarker) |
| 49 | + { |
| 50 | + $tokens = self::$phpcsFile->getTokens(); |
| 51 | + |
| 52 | + $token = $this->getTargetToken($testMarker, T_FN); |
| 53 | + $this->assertTrue(array_key_exists('parenthesis_owner', $tokens[$token]), 'Parenthesis owner is not set'); |
| 54 | + $this->assertTrue(array_key_exists('parenthesis_opener', $tokens[$token]), 'Parenthesis opener is not set'); |
| 55 | + $this->assertTrue(array_key_exists('parenthesis_closer', $tokens[$token]), 'Parenthesis closer is not set'); |
| 56 | + $this->assertSame($tokens[$token]['parenthesis_owner'], $token, 'Parenthesis owner is not the T_FN token'); |
| 57 | + |
| 58 | + $opener = $tokens[$token]['parenthesis_opener']; |
| 59 | + $this->assertTrue(array_key_exists('parenthesis_owner', $tokens[$opener]), 'Opening parenthesis owner is not set'); |
| 60 | + $this->assertSame($tokens[$opener]['parenthesis_owner'], $token, 'Opening parenthesis owner is not the T_FN token'); |
| 61 | + |
| 62 | + $closer = $tokens[$token]['parenthesis_closer']; |
| 63 | + $this->assertTrue(array_key_exists('parenthesis_owner', $tokens[$closer]), 'Closing parenthesis owner is not set'); |
| 64 | + $this->assertSame($tokens[$closer]['parenthesis_owner'], $token, 'Closing parenthesis owner is not the T_FN token'); |
| 65 | + |
| 66 | + }//end testAnonClassNoParentheses() |
| 67 | + |
| 68 | + |
| 69 | +}//end class |
0 commit comments