Documentation

BackfillMatchTokenTest extends AbstractTokenizerTestCase
in package

FinalYes

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.
dataMatchExpression()  : array<string, array<string, string|int>>
Data provider.
dataNotAMatchStructure()  : array<string, array<string, string>>
Data provider.
dataSwitchCaseVersusMatch()  : array<string, array<string, string|int>>
Data provider.
dataSwitchExpression()  : array<string, array<string, string|int>>
Data provider.
testMatchExpression()  : void
Test tokenization of match expressions.
testNotAMatchStructure()  : void
Verify that "match" keywords which are not match control structures get tokenized as T_STRING and don't have the extra token array indexes.
testSwitchCaseVersusMatch()  : void
Verify that the tokenization of a switch case/default structure containing a match structure or contained *in* a match structure is not affected by the backfill.
testSwitchExpression()  : void
Verify that the tokenization of switch structures is not affected by the backfill.
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.
parenthesisTestHelper()  : void
Helper function to verify that all parenthesis related array indexes for a control structure token are set correctly.
scopeTestHelper()  : void
Helper function to verify that all scope related array indexes for a control structure are set correctly.

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.

dataMatchExpression()

Data provider.

public static dataMatchExpression() : array<string, array<string, string|int>>
Tags
see
testMatchExpression()
Return values
array<string, array<string, string|int>>

dataNotAMatchStructure()

Data provider.

public static dataNotAMatchStructure() : array<string, array<string, string>>
Tags
see
testNotAMatchStructure()
Return values
array<string, array<string, string>>

dataSwitchCaseVersusMatch()

Data provider.

public static dataSwitchCaseVersusMatch() : array<string, array<string, string|int>>
Tags
see
testSwitchCaseVersusMatch()
Return values
array<string, array<string, string|int>>

dataSwitchExpression()

Data provider.

public static dataSwitchExpression() : array<string, array<string, string|int>>
Tags
see
testSwitchExpression()
Return values
array<string, array<string, string|int>>

testMatchExpression()

Test tokenization of match expressions.

public testMatchExpression(string $testMarker, int $openerOffset, int $closerOffset[, string $testContent = 'match' ]) : void
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.

$testContent : string = 'match'

The token content to look for.

Tags
dataProvider

dataMatchExpression

covers

testNotAMatchStructure()

Verify that "match" keywords which are not match control structures get tokenized as T_STRING and don't have the extra token array indexes.

public testNotAMatchStructure(string $testMarker[, string $testContent = 'match' ]) : void
Parameters
$testMarker : string

The comment prefacing the target token.

$testContent : string = 'match'

The token content to look for.

Tags
dataProvider

dataNotAMatchStructure

covers
covers

testSwitchCaseVersusMatch()

Verify that the tokenization of a switch case/default structure containing a match structure or contained *in* a match structure is not affected by the backfill.

public testSwitchCaseVersusMatch(string $testMarker, int $openerOffset, int $closerOffset) : void
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.

Tags
dataProvider

dataSwitchCaseVersusMatch

covers
covers

testSwitchExpression()

Verify that the tokenization of switch structures is not affected by the backfill.

public testSwitchExpression(string $testMarker, int $openerOffset, int $closerOffset) : void
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.

Tags
dataProvider

dataSwitchExpression

covers
covers

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
int

initializeFile()

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
before

parenthesisTestHelper()

Helper function to verify that all parenthesis related array indexes for a control structure token are set correctly.

private parenthesisTestHelper(int $token) : void
Parameters
$token : int

The position of the control structure token.

scopeTestHelper()

Helper function to verify that all scope related array indexes for a control structure are set correctly.

private scopeTestHelper(string $token, int $openerOffset, int $closerOffset[, bool $skipScopeCloserCheck = false ]) : void
Parameters
$token : string

The control structure token to check.

$openerOffset : int

The expected offset of the scope opener in relation to the control structure token.

$closerOffset : int

The expected offset of the scope closer in relation to the control structure token.

$skipScopeCloserCheck : bool = false

Whether to skip the scope closer check. This should be set to "true" when testing nested arrow functions, where the "inner" arrow function shares a scope closer with the "outer" arrow function, as the 'scope_condition' for the scope closer of the "inner" arrow function will point to the "outer" arrow function.


        
On this page

Search results