Documentation

GetMethodParametersTest extends AbstractMethodUnitTest
in package

FinalYes

Tests for the \PHP_CodeSniffer\Files\File::getMethodParameters 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

dataInvalidUse()  : array<string, array<string|int, string>>
Data Provider.
dataNoParams()  : array<string, array<string|int, int|string|array<string|int, int|string>>>
Data Provider.
dataUnexpectedTokenException()  : array<string, array<string, int|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.
testArrayDefaultValues()  : void
Verify default value parsing with array values.
testArrayHint()  : void
Verify array hint parsing.
testArrowFunction()  : void
Verify that arrow functions are supported.
testArrowFunctionParamListWithTrailingComma()  : void
Verify arrow function declarations with trailing commas are handled correctly.
testArrowFunctionReturnByRef()  : void
Verify that arrow functions are supported.
testArrowFunctionWithAllTypes()  : void
Verify correctly recognizing all type declarations supported by PHP when used with an arrow function.
testBitwiseAndConstantExpressionDefaultValue()  : void
Verify "bitwise and" in default value !== pass-by-reference.
testClosure()  : void
Verify handling of a closure.
testClosureParamListWithTrailingComma()  : void
Verify closure declarations with trailing commas are handled correctly.
testClosureUse()  : void
Verify handling of a closure T_USE token correctly.
testClosureUseWithTrailingComma()  : void
Verify closure T_USE statements with trailing commas are handled correctly.
testCommentsInParameter()  : void
Verify and document behaviour when there are comments within a parameter declaration.
testConstantDefaultValueSecondParam()  : void
Verify having a T_STRING constant as a default value for the second parameter.
testDefaultValues()  : void
Verify default value parsing.
testFunctionParamListWithTrailingComma()  : void
Verify function declarations with trailing commas are handled correctly.
testInvalidUse()  : void
Test receiving an expected exception when a non-closure use token is passed.
testMessyDeclaration()  : void
Verify handling of a declaration interlaced with whitespace and comments.
testNameSpacedTypeDeclaration()  : void
Verify distinquishing between a nullable type and a ternary within a default expression.
testNamespaceOperatorTypeHint()  : void
Verify recognition of type declarations using the namespace operator.
testNoParams()  : void
Test receiving an empty array when there are no parameters.
testNullableTypeHint()  : void
Verify nullable type hint parsing.
testParameterAttributesInFunctionDeclaration()  : void
Verify behaviour when parameters have attributes attached.
testPassByReference()  : void
Verify pass-by-reference parsing.
testPHP81ConstructorPropertyPromotionWithOnlyReadOnly()  : void
Verify recognition of PHP8 constructor with property promotion using PHP 8.1 readonly keyword without explicit visibility.
testPHP81ConstructorPropertyPromotionWithReadOnly()  : void
Verify recognition of PHP8 constructor with property promotion using PHP 8.1 readonly keyword.
testPHP81ConstructorPropertyPromotionWithReadOnlyNoTypeDeclaration()  : void
Verify recognition of PHP8 constructor with property promotion using PHP 8.1 readonly keyword without a property type.
testPHP81IllegalIntersectionTypes()  : void
Verify recognition of PHP8.1 intersection type declaration with illegal simple types.
testPHP81IntersectionTypesWithSpreadOperatorAndReference()  : void
Verify recognition of PHP8.1 intersection type declaration when the variable has either a spread operator or a reference.
testPHP81MoreIntersectionTypes()  : void
Verify recognition of PHP8.1 intersection type declaration with more types.
testPHP81NewInInitializers()  : void
Verify behaviour when the default value uses the "new" keyword, as is allowed per PHP 8.1.
testPHP81NullableIntersectionTypes()  : void
Verify recognition of PHP8.1 intersection type declaration with (illegal) nullability.
testPHP82DNFTypes()  : void
Verify recognition of 8.2 DNF parameter type declarations.
testPHP82DNFTypesIllegalNullable()  : void
Verify recognition of PHP 8.2 DNF parameter type declarations using the nullability operator (not allowed).
testPHP82DNFTypesInArrow()  : void
Verify recognition of PHP 8.2 DNF parameter type declarations in an arrow function.
testPHP82DNFTypesWithSpreadOperatorAndReference()  : void
Verify recognition of PHP 8.2 DNF parameter type declarations when the variable has either a spread operator or a reference.
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.
testPHP8ConstructorPropertyPromotionAbstractMethod()  : void
Verify behaviour when an abstract constructor uses PHP 8 property promotion syntax.
testPHP8ConstructorPropertyPromotionAndNormalParam()  : void
Verify recognition of PHP8 constructor with both property promotion as well as normal parameters.
testPHP8ConstructorPropertyPromotionGlobalFunction()  : void
Verify behaviour when a non-constructor function uses PHP 8 property promotion syntax.
testPHP8ConstructorPropertyPromotionNoTypes()  : void
Verify recognition of PHP8 constructor property promotion without type declaration, with defaults.
testPHP8ConstructorPropertyPromotionWithTypes()  : void
Verify recognition of PHP8 constructor property promotion with type declarations.
testPHP8DuplicateTypeInUnionWhitespaceAndComment()  : void
Verify recognition of PHP8 type declaration with (illegal) duplicate types.
testPHP8IntersectionTypes()  : void
Verify recognition of PHP8.1 intersection type declaration.
testPHP8MixedTypeHint()  : void
Verify recognition of PHP8 mixed type declaration.
testPHP8MixedTypeHintNullable()  : void
Verify recognition of PHP8 mixed type declaration with 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.
testPHP8UnionTypesSimpleWithBitwiseOrInDefault()  : void
Verify recognition of PHP8 union type declaration with a bitwise or in the default value.
testPHP8UnionTypesTwoClasses()  : void
Verify recognition of PHP8 union type declaration with two classes.
testPHP8UnionTypesWithSpreadOperatorAndReference()  : void
Verify recognition of PHP8 union type declaration when the variable has either a spread operator or a reference.
testScalarTernaryExpressionInDefault()  : void
Verify distinquishing between a nullable type and a ternary within a default expression.
testSelfTypeHint()  : void
Verify self type hint parsing.
testSingleDefaultValue()  : void
Verify default value parsing with a single function param.
testTypeHint()  : void
Verify type hint parsing.
testUnexpectedTokenException()  : void
Test receiving an expected exception when a non function/use token is passed.
testVariable()  : void
Verify variable.
testVariadicByRefFunction()  : void
Verify a variadic parameter passed by reference being recognized correctly.
testVariadicFunction()  : void
Verify a variadic parameter being recognized correctly.
testVariadicFunctionClassType()  : void
Verify handling of a variadic parameter with a class based type declaration.
testWithAllTypes()  : void
Verify correctly recognizing all type declarations supported by PHP.
getMethodParametersTestHelper()  : 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

dataInvalidUse()

Data Provider.

public static dataInvalidUse() : array<string, array<string|int, string>>
Tags
see
testInvalidUse()

For the array format.

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

dataNoParams()

Data Provider.

public static dataNoParams() : array<string, array<string|int, int|string|array<string|int, int|string>>>
Tags
see
testNoParams()

For the array format.

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

dataUnexpectedTokenException()

Data Provider.

public static dataUnexpectedTokenException() : array<string, array<string, int|string|array<string|int, int|string>>>
Tags
see
testUnexpectedTokenException()

For the array format.

Return values
array<string, array<string, int|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
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

testArrayDefaultValues()

Verify default value parsing with array values.

public testArrayDefaultValues() : void

testArrowFunctionParamListWithTrailingComma()

Verify arrow function declarations with trailing commas are handled correctly.

public testArrowFunctionParamListWithTrailingComma() : void

testArrowFunctionReturnByRef()

Verify that arrow functions are supported.

public testArrowFunctionReturnByRef() : void

testArrowFunctionWithAllTypes()

Verify correctly recognizing all type declarations supported by PHP when used with an arrow function.

public testArrowFunctionWithAllTypes() : void

testBitwiseAndConstantExpressionDefaultValue()

Verify "bitwise and" in default value !== pass-by-reference.

public testBitwiseAndConstantExpressionDefaultValue() : void

testClosureParamListWithTrailingComma()

Verify closure declarations with trailing commas are handled correctly.

public testClosureParamListWithTrailingComma() : void

testClosureUse()

Verify handling of a closure T_USE token correctly.

public testClosureUse() : void

testClosureUseWithTrailingComma()

Verify closure T_USE statements with trailing commas are handled correctly.

public testClosureUseWithTrailingComma() : void

testCommentsInParameter()

Verify and document behaviour when there are comments within a parameter declaration.

public testCommentsInParameter() : void

testConstantDefaultValueSecondParam()

Verify having a T_STRING constant as a default value for the second parameter.

public testConstantDefaultValueSecondParam() : void

testFunctionParamListWithTrailingComma()

Verify function declarations with trailing commas are handled correctly.

public testFunctionParamListWithTrailingComma() : void

testInvalidUse()

Test receiving an expected exception when a non-closure use token is passed.

public testInvalidUse(string $identifier) : void
Parameters
$identifier : string

The comment which preceeds the test.

Tags
dataProvider

dataInvalidUse

testMessyDeclaration()

Verify handling of a declaration interlaced with whitespace and comments.

public testMessyDeclaration() : void

testNameSpacedTypeDeclaration()

Verify distinquishing between a nullable type and a ternary within a default expression.

public testNameSpacedTypeDeclaration() : void

testNamespaceOperatorTypeHint()

Verify recognition of type declarations using the namespace operator.

public testNamespaceOperatorTypeHint() : void

testNoParams()

Test receiving an empty array when there are no parameters.

public testNoParams(string $commentString[, int|string|array<string|int, int|string> $targetTokenType = [T_FUNCTION, T_CLOSURE, T_FN] ]) : void
Parameters
$commentString : string

The comment which preceeds the test.

$targetTokenType : int|string|array<string|int, int|string> = [T_FUNCTION, T_CLOSURE, T_FN]

Optional. The token type to search for after $commentString. Defaults to the function/closure/arrow tokens.

Tags
dataProvider

dataNoParams

testParameterAttributesInFunctionDeclaration()

Verify behaviour when parameters have attributes attached.

public testParameterAttributesInFunctionDeclaration() : void

testPHP81ConstructorPropertyPromotionWithOnlyReadOnly()

Verify recognition of PHP8 constructor with property promotion using PHP 8.1 readonly keyword without explicit visibility.

public testPHP81ConstructorPropertyPromotionWithOnlyReadOnly() : void

testPHP81ConstructorPropertyPromotionWithReadOnly()

Verify recognition of PHP8 constructor with property promotion using PHP 8.1 readonly keyword.

public testPHP81ConstructorPropertyPromotionWithReadOnly() : void

testPHP81ConstructorPropertyPromotionWithReadOnlyNoTypeDeclaration()

Verify recognition of PHP8 constructor with property promotion using PHP 8.1 readonly keyword without a property type.

public testPHP81ConstructorPropertyPromotionWithReadOnlyNoTypeDeclaration() : void

testPHP81IllegalIntersectionTypes()

Verify recognition of PHP8.1 intersection type declaration with illegal simple types.

public testPHP81IllegalIntersectionTypes() : void

testPHP81IntersectionTypesWithSpreadOperatorAndReference()

Verify recognition of PHP8.1 intersection type declaration when the variable has either a spread operator or a reference.

public testPHP81IntersectionTypesWithSpreadOperatorAndReference() : void

testPHP81MoreIntersectionTypes()

Verify recognition of PHP8.1 intersection type declaration with more types.

public testPHP81MoreIntersectionTypes() : void

testPHP81NewInInitializers()

Verify behaviour when the default value uses the "new" keyword, as is allowed per PHP 8.1.

public testPHP81NewInInitializers() : void

testPHP81NullableIntersectionTypes()

Verify recognition of PHP8.1 intersection type declaration with (illegal) nullability.

public testPHP81NullableIntersectionTypes() : void

testPHP82DNFTypes()

Verify recognition of 8.2 DNF parameter type declarations.

public testPHP82DNFTypes() : void

testPHP82DNFTypesIllegalNullable()

Verify recognition of PHP 8.2 DNF parameter type declarations using the nullability operator (not allowed).

public testPHP82DNFTypesIllegalNullable() : void

testPHP82DNFTypesInArrow()

Verify recognition of PHP 8.2 DNF parameter type declarations in an arrow function.

public testPHP82DNFTypesInArrow() : void

testPHP82DNFTypesWithSpreadOperatorAndReference()

Verify recognition of PHP 8.2 DNF parameter type declarations when the variable has either a spread operator or a reference.

public testPHP82DNFTypesWithSpreadOperatorAndReference() : 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

testPHP8ConstructorPropertyPromotionAbstractMethod()

Verify behaviour when an abstract constructor uses PHP 8 property promotion syntax.

public testPHP8ConstructorPropertyPromotionAbstractMethod() : void

testPHP8ConstructorPropertyPromotionAndNormalParam()

Verify recognition of PHP8 constructor with both property promotion as well as normal parameters.

public testPHP8ConstructorPropertyPromotionAndNormalParam() : void

testPHP8ConstructorPropertyPromotionGlobalFunction()

Verify behaviour when a non-constructor function uses PHP 8 property promotion syntax.

public testPHP8ConstructorPropertyPromotionGlobalFunction() : void

testPHP8ConstructorPropertyPromotionNoTypes()

Verify recognition of PHP8 constructor property promotion without type declaration, with defaults.

public testPHP8ConstructorPropertyPromotionNoTypes() : void

testPHP8ConstructorPropertyPromotionWithTypes()

Verify recognition of PHP8 constructor property promotion with type declarations.

public testPHP8ConstructorPropertyPromotionWithTypes() : 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()

Verify recognition of PHP8 mixed type declaration.

public testPHP8MixedTypeHint() : void

testPHP8MixedTypeHintNullable()

Verify recognition of PHP8 mixed type declaration with 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

testPHP8UnionTypesSimpleWithBitwiseOrInDefault()

Verify recognition of PHP8 union type declaration with a bitwise or in the default value.

public testPHP8UnionTypesSimpleWithBitwiseOrInDefault() : void

testPHP8UnionTypesTwoClasses()

Verify recognition of PHP8 union type declaration with two classes.

public testPHP8UnionTypesTwoClasses() : void

testPHP8UnionTypesWithSpreadOperatorAndReference()

Verify recognition of PHP8 union type declaration when the variable has either a spread operator or a reference.

public testPHP8UnionTypesWithSpreadOperatorAndReference() : void

testScalarTernaryExpressionInDefault()

Verify distinquishing between a nullable type and a ternary within a default expression.

public testScalarTernaryExpressionInDefault() : void

testSingleDefaultValue()

Verify default value parsing with a single function param.

public testSingleDefaultValue() : void

testUnexpectedTokenException()

Test receiving an expected exception when a non function/use token is passed.

public testUnexpectedTokenException(string $commentString, int|string|array<string|int, int|string> $targetTokenType) : void
Parameters
$commentString : string

The comment which preceeds the test.

$targetTokenType : int|string|array<string|int, int|string>

The token type to search for after $commentString.

Tags
dataProvider

dataUnexpectedTokenException

testVariadicByRefFunction()

Verify a variadic parameter passed by reference being recognized correctly.

public testVariadicByRefFunction() : void

testVariadicFunction()

Verify a variadic parameter being recognized correctly.

public testVariadicFunction() : void

testVariadicFunctionClassType()

Verify handling of a variadic parameter with a class based type declaration.

public testVariadicFunctionClassType() : void

testWithAllTypes()

Verify correctly recognizing all type declarations supported by PHP.

public testWithAllTypes() : void

getMethodParametersTestHelper()

Test helper.

private getMethodParametersTestHelper(string $commentString, array<int, array<string, int|string|bool>> $expected[, int|string|array<string|int, int|string> $targetType = [T_FUNCTION, T_CLOSURE, T_FN] ]) : void
Parameters
$commentString : string

The comment which preceeds the test.

$expected : array<int, array<string, int|string|bool>>

The expected function output.

$targetType : int|string|array<string|int, int|string> = [T_FUNCTION, T_CLOSURE, T_FN]

Optional. The token type to search for after $marker. Defaults to the function/closure/arrow tokens.


        
On this page

Search results