|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Tests the adding of the "bracket_opener/closer" keys to use group tokens. |
| 4 | + * |
| 5 | + * @author Juliette Reinders Folmer <[email protected]> |
| 6 | + * @copyright 2020 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 ScopeSettingWithNamespaceOperatorTest extends AbstractMethodUnitTest |
| 15 | +{ |
| 16 | + |
| 17 | + |
| 18 | + /** |
| 19 | + * Test that the scope opener/closers are set correctly when the namespace keyword is encountered as an operator. |
| 20 | + * |
| 21 | + * @param string $testMarker The comment which prefaces the target tokens in the test file. |
| 22 | + * @param int|string[] $tokenTypes The token type to search for. |
| 23 | + * @param int|string[] $open Optional. The token type for the scope opener. |
| 24 | + * @param int|string[] $close Optional. The token type for the scope closer. |
| 25 | + * |
| 26 | + * @dataProvider dataScopeSetting |
| 27 | + * @covers PHP_CodeSniffer\Tokenizers\Tokenizer::recurseScopeMap |
| 28 | + * |
| 29 | + * @return void |
| 30 | + */ |
| 31 | + public function testScopeSetting($testMarker, $tokenTypes, $open = T_OPEN_CURLY_BRACKET, $close = T_CLOSE_CURLY_BRACKET) |
| 32 | + { |
| 33 | + $tokens = self::$phpcsFile->getTokens(); |
| 34 | + |
| 35 | + $target = $this->getTargetToken($testMarker, $tokenTypes); |
| 36 | + $opener = $this->getTargetToken($testMarker, $open); |
| 37 | + $closer = $this->getTargetToken($testMarker, $close); |
| 38 | + |
| 39 | + $this->assertArrayHasKey('scope_opener', $tokens[$target], 'Scope opener missing'); |
| 40 | + $this->assertArrayHasKey('scope_closer', $tokens[$target], 'Scope closer missing'); |
| 41 | + $this->assertSame($opener, $tokens[$target]['scope_opener'], 'Scope opener not same'); |
| 42 | + $this->assertSame($closer, $tokens[$target]['scope_closer'], 'Scope closer not same'); |
| 43 | + |
| 44 | + $this->assertArrayHasKey('scope_opener', $tokens[$opener], 'Scope opener missing for open curly'); |
| 45 | + $this->assertArrayHasKey('scope_closer', $tokens[$opener], 'Scope closer missing for open curly'); |
| 46 | + $this->assertSame($opener, $tokens[$opener]['scope_opener'], 'Scope opener not same for open curly'); |
| 47 | + $this->assertSame($closer, $tokens[$opener]['scope_closer'], 'Scope closer not same for open curly'); |
| 48 | + |
| 49 | + $this->assertArrayHasKey('scope_opener', $tokens[$closer], 'Scope opener missing for close curly'); |
| 50 | + $this->assertArrayHasKey('scope_closer', $tokens[$closer], 'Scope closer missing for close curly'); |
| 51 | + $this->assertSame($opener, $tokens[$closer]['scope_opener'], 'Scope opener not same for close curly'); |
| 52 | + $this->assertSame($closer, $tokens[$closer]['scope_closer'], 'Scope closer not same for close curly'); |
| 53 | + |
| 54 | + }//end testScopeSetting() |
| 55 | + |
| 56 | + |
| 57 | + /** |
| 58 | + * Data provider. |
| 59 | + * |
| 60 | + * @see testScopeSetting() |
| 61 | + * |
| 62 | + * @return array |
| 63 | + */ |
| 64 | + public function dataScopeSetting() |
| 65 | + { |
| 66 | + return [ |
| 67 | + [ |
| 68 | + '/* testClassExtends */', |
| 69 | + [T_CLASS], |
| 70 | + ], |
| 71 | + [ |
| 72 | + '/* testClassImplements */', |
| 73 | + [T_ANON_CLASS], |
| 74 | + ], |
| 75 | + [ |
| 76 | + '/* testInterfaceExtends */', |
| 77 | + [T_INTERFACE], |
| 78 | + ], |
| 79 | + [ |
| 80 | + '/* testFunctionReturnType */', |
| 81 | + [T_FUNCTION], |
| 82 | + ], |
| 83 | + [ |
| 84 | + '/* testClosureReturnType */', |
| 85 | + [T_CLOSURE], |
| 86 | + ], |
| 87 | + [ |
| 88 | + '/* testArrowFunctionReturnType */', |
| 89 | + [T_FN], |
| 90 | + [T_FN_ARROW], |
| 91 | + [T_SEMICOLON], |
| 92 | + ], |
| 93 | + ]; |
| 94 | + |
| 95 | + }//end dataScopeSetting() |
| 96 | + |
| 97 | + |
| 98 | +}//end class |
0 commit comments