GetMethodPropertiesTest
extends AbstractMethodUnitTest
in package
Tests for the \PHP_CodeSniffer\Files\File::getMethodProperties 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
- dataNotAFunctionException() : array<string, array<string, string|int|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.
- testAbstractMethod() : void
- Test a basic abstract method.
- testAbstractReturnMethod() : void
- Test an abstract method with a return type.
- testArrowFunction() : void
- Test a static arrow function.
- testArrowFunctionArrayReturnValue() : void
- Test handling of incorrect tokenization of array return type declarations for arrow functions in a very specific code sample in PHPCS < 3.5.4.
- testArrowFunctionReturnByRef() : void
- Test handling of an arrow function returning by reference.
- testBasicFunction() : void
- Test a basic function.
- testBasicMethod() : void
- Test a basic method.
- testClosureWithUseMultiParamWithReturnType() : void
- Test handling of closure declarations with a use variable import with a return type declaration.
- testClosureWithUseNoReturnType() : void
- Test handling of closure declarations with a use variable import without a return type declaration.
- testClosureWithUseNoReturnTypeIllegalUseProp() : void
- Test handling of closure declarations with an illegal use variable for a property import (not allowed in PHP) without a return type declaration.
- testClosureWithUseWithReturnType() : void
- Test handling of closure declarations with a use variable import with a return type declaration.
- testFinalMethod() : void
- Test a basic final method.
- testFunctionDeclarationNestedInTernaryPHPCS2975() : void
- Test handling of function declaration nested in a ternary, where the colon for the return type was incorrectly tokenized as T_INLINE_ELSE prior to PHPCS 3.5.7.
- testInterfaceMethod() : void
- Test a basic interface method.
- testMessyNullableReturnMethod() : void
- Test a public method with a nullable return type.
- testNamespaceOperatorTypeHint() : void
- Test a function with return type using the namespace operator.
- testNestedClosure() : void
- Test a closure used as a function argument.
- testNotAFunctionException() : void
- Test receiving an expected exception when a non function token is passed.
- testNullableReturnMethod() : void
- Test a public method with a nullable return type.
- testPHP81IllegalIntersectionTypes() : void
- Verify recognition of PHP8.1 intersection type declaration with illegal simple types.
- testPHP81IntersectionArrowFunction() : void
- Verify recognition of PHP8.1 intersection type declaration in arrow function.
- testPHP81MoreIntersectionTypes() : void
- Verify recognition of PHP8.1 intersection type declaration with more types.
- testPHP81NeverType() : void
- Verify recognition of PHP8.1 type "never".
- testPHP81NullableIntersectionTypes() : void
- Verify recognition of PHP8.1 intersection type declaration with (illegal) nullability.
- testPHP81NullableNeverType() : void
- Verify recognition of PHP8.1 type "never" with (illegal) nullability.
- testPHP82DNFType() : void
- Verify recognition of PHP 8.2 DNF return type declaration.
- testPHP82DNFTypeAbstractMethod() : void
- Verify recognition of PHP 8.2 DNF return type declaration on an abstract method.
- testPHP82DNFTypeClosure() : void
- Verify recognition of PHP 8.2 DNF return type declaration on a closure.
- testPHP82DNFTypeFn() : void
- Verify recognition of PHP 8.2 DNF return type declaration on an arrow function.
- testPHP82DNFTypeIllegalNullable() : void
- Verify recognition of PHP 8.2 DNF return type declaration with illegal nullability.
- testPHP82PseudoTypeFalseAndTrue() : void
- Verify recognition of PHP 8.2 type declaration with (illegal) type false combined with type true.
- testPHP82PseudoTypeTrue() : void
- Verify recognition of PHP 8.2 stand-alone `true` type.
- testPHP8DuplicateTypeInUnionWhitespaceAndComment() : void
- Verify recognition of PHP8 type declaration with (illegal) duplicate types.
- testPHP8IntersectionTypes() : void
- Verify recognition of PHP8.1 intersection type declaration.
- testPHP8MixedTypeHint() : void
- Test a function with return type "mixed".
- testPHP8MixedTypeHintNullable() : void
- Test a function with return type "mixed" and nullability.
- testPHP8ObjectAndClass() : void
- Verify recognition of PHP8 type declaration with (illegal) type object combined with a class name.
- testPHP8PseudoTypeFalse() : void
- Verify recognition of PHP8 type declaration with (illegal) single type false.
- testPHP8PseudoTypeFalseAndBool() : void
- Verify recognition of PHP8 type declaration with (illegal) type false combined with type bool.
- testPHP8PseudoTypeIterableAndArray() : void
- Verify recognition of PHP8 type declaration with (illegal) type iterable combined with array/Traversable.
- testPHP8PseudoTypeNull() : void
- Verify recognition of PHP8 type declaration with (illegal) single type null.
- testPHP8UnionTypesAllBaseTypes() : void
- Verify recognition of PHP8 union type declaration with all base types.
- testPHP8UnionTypesAllPseudoTypes() : void
- Verify recognition of PHP8 union type declaration with all pseudo types.
- testPHP8UnionTypesNullable() : void
- Verify recognition of PHP8 union type declaration with (illegal) nullability.
- testPHP8UnionTypesSimple() : void
- Verify recognition of PHP8 union type declaration.
- testPHP8UnionTypesTwoClasses() : void
- Verify recognition of PHP8 union type declaration with two classes.
- testPhpcsIssue1264() : void
- Test for incorrect tokenization of array return type declarations in PHPCS < 2.8.0.
- testPrivateStaticMethod() : void
- Test a private static method.
- testProtectedReturnMethod() : void
- Test a protected method with a return type.
- testPublicReturnMethod() : void
- Test a public method with a return type.
- testReturnFunction() : void
- Test a function with a return type.
- testReturnMultilineNamespace() : void
- Test a method with a messy namespaces return type.
- testReturnNamespace() : void
- Test a method with a namespaced return type.
- testReturnPartiallyQualifiedName() : void
- Test a method with a partially qualified namespaced return type.
- testReturnTypeNullableStatic() : void
- Test a function with return type "?static".
- testReturnTypeStatic() : void
- Test a function with return type "static".
- testReturnUnqualifiedName() : void
- Test a method with an unqualified named return type.
- getMethodPropertiesTestHelper() : void
- Test helper.
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
dataNotAFunctionException()
Data Provider.
public
static dataNotAFunctionException() : array<string, array<string, string|int|array<string|int, int|string>>>
Tags
Return values
array<string, array<string, string|int|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
testAbstractMethod()
Test a basic abstract method.
public
testAbstractMethod() : void
testAbstractReturnMethod()
Test an abstract method with a return type.
public
testAbstractReturnMethod() : void
testArrowFunction()
Test a static arrow function.
public
testArrowFunction() : void
testArrowFunctionArrayReturnValue()
Test handling of incorrect tokenization of array return type declarations for arrow functions in a very specific code sample in PHPCS < 3.5.4.
public
testArrowFunctionArrayReturnValue() : void
Tags
testArrowFunctionReturnByRef()
Test handling of an arrow function returning by reference.
public
testArrowFunctionReturnByRef() : void
testBasicFunction()
Test a basic function.
public
testBasicFunction() : void
testBasicMethod()
Test a basic method.
public
testBasicMethod() : void
testClosureWithUseMultiParamWithReturnType()
Test handling of closure declarations with a use variable import with a return type declaration.
public
testClosureWithUseMultiParamWithReturnType() : void
testClosureWithUseNoReturnType()
Test handling of closure declarations with a use variable import without a return type declaration.
public
testClosureWithUseNoReturnType() : void
testClosureWithUseNoReturnTypeIllegalUseProp()
Test handling of closure declarations with an illegal use variable for a property import (not allowed in PHP) without a return type declaration.
public
testClosureWithUseNoReturnTypeIllegalUseProp() : void
testClosureWithUseWithReturnType()
Test handling of closure declarations with a use variable import with a return type declaration.
public
testClosureWithUseWithReturnType() : void
testFinalMethod()
Test a basic final method.
public
testFinalMethod() : void
testFunctionDeclarationNestedInTernaryPHPCS2975()
Test handling of function declaration nested in a ternary, where the colon for the return type was incorrectly tokenized as T_INLINE_ELSE prior to PHPCS 3.5.7.
public
testFunctionDeclarationNestedInTernaryPHPCS2975() : void
testInterfaceMethod()
Test a basic interface method.
public
testInterfaceMethod() : void
testMessyNullableReturnMethod()
Test a public method with a nullable return type.
public
testMessyNullableReturnMethod() : void
testNamespaceOperatorTypeHint()
Test a function with return type using the namespace operator.
public
testNamespaceOperatorTypeHint() : void
testNestedClosure()
Test a closure used as a function argument.
public
testNestedClosure() : void
testNotAFunctionException()
Test receiving an expected exception when a non function token is passed.
public
testNotAFunctionException(string $commentString, string|int|array<string|int, int|string> $targetTokenType) : void
Parameters
- $commentString : string
-
The comment which preceeds the test.
- $targetTokenType : string|int|array<string|int, int|string>
-
The token type to search for after $commentString.
Tags
testNullableReturnMethod()
Test a public method with a nullable return type.
public
testNullableReturnMethod() : void
testPHP81IllegalIntersectionTypes()
Verify recognition of PHP8.1 intersection type declaration with illegal simple types.
public
testPHP81IllegalIntersectionTypes() : void
testPHP81IntersectionArrowFunction()
Verify recognition of PHP8.1 intersection type declaration in arrow function.
public
testPHP81IntersectionArrowFunction() : void
testPHP81MoreIntersectionTypes()
Verify recognition of PHP8.1 intersection type declaration with more types.
public
testPHP81MoreIntersectionTypes() : void
testPHP81NeverType()
Verify recognition of PHP8.1 type "never".
public
testPHP81NeverType() : void
testPHP81NullableIntersectionTypes()
Verify recognition of PHP8.1 intersection type declaration with (illegal) nullability.
public
testPHP81NullableIntersectionTypes() : void
testPHP81NullableNeverType()
Verify recognition of PHP8.1 type "never" with (illegal) nullability.
public
testPHP81NullableNeverType() : void
testPHP82DNFType()
Verify recognition of PHP 8.2 DNF return type declaration.
public
testPHP82DNFType() : void
testPHP82DNFTypeAbstractMethod()
Verify recognition of PHP 8.2 DNF return type declaration on an abstract method.
public
testPHP82DNFTypeAbstractMethod() : void
testPHP82DNFTypeClosure()
Verify recognition of PHP 8.2 DNF return type declaration on a closure.
public
testPHP82DNFTypeClosure() : void
testPHP82DNFTypeFn()
Verify recognition of PHP 8.2 DNF return type declaration on an arrow function.
public
testPHP82DNFTypeFn() : void
testPHP82DNFTypeIllegalNullable()
Verify recognition of PHP 8.2 DNF return type declaration with illegal nullability.
public
testPHP82DNFTypeIllegalNullable() : void
testPHP82PseudoTypeFalseAndTrue()
Verify recognition of PHP 8.2 type declaration with (illegal) type false combined with type true.
public
testPHP82PseudoTypeFalseAndTrue() : void
testPHP82PseudoTypeTrue()
Verify recognition of PHP 8.2 stand-alone `true` type.
public
testPHP82PseudoTypeTrue() : void
testPHP8DuplicateTypeInUnionWhitespaceAndComment()
Verify recognition of PHP8 type declaration with (illegal) duplicate types.
public
testPHP8DuplicateTypeInUnionWhitespaceAndComment() : void
testPHP8IntersectionTypes()
Verify recognition of PHP8.1 intersection type declaration.
public
testPHP8IntersectionTypes() : void
testPHP8MixedTypeHint()
Test a function with return type "mixed".
public
testPHP8MixedTypeHint() : void
testPHP8MixedTypeHintNullable()
Test a function with return type "mixed" and nullability.
public
testPHP8MixedTypeHintNullable() : void
testPHP8ObjectAndClass()
Verify recognition of PHP8 type declaration with (illegal) type object combined with a class name.
public
testPHP8ObjectAndClass() : void
testPHP8PseudoTypeFalse()
Verify recognition of PHP8 type declaration with (illegal) single type false.
public
testPHP8PseudoTypeFalse() : void
testPHP8PseudoTypeFalseAndBool()
Verify recognition of PHP8 type declaration with (illegal) type false combined with type bool.
public
testPHP8PseudoTypeFalseAndBool() : void
testPHP8PseudoTypeIterableAndArray()
Verify recognition of PHP8 type declaration with (illegal) type iterable combined with array/Traversable.
public
testPHP8PseudoTypeIterableAndArray() : void
testPHP8PseudoTypeNull()
Verify recognition of PHP8 type declaration with (illegal) single type null.
public
testPHP8PseudoTypeNull() : void
testPHP8UnionTypesAllBaseTypes()
Verify recognition of PHP8 union type declaration with all base types.
public
testPHP8UnionTypesAllBaseTypes() : void
testPHP8UnionTypesAllPseudoTypes()
Verify recognition of PHP8 union type declaration with all pseudo types.
public
testPHP8UnionTypesAllPseudoTypes() : void
Note: "Resource" is not a type, but seen as a class name.
testPHP8UnionTypesNullable()
Verify recognition of PHP8 union type declaration with (illegal) nullability.
public
testPHP8UnionTypesNullable() : void
testPHP8UnionTypesSimple()
Verify recognition of PHP8 union type declaration.
public
testPHP8UnionTypesSimple() : void
testPHP8UnionTypesTwoClasses()
Verify recognition of PHP8 union type declaration with two classes.
public
testPHP8UnionTypesTwoClasses() : void
testPhpcsIssue1264()
Test for incorrect tokenization of array return type declarations in PHPCS < 2.8.0.
public
testPhpcsIssue1264() : void
Tags
testPrivateStaticMethod()
Test a private static method.
public
testPrivateStaticMethod() : void
testProtectedReturnMethod()
Test a protected method with a return type.
public
testProtectedReturnMethod() : void
testPublicReturnMethod()
Test a public method with a return type.
public
testPublicReturnMethod() : void
testReturnFunction()
Test a function with a return type.
public
testReturnFunction() : void
testReturnMultilineNamespace()
Test a method with a messy namespaces return type.
public
testReturnMultilineNamespace() : void
testReturnNamespace()
Test a method with a namespaced return type.
public
testReturnNamespace() : void
testReturnPartiallyQualifiedName()
Test a method with a partially qualified namespaced return type.
public
testReturnPartiallyQualifiedName() : void
testReturnTypeNullableStatic()
Test a function with return type "?static".
public
testReturnTypeNullableStatic() : void
testReturnTypeStatic()
Test a function with return type "static".
public
testReturnTypeStatic() : void
testReturnUnqualifiedName()
Test a method with an unqualified named return type.
public
testReturnUnqualifiedName() : void
getMethodPropertiesTestHelper()
Test helper.
private
getMethodPropertiesTestHelper(string $commentString, array<string, string|int|bool> $expected) : void
Parameters
- $commentString : string
-
The comment which preceeds the test.
- $expected : array<string, string|int|bool>
-
The expected function output.