![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/squizlabs/php_codesniffer/tests/Core/Tokenizer/ |
<?php /** * Tests the tokenization of goto declarations and statements. * * @author Juliette Reinders Folmer <[email protected]> * @copyright 2020 Squiz Pty Ltd (ABN 77 084 670 600) * @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/master/licence.txt BSD Licence */ namespace PHP_CodeSniffer\Tests\Core\Tokenizer; use PHP_CodeSniffer\Tests\Core\AbstractMethodUnitTest; class GotoLabelTest extends AbstractMethodUnitTest { /** * Verify that the label in a goto statement is tokenized as T_STRING. * * @param string $testMarker The comment prefacing the target token. * @param string $testContent The token content to expect. * * @dataProvider dataGotoStatement * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize * * @return void */ public function testGotoStatement($testMarker, $testContent) { $tokens = self::$phpcsFile->getTokens(); $label = $this->getTargetToken($testMarker, T_STRING); $this->assertTrue(is_int($label)); $this->assertSame($testContent, $tokens[$label]['content']); }//end testGotoStatement() /** * Data provider. * * @see testGotoStatement() * * @return array */ public function dataGotoStatement() { return [ [ '/* testGotoStatement */', 'marker', ], [ '/* testGotoStatementInLoop */', 'end', ], ]; }//end dataGotoStatement() /** * Verify that the label in a goto declaration is tokenized as T_GOTO_LABEL. * * @param string $testMarker The comment prefacing the target token. * @param string $testContent The token content to expect. * * @dataProvider dataGotoDeclaration * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize * * @return void */ public function testGotoDeclaration($testMarker, $testContent) { $tokens = self::$phpcsFile->getTokens(); $label = $this->getTargetToken($testMarker, T_GOTO_LABEL); $this->assertTrue(is_int($label)); $this->assertSame($testContent, $tokens[$label]['content']); }//end testGotoDeclaration() /** * Data provider. * * @see testGotoDeclaration() * * @return array */ public function dataGotoDeclaration() { return [ [ '/* testGotoDeclaration */', 'marker:', ], [ '/* testGotoDeclarationOutsideLoop */', 'end:', ], ]; }//end dataGotoDeclaration() /** * Verify that the constant used in a switch - case statement is not confused with a goto label. * * @param string $testMarker The comment prefacing the target token. * @param string $testContent The token content to expect. * * @dataProvider dataNotAGotoDeclaration * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize * * @return void */ public function testNotAGotoDeclaration($testMarker, $testContent) { $tokens = self::$phpcsFile->getTokens(); $target = $this->getTargetToken($testMarker, [T_GOTO_LABEL, T_STRING], $testContent); $this->assertSame(T_STRING, $tokens[$target]['code']); $this->assertSame('T_STRING', $tokens[$target]['type']); }//end testNotAGotoDeclaration() /** * Data provider. * * @see testNotAGotoDeclaration() * * @return array */ public function dataNotAGotoDeclaration() { return [ [ '/* testNotGotoDeclarationGlobalConstant */', 'CONSTANT', ], [ '/* testNotGotoDeclarationNamespacedConstant */', 'CONSTANT', ], [ '/* testNotGotoDeclarationClassConstant */', 'CONSTANT', ], [ '/* testNotGotoDeclarationClassProperty */', 'property', ], [ '/* testNotGotoDeclarationGlobalConstantInTernary */', 'CONST_A', ], [ '/* testNotGotoDeclarationGlobalConstantInTernary */', 'CONST_B', ], [ '/* testNotGotoDeclarationEnumWithType */', 'Suit', ], ]; }//end dataNotAGotoDeclaration() }//end class