Skip to content

Commit

Permalink
Tests: add extra tests for the default keyword tokenization
Browse files Browse the repository at this point in the history
  • Loading branch information
jrfnl committed May 27, 2021
1 parent 16b6dda commit 65ab395
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/Core/Tokenizer/DefaultKeywordTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,11 @@ function switchWithConstantNonDefault($i) {
return 2;
}
}

class Foo {
/* testClassConstant */
const DEFAULT = 'foo';

/* testMethodDeclaration */
public function default() {}
}
27 changes: 27 additions & 0 deletions tests/Core/Tokenizer/DefaultKeywordTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 65ab395

Please sign in to comment.