IsReferenceTest
extends AbstractMethodUnitTest
in package
Tests for the \PHP_CodeSniffer\Files\File::isReference method.
Tags
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
- dataIsReference() : array<string, array<string, string|bool>>
- Data provider for the IsReference test.
- dataNotBitwiseAndToken() : array<string, array<string, string|array<string|int, int|string>>>
- 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.
- testIsReference() : void
- Test correctly identifying whether a "bitwise and" token is a reference or not.
- testNotBitwiseAndToken() : void
- Test that false is returned when a non-"bitwise and" token is passed.
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
dataIsReference()
Data provider for the IsReference test.
public
static dataIsReference() : array<string, array<string, string|bool>>
Tags
Return values
array<string, array<string, string|bool>>dataNotBitwiseAndToken()
Data provider.
public
static dataNotBitwiseAndToken() : array<string, array<string, string|array<string|int, int|string>>>
Tags
Return values
array<string, array<string, string|array<string|int, int|string>>>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
intgetTargetTokenFromFile()
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
Return values
intinitializeFile()
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
testIsReference()
Test correctly identifying whether a "bitwise and" token is a reference or not.
public
testIsReference(string $testMarker, bool $expected) : void
Parameters
- $testMarker : string
-
Comment which precedes the test case.
- $expected : bool
-
Expected function output.
Tags
testNotBitwiseAndToken()
Test that false is returned when a non-"bitwise and" token is passed.
public
testNotBitwiseAndToken(string $testMarker, array<string|int, int|string> $targetTokens) : void
Parameters
- $testMarker : string
-
Comment which precedes the test case.
- $targetTokens : array<string|int, int|string>
-
Type of tokens to look for.