GetDeclarationNameJSTest
extends AbstractMethodUnitTest
in package
Tests for the \PHP_CodeSniffer\Files\File:getDeclarationName 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
- dataGetDeclarationName() : array<string, array<string, string|array<string|int, int|string>>>
- Data provider.
- dataGetDeclarationNameNull() : array<string, array<string, 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.
- testGetDeclarationName() : void
- Test retrieving the name of a function or OO structure.
- testGetDeclarationNameES6Method() : void
- Test retrieving the name of JS ES6 class method.
- testGetDeclarationNameNull() : void
- Test receiving "null" when passed an anonymous construct or in case of a parse error.
- testInvalidTokenPassed() : void
- Test receiving an expected exception when a non-supported token is passed.
Properties
$fileExtension
The file extension of the test case file (without leading dot).
protected
static string
$fileExtension
= 'js'
$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
dataGetDeclarationName()
Data provider.
public
static dataGetDeclarationName() : array<string, array<string, string|array<string|int, int|string>>>
Tags
Return values
array<string, array<string, string|array<string|int, int|string>>>dataGetDeclarationNameNull()
Data provider.
public
static dataGetDeclarationNameNull() : array<string, array<string, int|string>>
Tags
Return values
array<string, array<string, 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
testGetDeclarationName()
Test retrieving the name of a function or OO structure.
public
testGetDeclarationName(string $testMarker, string $expected[, array<string|int, int|string>|null $targetType = null ]) : void
Parameters
- $testMarker : string
-
The comment which prefaces the target token in the test file.
- $expected : string
-
Expected function output.
- $targetType : array<string|int, int|string>|null = null
-
Token type of the token to get as stackPtr.
Tags
testGetDeclarationNameES6Method()
Test retrieving the name of JS ES6 class method.
public
testGetDeclarationNameES6Method() : void
testGetDeclarationNameNull()
Test receiving "null" when passed an anonymous construct or in case of a parse error.
public
testGetDeclarationNameNull(string $testMarker, int|string $targetType) : void
Parameters
- $testMarker : string
-
The comment which prefaces the target token in the test file.
- $targetType : int|string
-
Token type of the token to get as stackPtr.
Tags
testInvalidTokenPassed()
Test receiving an expected exception when a non-supported token is passed.
public
testInvalidTokenPassed() : void