PhpcsAnnotationsInDocBlockTest
extends CommentTestCase
in package
Tests that PHPCS native annotations in docblocks are tokenized correctly.
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
- clearResolvedTokensCache() : void
- Clear the static "resolved tokens" cache property on the Tokenizer\PHP class.
- dataDocblockOpenerCloser() : array<string, array<string, string|int|array<string|int, int>>>
- Data provider.
- testDocblockOpenerCloser() : void
- Test whether the docblock opener and closer have the expected extra keys.
- testMultiLineDocDisableAnnotationAtEnd() : void
- Verify tokenization of a single line DocBlock containing a PHPCS disable annotation at the end.
- testMultiLineDocDisableAnnotationAtStart() : void
- Verify tokenization of a single line DocBlock containing a PHPCS disable annotation at the start.
- testMultiLineDocDisableAnnotationInMiddle() : void
- Verify tokenization of a single line DocBlock containing a PHPCS disable annotation in the middle.
- testMultiLineDocEnableAnnotationAtEnd() : void
- Verify tokenization of a single line DocBlock containing a PHPCS enable annotation at the end.
- testMultiLineDocEnableAnnotationAtStart() : void
- Verify tokenization of a single line DocBlock containing a PHPCS enable annotation at the start.
- testMultiLineDocEnableAnnotationInMiddle() : void
- Verify tokenization of a single line DocBlock containing a PHPCS enable annotation in the middle.
- testMultiLineDocIgnoreAnnotationAtEnd() : void
- Verify tokenization of a single line DocBlock containing a PHPCS ignore annotation at the end.
- testMultiLineDocIgnoreAnnotationAtStart() : void
- Verify tokenization of a single line DocBlock containing a PHPCS ignore annotation at the start.
- testMultiLineDocIgnoreAnnotationInMiddle() : void
- Verify tokenization of a single line DocBlock containing a PHPCS ignore annotation in the middle.
- testMultiLineDocIgnoreFileAnnotationAtEnd() : void
- Verify tokenization of a single line DocBlock containing a PHPCS ignoreFile annotation at the end.
- testMultiLineDocIgnoreFileAnnotationAtStart() : void
- Verify tokenization of a single line DocBlock containing a PHPCS ignoreFile annotation at the start.
- testMultiLineDocIgnoreFileAnnotationInMiddle() : void
- Verify tokenization of a single line DocBlock containing a PHPCS ignoreFile annotation in the middle.
- testSingleLineDocDisableAnnotation() : void
- Verify tokenization of a single line DocBlock containing a PHPCS disable annotation.
- testSingleLineDocEnableAnnotationNoWhitespace() : void
- Verify tokenization of a single line DocBlock containing a PHPCS enable annotation.
- testSingleLineDocIgnoreAnnotation() : void
- Verify tokenization of a single line DocBlock containing a PHPCS ignore annotation.
- testSingleLineDocIgnoreFileAnnotation() : void
- Verify tokenization of a single line DocBlock containing a PHPCS ignoreFile annotation.
- checkTokenSequence() : void
- Test helper. Check a token sequence complies with an expected token sequence.
- 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.
dataDocblockOpenerCloser()
Data provider.
public
static dataDocblockOpenerCloser() : array<string, array<string, string|int|array<string|int, int>>>
Tags
Return values
array<string, array<string, string|int|array<string|int, int>>>testDocblockOpenerCloser()
Test whether the docblock opener and closer have the expected extra keys.
public
testDocblockOpenerCloser(string $marker, int $closerOffset, array<string|int, int> $expectedTags) : void
Parameters
- $marker : string
-
The comment prefacing the target token.
- $closerOffset : int
-
The offset of the closer from the opener.
- $expectedTags : array<string|int, int>
-
The expected tags offsets array.
Tags
testMultiLineDocDisableAnnotationAtEnd()
Verify tokenization of a single line DocBlock containing a PHPCS disable annotation at the end.
public
testMultiLineDocDisableAnnotationAtEnd() : void
testMultiLineDocDisableAnnotationAtStart()
Verify tokenization of a single line DocBlock containing a PHPCS disable annotation at the start.
public
testMultiLineDocDisableAnnotationAtStart() : void
testMultiLineDocDisableAnnotationInMiddle()
Verify tokenization of a single line DocBlock containing a PHPCS disable annotation in the middle.
public
testMultiLineDocDisableAnnotationInMiddle() : void
testMultiLineDocEnableAnnotationAtEnd()
Verify tokenization of a single line DocBlock containing a PHPCS enable annotation at the end.
public
testMultiLineDocEnableAnnotationAtEnd() : void
testMultiLineDocEnableAnnotationAtStart()
Verify tokenization of a single line DocBlock containing a PHPCS enable annotation at the start.
public
testMultiLineDocEnableAnnotationAtStart() : void
testMultiLineDocEnableAnnotationInMiddle()
Verify tokenization of a single line DocBlock containing a PHPCS enable annotation in the middle.
public
testMultiLineDocEnableAnnotationInMiddle() : void
testMultiLineDocIgnoreAnnotationAtEnd()
Verify tokenization of a single line DocBlock containing a PHPCS ignore annotation at the end.
public
testMultiLineDocIgnoreAnnotationAtEnd() : void
testMultiLineDocIgnoreAnnotationAtStart()
Verify tokenization of a single line DocBlock containing a PHPCS ignore annotation at the start.
public
testMultiLineDocIgnoreAnnotationAtStart() : void
testMultiLineDocIgnoreAnnotationInMiddle()
Verify tokenization of a single line DocBlock containing a PHPCS ignore annotation in the middle.
public
testMultiLineDocIgnoreAnnotationInMiddle() : void
testMultiLineDocIgnoreFileAnnotationAtEnd()
Verify tokenization of a single line DocBlock containing a PHPCS ignoreFile annotation at the end.
public
testMultiLineDocIgnoreFileAnnotationAtEnd() : void
testMultiLineDocIgnoreFileAnnotationAtStart()
Verify tokenization of a single line DocBlock containing a PHPCS ignoreFile annotation at the start.
public
testMultiLineDocIgnoreFileAnnotationAtStart() : void
testMultiLineDocIgnoreFileAnnotationInMiddle()
Verify tokenization of a single line DocBlock containing a PHPCS ignoreFile annotation in the middle.
public
testMultiLineDocIgnoreFileAnnotationInMiddle() : void
testSingleLineDocDisableAnnotation()
Verify tokenization of a single line DocBlock containing a PHPCS disable annotation.
public
testSingleLineDocDisableAnnotation() : void
testSingleLineDocEnableAnnotationNoWhitespace()
Verify tokenization of a single line DocBlock containing a PHPCS enable annotation.
public
testSingleLineDocEnableAnnotationNoWhitespace() : void
testSingleLineDocIgnoreAnnotation()
Verify tokenization of a single line DocBlock containing a PHPCS ignore annotation.
public
testSingleLineDocIgnoreAnnotation() : void
testSingleLineDocIgnoreFileAnnotation()
Verify tokenization of a single line DocBlock containing a PHPCS ignoreFile annotation.
public
testSingleLineDocIgnoreFileAnnotation() : void
Tags
checkTokenSequence()
Test helper. Check a token sequence complies with an expected token sequence.
protected
checkTokenSequence(int $startPtr, array<string|int, array<int|string, string>> $expectedSequence) : void
Parameters
- $startPtr : int
-
The position in the file to start checking from.
- $expectedSequence : array<string|int, array<int|string, string>>
-
The consecutive token constants and their contents to expect.
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
intinitializeFile()
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.