PATH:
opt
/
cpanel
/
ea-wappspector
/
vendor
/
squizlabs
/
php_codesniffer
/
tests
/
Core
/
Tokenizers
/
PHP
<?php /** * Tests the tokenization of goto declarations and statements. * * @author Juliette Reinders Folmer <phpcs_nospam@adviesenzo.nl> * @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\Tokenizers\PHP; use PHP_CodeSniffer\Tests\Core\Tokenizers\AbstractTokenizerTestCase; /** * Tests the tokenization of goto declarations and statements. * * @covers PHP_CodeSniffer\Tokenizers\PHP::tokenize */ final class GotoLabelTest extends AbstractTokenizerTestCase { /** * 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 * * @return void */ public function testGotoStatement($testMarker, $testContent) { $tokens = $this->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<string, array<string, string>> */ public static function dataGotoStatement() { return [ 'label for goto statement' => [ 'testMarker' => '/* testGotoStatement */', 'testContent' => 'marker', ], 'label for goto statement in loop, keyword capitalized' => [ 'testMarker' => '/* testGotoStatementInLoop */', 'testContent' => 'end', ], 'label for goto statement in switch' => [ 'testMarker' => '/* testGotoStatementInSwitch */', 'testContent' => 'def', ], 'label for goto statement within function' => [ 'testMarker' => '/* testGotoStatementInFunction */', 'testContent' => 'label', ], ]; }//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 * * @return void */ public function testGotoDeclaration($testMarker, $testContent) { $tokens = $this->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<string, array<string, string>> */ public static function dataGotoDeclaration() { return [ 'label in goto declaration - marker' => [ 'testMarker' => '/* testGotoDeclaration */', 'testContent' => 'marker:', ], 'label in goto declaration - end' => [ 'testMarker' => '/* testGotoDeclarationOutsideLoop */', 'testContent' => 'end:', ], 'label in goto declaration - def' => [ 'testMarker' => '/* testGotoDeclarationInSwitch */', 'testContent' => 'def:', ], 'label in goto declaration - label' => [ 'testMarker' => '/* testGotoDeclarationInFunction */', 'testContent' => 'label:', ], ]; }//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 * * @return void */ public function testNotAGotoDeclaration($testMarker, $testContent) { $tokens = $this->phpcsFile->getTokens(); $target = $this->getTargetToken($testMarker, [T_GOTO_LABEL, T_STRING], $testContent); $tokenArray = $tokens[$target]; $this->assertSame(T_STRING, $tokenArray['code'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (code)'); $this->assertSame('T_STRING', $tokenArray['type'], 'Token tokenized as '.$tokenArray['type'].', not T_STRING (type)'); }//end testNotAGotoDeclaration() /** * Data provider. * * @see testNotAGotoDeclaration() * * @return array<string, array<string, string>> */ public static function dataNotAGotoDeclaration() { return [ 'not goto label - global constant followed by switch-case colon' => [ 'testMarker' => '/* testNotGotoDeclarationGlobalConstant */', 'testContent' => 'CONSTANT', ], 'not goto label - namespaced constant followed by switch-case colon' => [ 'testMarker' => '/* testNotGotoDeclarationNamespacedConstant */', 'testContent' => 'CONSTANT', ], 'not goto label - class constant followed by switch-case colon' => [ 'testMarker' => '/* testNotGotoDeclarationClassConstant */', 'testContent' => 'CONSTANT', ], 'not goto label - class property use followed by switch-case colon' => [ 'testMarker' => '/* testNotGotoDeclarationClassProperty */', 'testContent' => 'property', ], 'not goto label - global constant followed by ternary else' => [ 'testMarker' => '/* testNotGotoDeclarationGlobalConstantInTernary */', 'testContent' => 'CONST_A', ], 'not goto label - global constant after ternary else' => [ 'testMarker' => '/* testNotGotoDeclarationGlobalConstantInTernary */', 'testContent' => 'CONST_B', ], 'not goto label - name of backed enum' => [ 'testMarker' => '/* testNotGotoDeclarationEnumWithType */', 'testContent' => 'Suit', ], ]; }//end dataNotAGotoDeclaration() }//end class
[-] BackfillExplicitOctalNotationTest.php
[edit]
[-] PHPOpenTagEOF2Test.inc
[edit]
[-] BackfillEnumTest.inc
[edit]
[-] PHPOpenTagEOF1Test.php
[edit]
[-] BackfillAsymmetricVisibilityTest.php
[edit]
[-] EnumCaseTest.php
[edit]
[-] StableCommentWhitespaceTest.inc
[edit]
[-] HeredocNowdocTest.inc
[edit]
[-] TypeIntersectionTest.php
[edit]
[-] DNFTypesParseError2Test.php
[edit]
[-] TypeIntersectionTest.inc
[edit]
[-] NamedFunctionCallArgumentsTest.inc
[edit]
[-] TypedConstantsTest.inc
[edit]
[-] UndoNamespacedNameSingleTokenTest.php
[edit]
[-] BackfillFnTokenParseErrorTest.inc
[edit]
[+]
..
[-] StableCommentWhitespaceWinTest.php
[edit]
[-] DNFTypesTest.inc
[edit]
[-] DNFTypesParseError1Test.inc
[edit]
[-] BitwiseOrTest.php
[edit]
[-] BackfillFnTokenParseErrorTest.php
[edit]
[-] DoubleQuotedStringTest.php
[edit]
[-] BackfillReadonlyTest.inc
[edit]
[-] PHPOpenTagEOF1Test.inc
[edit]
[-] PHPOpenTagEOF2Test.php
[edit]
[-] BackfillNumericSeparatorTest.inc
[edit]
[-] ArrayKeywordTest.inc
[edit]
[-] BackfillMatchTokenTest.php
[edit]
[-] DoubleArrowTest.inc
[edit]
[-] HeredocStringTest.inc
[edit]
[-] GotoLabelTest.inc
[edit]
[-] OtherContextSensitiveKeywordsTest.php
[edit]
[-] StableCommentWhitespaceTest.php
[edit]
[-] NullsafeObjectOperatorTest.php
[edit]
[-] DNFTypesParseError1Test.php
[edit]
[-] AttributesTest.php
[edit]
[-] ExitKeywordTest.inc
[edit]
[-] HeredocParseErrorTest.php
[edit]
[-] AnonClassParenthesisOwnerTest.php
[edit]
[-] NullableVsInlineThenTest.inc
[edit]
[-] ArrayKeywordTest.php
[edit]
[-] NullsafeObjectOperatorTest.inc
[edit]
[-] BackfillExplicitOctalNotationTest.inc
[edit]
[-] ResolveSimpleTokenTest.inc
[edit]
[-] DNFTypesParseError2Test.inc
[edit]
[-] BackfillEnumTest.php
[edit]
[-] YieldTest.inc
[edit]
[-] BackfillReadonlyTest.php
[edit]
[-] HeredocNowdocTest.php
[edit]
[-] ShortArrayTest.inc
[edit]
[-] DefaultKeywordTest.php
[edit]
[-] StableCommentWhitespaceWinTest.inc
[edit]
[-] BitwiseOrTest.inc
[edit]
[-] DNFTypesTest.php
[edit]
[-] DoubleArrowTest.php
[edit]
[-] EnumCaseTest.inc
[edit]
[-] TypedConstantsTest.php
[edit]
[-] BackfillNumericSeparatorTest.php
[edit]
[-] BackfillFnTokenTest.php
[edit]
[-] FinallyTest.inc
[edit]
[-] HeredocStringTest.php
[edit]
[-] ShortArrayTest.php
[edit]
[-] BackfillMatchTokenTest.inc
[edit]
[-] NullableVsInlineThenTest.php
[edit]
[-] DoubleQuotedStringTest.inc
[edit]
[-] GotoLabelTest.php
[edit]
[-] ExitKeywordTest.php
[edit]
[-] HeredocParseErrorTest.inc
[edit]
[-] ResolveSimpleTokenTest.php
[edit]
[-] UndoNamespacedNameSingleTokenTest.inc
[edit]
[-] OtherContextSensitiveKeywordsTest.inc
[edit]
[-] NamedFunctionCallArgumentsTest.php
[edit]
[-] AnonClassParenthesisOwnerTest.inc
[edit]
[-] PHPOpenTagEOF3Test.inc
[edit]
[-] BackfillFnTokenTest.inc
[edit]
[-] BackfillAsymmetricVisibilityTest.inc
[edit]
[-] AttributesTest.inc
[edit]
[-] ContextSensitiveKeywordsTest.inc
[edit]
[-] FinallyTest.php
[edit]
[-] PHPOpenTagEOF3Test.php
[edit]
[-] YieldTest.php
[edit]
[-] DefaultKeywordTest.inc
[edit]
[-] ContextSensitiveKeywordsTest.php
[edit]