Documentation

AttributesTest 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.
dataAttribute()  : array<string, array<string, string|int|array<string|int, int|string>>>
Data provider.
dataAttributeOnParameters()  : array<string, array<string, string|int|array<string|int, int|string>>>
Data provider.
dataAttributeOnTextLookingLikeCloseTag()  : array<string, array<string, string|int|array<string|int, array<string|int, string>>|array<string|int, int|string>>>
Data provider.
testAttribute()  : void
Test that attributes are parsed correctly.
testAttributeAndLineComment()  : void
Test that attribute followed by a line comment is parsed correctly.
testAttributeContainingTextLookingLikeCloseTag()  : void
Test that an attribute containing text which looks like a PHP close tag is tokenized correctly.
testAttributeOnParameters()  : void
Test that attributes on function declaration parameters are parsed correctly.
testInvalidAttribute()  : void
Test that invalid attribute (or comment starting with #[ and without ]) are parsed correctly.
testNestedAttributes()  : void
Test that nested attributes are parsed correctly.
testTwoAttributesOnTheSameLine()  : void
Test that multiple attributes on the same line are parsed correctly.
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.

dataAttribute()

Data provider.

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

dataAttributeOnParameters()

Data provider.

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

dataAttributeOnTextLookingLikeCloseTag()

Data provider.

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

testAttribute()

Test that attributes are parsed correctly.

public testAttribute(string $testMarker, int $length, array<string|int, int|string> $tokenCodes) : void
Parameters
$testMarker : string

The comment which prefaces the target token in the test file.

$length : int

The number of tokens between opener and closer.

$tokenCodes : array<string|int, int|string>

The codes of tokens inside the attributes.

Tags
dataProvider

dataAttribute

covers
covers
covers

testAttributeAndLineComment()

Test that attribute followed by a line comment is parsed correctly.

public testAttributeAndLineComment() : void
Tags
covers
covers
covers

testAttributeContainingTextLookingLikeCloseTag()

Test that an attribute containing text which looks like a PHP close tag is tokenized correctly.

public testAttributeContainingTextLookingLikeCloseTag(string $testMarker, int $length, array<string|int, array<string|int, string>> $expectedTokensAttribute, array<string|int, int|string> $expectedTokensAfter) : void
Parameters
$testMarker : string

The comment which prefaces the target token in the test file.

$length : int

The number of tokens between opener and closer.

$expectedTokensAttribute : array<string|int, array<string|int, string>>

The codes of tokens inside the attributes.

$expectedTokensAfter : array<string|int, int|string>

The codes of tokens after the attributes.

Tags
covers
dataProvider

dataAttributeOnTextLookingLikeCloseTag

testAttributeOnParameters()

Test that attributes on function declaration parameters are parsed correctly.

public testAttributeOnParameters(string $testMarker, int $position, int $length, array<string|int, int|string> $tokenCodes) : void
Parameters
$testMarker : string

The comment which prefaces the target token in the test file.

$position : int

The token position (starting from T_FUNCTION) of T_ATTRIBUTE token.

$length : int

The number of tokens between opener and closer.

$tokenCodes : array<string|int, int|string>

The codes of tokens inside the attributes.

Tags
dataProvider

dataAttributeOnParameters

covers
covers
covers

testInvalidAttribute()

Test that invalid attribute (or comment starting with #[ and without ]) are parsed correctly.

public testInvalidAttribute() : void
Tags
covers
covers
covers

testNestedAttributes()

Test that nested attributes are parsed correctly.

public testNestedAttributes() : void
Tags
covers
covers
covers
covers

testTwoAttributesOnTheSameLine()

Test that multiple attributes on the same line are parsed correctly.

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

        
On this page

Search results