Documentation

GetTokensAsStringTest extends AbstractMethodUnitTest
in package

FinalYes

Tests for the \PHP_CodeSniffer\Files\File:getTokensAsString method.

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.
$tabWidth  : int
The tab width setting to use when tokenizing the file.

Methods

dataGetOrigContent()  : array<string, array<string, string|int>>
Data provider.
dataGetTokensAsString()  : array<string, array<string, string|int>>
Data provider.
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.
testGetOrigContent()  : void
Test getting a token set as a string with the original, non tab-replaced content.
testGetTokensAsString()  : void
Test getting a token set as a string.
testLengthBeyondEndOfFile()  : void
Test passing a `$length` beyond the end of the file.
testLengthEqualToOrLessThanZero()  : void
Test passing a zero or negative `$length`.
testNonExistentToken()  : void
Test passing a non-existent token pointer.
testNonIntegerLength()  : void
Test passing a non integer `$length`.
testNonIntegerStart()  : void
Test passing a non integer `$start`, like the result of a failed $phpcsFile->findNext().

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

$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

dataGetOrigContent()

Data provider.

public static dataGetOrigContent() : array<string, array<string, string|int>>
Tags
see
testGetOrigContent()

For the array format.

Return values
array<string, array<string, string|int>>

dataGetTokensAsString()

Data provider.

public static dataGetTokensAsString() : array<string, array<string, string|int>>
Tags
see
testGetTokensAsString()

For the array format.

Return values
array<string, array<string, string|int>>

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

testGetOrigContent()

Test getting a token set as a string with the original, non tab-replaced content.

public testGetOrigContent(string $testMarker, int|string $startTokenType, int $length, string $expected) : void
Parameters
$testMarker : string

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

$startTokenType : int|string

The type of token(s) to look for for the start of the string.

$length : int

Token length to get.

$expected : string

The expected function return value.

Tags
dataProvider

dataGetOrigContent

testGetTokensAsString()

Test getting a token set as a string.

public testGetTokensAsString(string $testMarker, int|string $startTokenType, int $length, string $expected) : void
Parameters
$testMarker : string

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

$startTokenType : int|string

The type of token(s) to look for for the start of the string.

$length : int

Token length to get.

$expected : string

The expected function return value.

Tags
dataProvider

dataGetTokensAsString

testLengthBeyondEndOfFile()

Test passing a `$length` beyond the end of the file.

public testLengthBeyondEndOfFile() : void

testLengthEqualToOrLessThanZero()

Test passing a zero or negative `$length`.

public testLengthEqualToOrLessThanZero() : void

testNonExistentToken()

Test passing a non-existent token pointer.

public testNonExistentToken() : void

testNonIntegerLength()

Test passing a non integer `$length`.

public testNonIntegerLength() : void

testNonIntegerStart()

Test passing a non integer `$start`, like the result of a failed $phpcsFile->findNext().

public testNonIntegerStart() : void

        
On this page

Search results