From 65ab395d3d563c4396aaa5056198dd13fade7491 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 12 May 2021 06:54:06 +0200 Subject: [PATCH] Tests: add extra tests for the default keyword tokenization --- tests/Core/Tokenizer/DefaultKeywordTest.inc | 8 ++++++ tests/Core/Tokenizer/DefaultKeywordTest.php | 27 +++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/tests/Core/Tokenizer/DefaultKeywordTest.inc b/tests/Core/Tokenizer/DefaultKeywordTest.inc index 6de4485730..648149d2ff 100644 --- a/tests/Core/Tokenizer/DefaultKeywordTest.inc +++ b/tests/Core/Tokenizer/DefaultKeywordTest.inc @@ -193,3 +193,11 @@ function switchWithConstantNonDefault($i) { return 2; } } + +class Foo { + /* testClassConstant */ + const DEFAULT = 'foo'; + + /* testMethodDeclaration */ + public function default() {} +} diff --git a/tests/Core/Tokenizer/DefaultKeywordTest.php b/tests/Core/Tokenizer/DefaultKeywordTest.php index 2d1e68cb6c..9a5b061a05 100644 --- a/tests/Core/Tokenizer/DefaultKeywordTest.php +++ b/tests/Core/Tokenizer/DefaultKeywordTest.php @@ -267,9 +267,36 @@ public function dataNotDefaultKeyword() 'class-property-in-switch-case' => ['/* testClassPropertyInSwitchCase */'], 'namespaced-constant-in-switch-case' => ['/* testNamespacedConstantInSwitchCase */'], 'namespace-relative-constant-in-switch-case' => ['/* testNamespaceRelativeConstantInSwitchCase */'], + + 'class-constant-declaration' => ['/* testClassConstant */'], + 'class-method-declaration' => [ + '/* testMethodDeclaration */', + 'default', + ], ]; }//end dataNotDefaultKeyword() + /** + * Test a specific edge case where a scope opener would be incorrectly set. + * + * @link https://github.com/squizlabs/PHP_CodeSniffer/issues/3326 + * + * @return void + */ + public function testIssue3326() + { + $tokens = self::$phpcsFile->getTokens(); + + $token = $this->getTargetToken('/* testClassConstant */', [T_SEMICOLON]); + $tokenArray = $tokens[$token]; + + $this->assertArrayNotHasKey('scope_condition', $tokenArray, 'Scope condition is set'); + $this->assertArrayNotHasKey('scope_opener', $tokenArray, 'Scope opener is set'); + $this->assertArrayNotHasKey('scope_closer', $tokenArray, 'Scope closer is set'); + + }//end testIssue3326() + + }//end class