ResolveSimpleTokenTest
extends AbstractTokenizerTestCase
in package
Tests that simple tokens are assigned the correct token type and code.
Tags
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.
- clearTokenCache() : void
- Clear the "resolved tokens" cache before running this test as otherwise the code under test may not be run during the test.
- testAsperand() : void
- Verify tokenization of the silence operator.
- testBacktick() : void
- Verify tokenization of the backtick operator.
- testBitwiseOrInCatch() : void
- Verify tokenization of bitwise operator tokens.
- testBitwiseTokens() : void
- Verify tokenization of bitwise operator tokens.
- testBooleanNot() : void
- Verify tokenization of a boolean not operator.
- testBracesAndColon() : void
- Verify tokenization of parentheses, square brackets, curly brackets and a switch colon.
- testComma() : void
- Verify tokenization of commas.
- testConcat() : void
- Verify tokenization of a concatenation operator.
- testDollarAndCurlies() : void
- Verify tokenization of the dollar token and curlies for a variable variable.
- testGreaterThan() : void
- Verify tokenization of a greater than operator.
- testLessThan() : void
- Verify tokenization of a less than operator.
- testNamedParamColon() : void
- Verify tokenization of colon after named parameter.
- testReturnTypeColon() : void
- Verify tokenization of colon for a return type.
- testSimpleMathTokens() : void
- Verify tokenization of simple math operators.
- testUnaryPlusMinus() : void
- Verify tokenization of unary plus/minus operators.
- 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.
- checkTokenSequence() : void
- Test helper. Check a token sequence complies with an expected token sequence.
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.
clearTokenCache()
Clear the "resolved tokens" cache before running this test as otherwise the code under test may not be run during the test.
public
static clearTokenCache() : void
Tags
testAsperand()
Verify tokenization of the silence operator.
public
testAsperand() : void
testBacktick()
Verify tokenization of the backtick operator.
public
testBacktick() : void
testBitwiseOrInCatch()
Verify tokenization of bitwise operator tokens.
public
testBitwiseOrInCatch() : void
testBitwiseTokens()
Verify tokenization of bitwise operator tokens.
public
testBitwiseTokens() : void
testBooleanNot()
Verify tokenization of a boolean not operator.
public
testBooleanNot() : void
testBracesAndColon()
Verify tokenization of parentheses, square brackets, curly brackets and a switch colon.
public
testBracesAndColon() : void
testComma()
Verify tokenization of commas.
public
testComma() : void
testConcat()
Verify tokenization of a concatenation operator.
public
testConcat() : void
testDollarAndCurlies()
Verify tokenization of the dollar token and curlies for a variable variable.
public
testDollarAndCurlies() : void
testGreaterThan()
Verify tokenization of a greater than operator.
public
testGreaterThan() : void
testLessThan()
Verify tokenization of a less than operator.
public
testLessThan() : void
testNamedParamColon()
Verify tokenization of colon after named parameter.
public
testNamedParamColon() : void
testReturnTypeColon()
Verify tokenization of colon for a return type.
public
testReturnTypeColon() : void
testSimpleMathTokens()
Verify tokenization of simple math operators.
public
testSimpleMathTokens() : void
testUnaryPlusMinus()
Verify tokenization of unary plus/minus operators.
public
testUnaryPlusMinus() : void
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.
Tags
checkTokenSequence()
Test helper. Check a token sequence complies with an expected token sequence.
private
checkTokenSequence(int $startPtr, array<string|int, int|string> $expectedSequence) : void
Parameters
- $startPtr : int
-
The position in the file to start checking from.
- $expectedSequence : array<string|int, int|string>
-
The consecutive token constants to expect.