Documentation

BackfillFnTokenTest 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.
dataInMatchValue()  : array<string, array<string, string|int>>
Data provider.
dataKeywordReturnTypes()  : array<string, array<string, string>>
Data provider.
dataNotAnArrowFunction()  : array<string, array<string, string>>
Data provider.
dataSimple()  : array<string, array<string, string>>
Data provider.
testArrayIndex()  : void
Test arrow functions using an array index.
testArrayValue()  : void
Test arrow functions that are used as array values.
testArrayValueNoTrailingComma()  : void
Test arrow functions that are used as array values with no trailing comma.
testChainedFunctionCall()  : void
Test arrow functions that are included in chained calls.
testClosure()  : void
Test arrow functions that use closures.
testComment()  : void
Test comments inside arrow function definitions.
testDNFParamType()  : void
Test arrow function with a DNF parameter type.
testDNFParamTypeWithReturnByRef()  : void
Test arrow function which returns by reference with a DNF parameter type.
testDNFReturnType()  : void
Test arrow function with a DNF return type.
testFunctionArgument()  : void
Test arrow functions that are used as function arguments.
testFunctionCall()  : void
Test arrow functions that call functions.
testGrouped()  : void
Test arrow functions that are grouped by parenthesis.
testHeredoc()  : void
Test heredocs inside arrow function definitions.
testInMatchValue()  : void
Test match control structure returning arrow functions.
testIntersectionParamType()  : void
Test arrow function with an intersection parameter type.
testIntersectionReturnType()  : void
Test arrow function with an intersection return type.
testKeywordReturnTypes()  : void
Test arrow functions that use keyword return types.
testNamespaceOperatorInTypes()  : void
Test arrow functions that use the namespace operator in the return type.
testNestedInMethod()  : void
Test arrow function nested within a method declaration.
testNestedInner()  : void
Test nested arrow functions.
testNestedOuter()  : void
Test nested arrow functions.
testNestedSharedCloser()  : void
Test nested arrow functions with a shared closer.
testNotAnArrowFunction()  : void
Verify that "fn" keywords which are not arrow functions get tokenized as T_STRING and don't have the extra token array indexes.
testNullableNamespace()  : void
Test arrow functions that use nullable namespace types.
testReference()  : void
Test arrow functions that return a reference.
testReturnType()  : void
Test arrow functions with a return type.
testSimple()  : void
Test simple arrow functions.
testTernary()  : void
Test arrow functions used in ternary operators.
testTernaryWithTypes()  : void
Test typed arrow functions used in ternary operators.
testUnionParamType()  : void
Test arrow function with a union parameter type.
testUnionReturnType()  : void
Test arrow function with a union return type.
testUnionReturnTypeWithFalse()  : void
Test arrow function with a union return type.
testUnionReturnTypeWithTrue()  : void
Test arrow function with a union return type.
testWhitespace()  : void
Test whitespace inside arrow function definitions.
testWithMatchValue()  : void
Test arrow function returning a match control structure.
testWithMatchValueAndMore()  : void
Test arrow function returning a match control structure with something behind it.
testYield()  : void
Test arrow functions that use the yield keyword.
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.
backfillHelper()  : void
Helper function to check that all token keys are correctly set for T_FN tokens.
scopePositionTestHelper()  : void
Helper function to check that the scope opener/closer positions are correctly set for T_FN tokens.

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.

dataInMatchValue()

Data provider.

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

dataKeywordReturnTypes()

Data provider.

public static dataKeywordReturnTypes() : array<string, array<string, string>>
Tags
see
testKeywordReturnTypes()
Return values
array<string, array<string, string>>

dataNotAnArrowFunction()

Data provider.

public static dataNotAnArrowFunction() : array<string, array<string, string>>
Tags
see
testNotAnArrowFunction()
Return values
array<string, array<string, string>>

dataSimple()

Data provider.

public static dataSimple() : array<string, array<string, string>>
Tags
see
testSimple()
Return values
array<string, array<string, string>>

testArrayIndex()

Test arrow functions using an array index.

public testArrayIndex() : void
Tags
covers

testArrayValue()

Test arrow functions that are used as array values.

public testArrayValue() : void
Tags
covers

testArrayValueNoTrailingComma()

Test arrow functions that are used as array values with no trailing comma.

public testArrayValueNoTrailingComma() : void
Tags
covers

testChainedFunctionCall()

Test arrow functions that are included in chained calls.

public testChainedFunctionCall() : void
Tags
covers

testClosure()

Test arrow functions that use closures.

public testClosure() : void
Tags
covers

testComment()

Test comments inside arrow function definitions.

public testComment() : void
Tags
covers

testDNFParamType()

Test arrow function with a DNF parameter type.

public testDNFParamType() : void
Tags
covers

testDNFParamTypeWithReturnByRef()

Test arrow function which returns by reference with a DNF parameter type.

public testDNFParamTypeWithReturnByRef() : void
Tags
covers

testDNFReturnType()

Test arrow function with a DNF return type.

public testDNFReturnType() : void
Tags
covers

testFunctionArgument()

Test arrow functions that are used as function arguments.

public testFunctionArgument() : void
Tags
covers

testFunctionCall()

Test arrow functions that call functions.

public testFunctionCall() : void
Tags
covers

testGrouped()

Test arrow functions that are grouped by parenthesis.

public testGrouped() : void
Tags
covers

testHeredoc()

Test heredocs inside arrow function definitions.

public testHeredoc() : void
Tags
covers

testInMatchValue()

Test match control structure returning arrow functions.

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

$expectedCloserType : string

The type of token expected for the scope closer.

$expectedCloserFriendlyName : string

A friendly name for the type of token expected for the scope closer to be used in the error message for failing tests.

Tags
dataProvider

dataInMatchValue

covers

testIntersectionParamType()

Test arrow function with an intersection parameter type.

public testIntersectionParamType() : void
Tags
covers

testIntersectionReturnType()

Test arrow function with an intersection return type.

public testIntersectionReturnType() : void
Tags
covers

testKeywordReturnTypes()

Test arrow functions that use keyword return types.

public testKeywordReturnTypes(string $testMarker) : void
Parameters
$testMarker : string

The comment prefacing the target token.

Tags
dataProvider

dataKeywordReturnTypes

covers

testNamespaceOperatorInTypes()

Test arrow functions that use the namespace operator in the return type.

public testNamespaceOperatorInTypes() : void
Tags
covers

testNestedInMethod()

Test arrow function nested within a method declaration.

public testNestedInMethod() : void
Tags
covers

testNestedInner()

Test nested arrow functions.

public testNestedInner() : void
Tags
covers

testNestedOuter()

Test nested arrow functions.

public testNestedOuter() : void
Tags
covers

testNestedSharedCloser()

Test nested arrow functions with a shared closer.

public testNestedSharedCloser() : void
Tags
covers

testNotAnArrowFunction()

Verify that "fn" keywords which are not arrow functions get tokenized as T_STRING and don't have the extra token array indexes.

public testNotAnArrowFunction(string $testMarker[, string $testContent = 'fn' ]) : void
Parameters
$testMarker : string

The comment prefacing the target token.

$testContent : string = 'fn'

The token content to look for.

Tags
dataProvider

dataNotAnArrowFunction

covers

testNullableNamespace()

Test arrow functions that use nullable namespace types.

public testNullableNamespace() : void
Tags
covers

testReference()

Test arrow functions that return a reference.

public testReference() : void
Tags
covers

testReturnType()

Test arrow functions with a return type.

public testReturnType() : void
Tags
covers

testSimple()

Test simple arrow functions.

public testSimple(string $testMarker) : void
Parameters
$testMarker : string

The comment prefacing the target token.

Tags
dataProvider

dataSimple

covers

testTernary()

Test arrow functions used in ternary operators.

public testTernary() : void
Tags
covers

testTernaryWithTypes()

Test typed arrow functions used in ternary operators.

public testTernaryWithTypes() : void
Tags
covers

testUnionParamType()

Test arrow function with a union parameter type.

public testUnionParamType() : void
Tags
covers

testUnionReturnType()

Test arrow function with a union return type.

public testUnionReturnType() : void
Tags
covers

testUnionReturnTypeWithFalse()

Test arrow function with a union return type.

public testUnionReturnTypeWithFalse() : void
Tags
covers

testUnionReturnTypeWithTrue()

Test arrow function with a union return type.

public testUnionReturnTypeWithTrue() : void
Tags
covers

testWhitespace()

Test whitespace inside arrow function definitions.

public testWhitespace() : void
Tags
covers

testWithMatchValue()

Test arrow function returning a match control structure.

public testWithMatchValue() : void
Tags
covers

testWithMatchValueAndMore()

Test arrow function returning a match control structure with something behind it.

public testWithMatchValueAndMore() : void
Tags
covers

testYield()

Test arrow functions that use the yield keyword.

public testYield() : void
Tags
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

backfillHelper()

Helper function to check that all token keys are correctly set for T_FN tokens.

private backfillHelper(int $token[, bool $skipScopeCloserCheck = false ]) : void
Parameters
$token : int

The T_FN token to check.

$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.

scopePositionTestHelper()

Helper function to check that the scope opener/closer positions are correctly set for T_FN tokens.

private scopePositionTestHelper(int $token, int $openerOffset, int $closerOffset[, string $expectedCloserType = 'semicolon' ]) : void
Parameters
$token : int

The T_FN token to check.

$openerOffset : int

The expected offset of the scope opener in relation to the fn keyword.

$closerOffset : int

The expected offset of the scope closer in relation to the fn keyword.

$expectedCloserType : string = 'semicolon'

Optional. The type of token expected for the scope closer.


        
On this page

Search results