RecurseScopeMapDefaultKeywordConditionsTest
extends AbstractTokenizerTestCase
in package
Table of Contents
Properties
- $fileExtension : string
- The file extension of the test case file (without leading dot).
- $phpcsFile : File
- The \PHP_CodeSniffer\Files\File object containing the parsed contents of the test case file.
- $tabWidth : int
- The tab width setting to use when tokenizing the file.
Methods
- clearResolvedTokensCache() : void
- Clear the static "resolved tokens" cache property on the Tokenizer\PHP class.
- dataMatchDefault() : array<string, array<string, string>>
- Data provider.
- dataNotDefaultKeyword() : array<string, array<string, string>>
- Data provider.
- dataSwitchDefault() : array<string, array<string, string|int>>
- Data provider.
- testIssue3326() : void
- Test a specific edge case where a scope opener would be incorrectly set.
- testMatchDefault() : void
- Test the retokenization of the `default` keyword for match structure to `T_MATCH_DEFAULT`.
- testNotDefaultKeyword() : void
- Verify that the retokenization of `T_DEFAULT` tokens in match constructs, doesn't negatively impact the tokenization of `T_STRING` tokens with the contents 'default' which aren't in actual fact the default keyword.
- testSwitchDefault() : void
- Verify that the retokenization of `T_DEFAULT` tokens in match constructs, doesn't negatively impact the tokenization of `T_DEFAULT` tokens in switch control structures.
- getTargetToken() : int
- Get the token pointer for a target token based on a specific comment found on the line before.
- initializeFile() : void
- Initialize & tokenize \PHP_CodeSniffer\Files\File with code from the test case file.
Properties
$fileExtension
The file extension of the test case file (without leading dot).
protected
string
$fileExtension
= 'inc'
This allows child classes to overrule the default inc with, for instance,
js or css when applicable.
$phpcsFile
The \PHP_CodeSniffer\Files\File object containing the parsed contents of the test case file.
protected
File
$phpcsFile
$tabWidth
The tab width setting to use when tokenizing the file.
protected
int
$tabWidth
= 4
This allows for test case files to use a different tab width than the default.
Methods
clearResolvedTokensCache()
Clear the static "resolved tokens" cache property on the Tokenizer\PHP class.
public
static clearResolvedTokensCache() : void
This method should be used selectively by tests to ensure the code under test is actually hit by the test testing the code.
dataMatchDefault()
Data provider.
public
static dataMatchDefault() : array<string, array<string, string>>
Tags
Return values
array<string, array<string, string>>dataNotDefaultKeyword()
Data provider.
public
static dataNotDefaultKeyword() : array<string, array<string, string>>
Tags
Return values
array<string, array<string, string>>dataSwitchDefault()
Data provider.
public
static dataSwitchDefault() : array<string, array<string, string|int>>
Tags
Return values
array<string, array<string, string|int>>testIssue3326()
Test a specific edge case where a scope opener would be incorrectly set.
public
testIssue3326() : void
Tags
testMatchDefault()
Test the retokenization of the `default` keyword for match structure to `T_MATCH_DEFAULT`.
public
testMatchDefault(string $testMarker[, string $testContent = 'default' ]) : void
Note: Cases and default structures within a match structure do NOT get case/default scope conditions, in contrast to case and default structures in switch control structures.
Parameters
- $testMarker : string
-
The comment prefacing the target token.
- $testContent : string = 'default'
-
The token content to look for.
Tags
testNotDefaultKeyword()
Verify that the retokenization of `T_DEFAULT` tokens in match constructs, doesn't negatively impact the tokenization of `T_STRING` tokens with the contents 'default' which aren't in actual fact the default keyword.
public
testNotDefaultKeyword(string $testMarker[, string $testContent = 'DEFAULT' ]) : void
Parameters
- $testMarker : string
-
The comment prefacing the target token.
- $testContent : string = 'DEFAULT'
-
The token content to look for.
Tags
testSwitchDefault()
Verify that the retokenization of `T_DEFAULT` tokens in match constructs, doesn't negatively impact the tokenization of `T_DEFAULT` tokens in switch control structures.
public
testSwitchDefault(string $testMarker, int $openerOffset, int $closerOffset[, int|null $conditionStop = null ][, string $testContent = 'default' ]) : void
Note: Cases and default structures within a switch control structure do get case/default scope conditions.
Parameters
- $testMarker : string
-
The comment prefacing the target token.
- $openerOffset : int
-
The expected offset of the scope opener in relation to the testMarker.
- $closerOffset : int
-
The expected offset of the scope closer in relation to the testMarker.
- $conditionStop : int|null = null
-
The expected offset at which tokens stop having T_DEFAULT as a scope condition.
- $testContent : string = 'default'
-
The token content to look for.
Tags
getTargetToken()
Get the token pointer for a target token based on a specific comment found on the line before.
protected
getTargetToken(string $commentString, int|string|array<string|int, mixed> $tokenType[, string $tokenContent = null ]) : int
Note: the test delimiter comment MUST start with "/* test" to allow this function to distinguish between comments used in a test and test delimiters.
Parameters
- $commentString : string
-
The delimiter comment to look for.
- $tokenType : int|string|array<string|int, mixed>
-
The type of token(s) to look for.
- $tokenContent : string = null
-
Optional. The token content for the target token.
Return values
intinitializeFile()
Initialize & tokenize \PHP_CodeSniffer\Files\File with code from the test case file.
protected
initializeFile() : void
The test case file for a unit test class has to be in the same directory directory and use the same file name as the test class, using the .inc extension.