Skip to content

Commit 65ab395

Browse files
committed
Tests: add extra tests for the default keyword tokenization
1 parent 16b6dda commit 65ab395

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

tests/Core/Tokenizer/DefaultKeywordTest.inc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,11 @@ function switchWithConstantNonDefault($i) {
193193
return 2;
194194
}
195195
}
196+
197+
class Foo {
198+
/* testClassConstant */
199+
const DEFAULT = 'foo';
200+
201+
/* testMethodDeclaration */
202+
public function default() {}
203+
}

tests/Core/Tokenizer/DefaultKeywordTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,36 @@ public function dataNotDefaultKeyword()
267267
'class-property-in-switch-case' => ['/* testClassPropertyInSwitchCase */'],
268268
'namespaced-constant-in-switch-case' => ['/* testNamespacedConstantInSwitchCase */'],
269269
'namespace-relative-constant-in-switch-case' => ['/* testNamespaceRelativeConstantInSwitchCase */'],
270+
271+
'class-constant-declaration' => ['/* testClassConstant */'],
272+
'class-method-declaration' => [
273+
'/* testMethodDeclaration */',
274+
'default',
275+
],
270276
];
271277

272278
}//end dataNotDefaultKeyword()
273279

274280

281+
/**
282+
* Test a specific edge case where a scope opener would be incorrectly set.
283+
*
284+
* @link https://github.com/squizlabs/PHP_CodeSniffer/issues/3326
285+
*
286+
* @return void
287+
*/
288+
public function testIssue3326()
289+
{
290+
$tokens = self::$phpcsFile->getTokens();
291+
292+
$token = $this->getTargetToken('/* testClassConstant */', [T_SEMICOLON]);
293+
$tokenArray = $tokens[$token];
294+
295+
$this->assertArrayNotHasKey('scope_condition', $tokenArray, 'Scope condition is set');
296+
$this->assertArrayNotHasKey('scope_opener', $tokenArray, 'Scope opener is set');
297+
$this->assertArrayNotHasKey('scope_closer', $tokenArray, 'Scope closer is set');
298+
299+
}//end testIssue3326()
300+
301+
275302
}//end class

0 commit comments

Comments
 (0)