Documentation

AbstractArraySniffTest extends AbstractMethodUnitTest
in package

FinalYes

Tests for the \PHP_CodeSniffer\Sniffs\AbstractArraySniff.

Tags
covers

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.
$sniff  : AbstractArraySniffTestable
The sniff objects we are testing.
$tabWidth  : int
The tab width setting to use when tokenizing the file.

Methods

expectRunTimeException()  : void
Helper method to tell PHPUnit to expect a PHPCS RuntimeException in a PHPUnit cross-version compatible manner.
getTargetToken()  : int
Get the token pointer for a target token based on a specific comment found on the line before.
getTargetTokenFromFile()  : 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.
testArrowFunctionValue()  : void
Test an array of with an arrow function as a value.
testHeredocValues()  : void
Test an array of heredocs.
testMissingKeys()  : void
Test an array of simple keys and values.
testMissingKeysCoalesceTernary()  : void
Test an array of simple keys and values.
testMultiTokenKeys()  : void
Test an array with keys that span multiple tokens.
testSimpleKeyValues()  : void
Test an array of simple keys and values.
testSimpleValues()  : void
Test an array of simple values only.
testTernaryValues()  : void
Test an array of ternary values.

Properties

$fileExtension

The file extension of the test case file (without leading dot).

protected static 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 static File $phpcsFile

$sniff

The sniff objects we are testing.

protected static AbstractArraySniffTestable $sniff

This extends the \PHP_CodeSniffer\Sniffs\AbstractArraySniff class to make the internal workings of the sniff observable.

$tabWidth

The tab width setting to use when tokenizing the file.

protected static int $tabWidth = 4

This allows for test case files to use a different tab width than the default.

Methods

expectRunTimeException()

Helper method to tell PHPUnit to expect a PHPCS RuntimeException in a PHPUnit cross-version compatible manner.

public expectRunTimeException(string $message) : void
Parameters
$message : string

The expected exception message.

getTargetToken()

Get the token pointer for a target token based on a specific comment found on the line before.

public 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

getTargetTokenFromFile()

Get the token pointer for a target token based on a specific comment found on the line before.

public static getTargetTokenFromFile(File $phpcsFile, 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
$phpcsFile : File

The file to find the token in.

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

Tags
throws
Exception

When the test delimiter comment is not found.

throws
Exception

When the test target token is not found.

Return values
int

initializeFile()

Initialize & tokenize \PHP_CodeSniffer\Files\File with code from the test case file.

public static 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
beforeClass

testArrowFunctionValue()

Test an array of with an arrow function as a value.

public testArrowFunctionValue() : void

testMissingKeysCoalesceTernary()

Test an array of simple keys and values.

public testMissingKeysCoalesceTernary() : void

testMultiTokenKeys()

Test an array with keys that span multiple tokens.

public testMultiTokenKeys() : void

testSimpleKeyValues()

Test an array of simple keys and values.

public testSimpleKeyValues() : void

        
On this page

Search results