From 8534f8dddaf1c85d07279507f1edc61f4d2a9dba Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 1 Jan 2024 08:15:03 +0100 Subject: [PATCH 1/4] Tests/GetMemberPropertiesTest: minor tweak ... to improve the descriptiveness of one test. --- tests/Core/File/GetMemberPropertiesTest.inc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Core/File/GetMemberPropertiesTest.inc b/tests/Core/File/GetMemberPropertiesTest.inc index 441bd97772..61ab56564c 100644 --- a/tests/Core/File/GetMemberPropertiesTest.inc +++ b/tests/Core/File/GetMemberPropertiesTest.inc @@ -245,7 +245,7 @@ $anon = class() { public readonly int $readonly; /* testPHP81ReadonlyWithNullableType */ - public readonly ?array $array; + public readonly ?array $readonlyWithNullableType; /* testPHP81ReadonlyWithUnionType */ public readonly string|int $readonlyWithUnionType; From 793bd3cde861b0aa81ddb14ee3626fb10e6123ff Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 1 Jan 2024 08:41:56 +0100 Subject: [PATCH 2/4] Tests/GetMemberPropertiesTest: use named data sets With non-named data sets, when a test fails, PHPUnit will display the number of the test which failed. With tests which have a _lot_ of data sets, this makes it _interesting_ (and time-consuming) to debug those, as one now has to figure out which of the data sets in the data provider corresponds to that number. Using named data sets makes debugging failing tests more straight forward as PHPUnit will display the data set name instead of the number. Using named data sets also documents what exactly each data set is testing. Aside from adding the data set name, this commit also adds the parameter name for each item in the data set, this time in an effort to make it more straight forward to update and add tests as it will be more obvious what each key in the data set signifies. Includes fixing the data types in the docblocks and making them more specific, where relevant. --- tests/Core/File/GetMemberPropertiesTest.php | 466 ++++++++++---------- 1 file changed, 233 insertions(+), 233 deletions(-) diff --git a/tests/Core/File/GetMemberPropertiesTest.php b/tests/Core/File/GetMemberPropertiesTest.php index 36bf4d7d3e..e069c20a59 100644 --- a/tests/Core/File/GetMemberPropertiesTest.php +++ b/tests/Core/File/GetMemberPropertiesTest.php @@ -23,8 +23,8 @@ class GetMemberPropertiesTest extends AbstractMethodUnitTest /** * Test the getMemberProperties() method. * - * @param string $identifier Comment which precedes the test case. - * @param bool $expected Expected function output. + * @param string $identifier Comment which precedes the test case. + * @param array $expected Expected function output. * * @dataProvider dataGetMemberProperties * @@ -48,14 +48,14 @@ public function testGetMemberProperties($identifier, $expected) * * @see testGetMemberProperties() * - * @return array + * @return array>> */ public function dataGetMemberProperties() { return [ - [ - '/* testVar */', - [ + 'var-modifier' => [ + 'identifier' => '/* testVar */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => false, @@ -64,9 +64,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testVarType */', - [ + 'var-modifier-and-type' => [ + 'identifier' => '/* testVarType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => false, @@ -75,9 +75,9 @@ public function dataGetMemberProperties() 'nullable_type' => true, ], ], - [ - '/* testPublic */', - [ + 'public-modifier' => [ + 'identifier' => '/* testPublic */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -86,9 +86,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPublicType */', - [ + 'public-modifier-and-type' => [ + 'identifier' => '/* testPublicType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -97,9 +97,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testProtected */', - [ + 'protected-modifier' => [ + 'identifier' => '/* testProtected */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => false, @@ -108,9 +108,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testProtectedType */', - [ + 'protected-modifier-and-type' => [ + 'identifier' => '/* testProtectedType */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => false, @@ -119,9 +119,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPrivate */', - [ + 'private-modifier' => [ + 'identifier' => '/* testPrivate */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -130,9 +130,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPrivateType */', - [ + 'private-modifier-and-type' => [ + 'identifier' => '/* testPrivateType */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -141,9 +141,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testStatic */', - [ + 'static-modifier' => [ + 'identifier' => '/* testStatic */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => true, @@ -152,9 +152,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testStaticType */', - [ + 'static-modifier-and-type' => [ + 'identifier' => '/* testStaticType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => true, @@ -163,9 +163,9 @@ public function dataGetMemberProperties() 'nullable_type' => true, ], ], - [ - '/* testStaticVar */', - [ + 'static-and-var-modifier' => [ + 'identifier' => '/* testStaticVar */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => true, @@ -174,9 +174,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testVarStatic */', - [ + 'var-and-static-modifier' => [ + 'identifier' => '/* testVarStatic */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => true, @@ -185,9 +185,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPublicStatic */', - [ + 'public-static-modifiers' => [ + 'identifier' => '/* testPublicStatic */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => true, @@ -196,9 +196,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testProtectedStatic */', - [ + 'protected-static-modifiers' => [ + 'identifier' => '/* testProtectedStatic */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => true, @@ -207,9 +207,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPrivateStatic */', - [ + 'private-static-modifiers' => [ + 'identifier' => '/* testPrivateStatic */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => true, @@ -218,9 +218,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testNoPrefix */', - [ + 'no-modifier' => [ + 'identifier' => '/* testNoPrefix */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => false, @@ -229,9 +229,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPublicStaticWithDocblock */', - [ + 'public-and-static-modifier-with-docblock' => [ + 'identifier' => '/* testPublicStaticWithDocblock */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => true, @@ -240,9 +240,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testProtectedStaticWithDocblock */', - [ + 'protected-and-static-modifier-with-docblock' => [ + 'identifier' => '/* testProtectedStaticWithDocblock */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => true, @@ -251,9 +251,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPrivateStaticWithDocblock */', - [ + 'private-and-static-modifier-with-docblock' => [ + 'identifier' => '/* testPrivateStaticWithDocblock */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => true, @@ -262,9 +262,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testGroupType 1 */', - [ + 'property-group-simple-type-prop-1' => [ + 'identifier' => '/* testGroupType 1 */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -273,9 +273,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testGroupType 2 */', - [ + 'property-group-simple-type-prop-2' => [ + 'identifier' => '/* testGroupType 2 */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -284,9 +284,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testGroupNullableType 1 */', - [ + 'property-group-nullable-type-prop-1' => [ + 'identifier' => '/* testGroupNullableType 1 */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => true, @@ -295,9 +295,9 @@ public function dataGetMemberProperties() 'nullable_type' => true, ], ], - [ - '/* testGroupNullableType 2 */', - [ + 'property-group-nullable-type-prop-2' => [ + 'identifier' => '/* testGroupNullableType 2 */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => true, @@ -306,9 +306,9 @@ public function dataGetMemberProperties() 'nullable_type' => true, ], ], - [ - '/* testGroupProtectedStatic 1 */', - [ + 'property-group-protected-static-prop-1' => [ + 'identifier' => '/* testGroupProtectedStatic 1 */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => true, @@ -317,9 +317,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testGroupProtectedStatic 2 */', - [ + 'property-group-protected-static-prop-2' => [ + 'identifier' => '/* testGroupProtectedStatic 2 */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => true, @@ -328,9 +328,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testGroupProtectedStatic 3 */', - [ + 'property-group-protected-static-prop-3' => [ + 'identifier' => '/* testGroupProtectedStatic 3 */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => true, @@ -339,9 +339,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testGroupPrivate 1 */', - [ + 'property-group-private-prop-1' => [ + 'identifier' => '/* testGroupPrivate 1 */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -350,9 +350,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testGroupPrivate 2 */', - [ + 'property-group-private-prop-2' => [ + 'identifier' => '/* testGroupPrivate 2 */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -361,9 +361,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testGroupPrivate 3 */', - [ + 'property-group-private-prop-3' => [ + 'identifier' => '/* testGroupPrivate 3 */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -372,9 +372,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testGroupPrivate 4 */', - [ + 'property-group-private-prop-4' => [ + 'identifier' => '/* testGroupPrivate 4 */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -383,9 +383,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testGroupPrivate 5 */', - [ + 'property-group-private-prop-5' => [ + 'identifier' => '/* testGroupPrivate 5 */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -394,9 +394,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testGroupPrivate 6 */', - [ + 'property-group-private-prop-6' => [ + 'identifier' => '/* testGroupPrivate 6 */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -405,9 +405,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testGroupPrivate 7 */', - [ + 'property-group-private-prop-7' => [ + 'identifier' => '/* testGroupPrivate 7 */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -416,9 +416,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testMessyNullableType */', - [ + 'messy-nullable-type' => [ + 'identifier' => '/* testMessyNullableType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -427,9 +427,9 @@ public function dataGetMemberProperties() 'nullable_type' => true, ], ], - [ - '/* testNamespaceType */', - [ + 'fqn-type' => [ + 'identifier' => '/* testNamespaceType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -438,9 +438,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testNullableNamespaceType 1 */', - [ + 'nullable-classname-type' => [ + 'identifier' => '/* testNullableNamespaceType 1 */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -449,9 +449,9 @@ public function dataGetMemberProperties() 'nullable_type' => true, ], ], - [ - '/* testNullableNamespaceType 2 */', - [ + 'nullable-namespace-relative-class-type' => [ + 'identifier' => '/* testNullableNamespaceType 2 */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => false, @@ -460,9 +460,9 @@ public function dataGetMemberProperties() 'nullable_type' => true, ], ], - [ - '/* testMultilineNamespaceType */', - [ + 'multiline-namespaced-type' => [ + 'identifier' => '/* testMultilineNamespaceType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -471,9 +471,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPropertyAfterMethod */', - [ + 'property-after-method' => [ + 'identifier' => '/* testPropertyAfterMethod */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => true, @@ -482,13 +482,13 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testInterfaceProperty */', - [], + 'invalid-property-in-interface' => [ + 'identifier' => '/* testInterfaceProperty */', + 'expected' => [], ], - [ - '/* testNestedProperty 1 */', - [ + 'property-in-nested-class-1' => [ + 'identifier' => '/* testNestedProperty 1 */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -497,9 +497,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testNestedProperty 2 */', - [ + 'property-in-nested-class-2' => [ + 'identifier' => '/* testNestedProperty 2 */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -508,9 +508,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP8MixedTypeHint */', - [ + 'php8-mixed-type' => [ + 'identifier' => '/* testPHP8MixedTypeHint */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => true, @@ -519,9 +519,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP8MixedTypeHintNullable */', - [ + 'php8-nullable-mixed-type' => [ + 'identifier' => '/* testPHP8MixedTypeHintNullable */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -530,9 +530,9 @@ public function dataGetMemberProperties() 'nullable_type' => true, ], ], - [ - '/* testNamespaceOperatorTypeHint */', - [ + 'namespace-operator-type-declaration' => [ + 'identifier' => '/* testNamespaceOperatorTypeHint */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -541,9 +541,9 @@ public function dataGetMemberProperties() 'nullable_type' => true, ], ], - [ - '/* testPHP8UnionTypesSimple */', - [ + 'php8-union-types-simple' => [ + 'identifier' => '/* testPHP8UnionTypesSimple */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -552,9 +552,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP8UnionTypesTwoClasses */', - [ + 'php8-union-types-two-classes' => [ + 'identifier' => '/* testPHP8UnionTypesTwoClasses */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -563,9 +563,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP8UnionTypesAllBaseTypes */', - [ + 'php8-union-types-all-base-types' => [ + 'identifier' => '/* testPHP8UnionTypesAllBaseTypes */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => false, @@ -574,9 +574,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP8UnionTypesAllPseudoTypes */', - [ + 'php8-union-types-all-pseudo-types' => [ + 'identifier' => '/* testPHP8UnionTypesAllPseudoTypes */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => false, @@ -585,9 +585,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP8UnionTypesIllegalTypes */', - [ + 'php8-union-types-illegal-types' => [ + 'identifier' => '/* testPHP8UnionTypesIllegalTypes */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -596,9 +596,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP8UnionTypesNullable */', - [ + 'php8-union-types-nullable' => [ + 'identifier' => '/* testPHP8UnionTypesNullable */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -607,9 +607,9 @@ public function dataGetMemberProperties() 'nullable_type' => true, ], ], - [ - '/* testPHP8PseudoTypeNull */', - [ + 'php8-union-types-pseudo-type-null' => [ + 'identifier' => '/* testPHP8PseudoTypeNull */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -618,9 +618,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP8PseudoTypeFalse */', - [ + 'php8-union-types-pseudo-type-false' => [ + 'identifier' => '/* testPHP8PseudoTypeFalse */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -629,9 +629,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP8PseudoTypeFalseAndBool */', - [ + 'php8-union-types-pseudo-type-false-and-bool' => [ + 'identifier' => '/* testPHP8PseudoTypeFalseAndBool */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -640,9 +640,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP8ObjectAndClass */', - [ + 'php8-union-types-object-and-class' => [ + 'identifier' => '/* testPHP8ObjectAndClass */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -651,9 +651,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP8PseudoTypeIterableAndArray */', - [ + 'php8-union-types-pseudo-type-iterable-and-array' => [ + 'identifier' => '/* testPHP8PseudoTypeIterableAndArray */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -662,9 +662,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP8DuplicateTypeInUnionWhitespaceAndComment */', - [ + 'php8-union-types-duplicate-type-with-whitespace-and-comments' => [ + 'identifier' => '/* testPHP8DuplicateTypeInUnionWhitespaceAndComment */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -673,9 +673,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP81Readonly */', - [ + 'php8.1-readonly-property' => [ + 'identifier' => '/* testPHP81Readonly */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -684,9 +684,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP81ReadonlyWithNullableType */', - [ + 'php8.1-readonly-property-with-nullable-type' => [ + 'identifier' => '/* testPHP81ReadonlyWithNullableType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -695,9 +695,9 @@ public function dataGetMemberProperties() 'nullable_type' => true, ], ], - [ - '/* testPHP81ReadonlyWithUnionType */', - [ + 'php8.1-readonly-property-with-union-type' => [ + 'identifier' => '/* testPHP81ReadonlyWithUnionType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -706,9 +706,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP81ReadonlyWithUnionTypeWithNull */', - [ + 'php8.1-readonly-property-with-union-type-with-null' => [ + 'identifier' => '/* testPHP81ReadonlyWithUnionTypeWithNull */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => false, @@ -717,9 +717,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP81OnlyReadonlyWithUnionType */', - [ + 'php8.1-readonly-property-with-union-type-no-visibility' => [ + 'identifier' => '/* testPHP81OnlyReadonlyWithUnionType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => false, @@ -728,9 +728,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP8PropertySingleAttribute */', - [ + 'php8-property-with-single-attribute' => [ + 'identifier' => '/* testPHP8PropertySingleAttribute */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -739,9 +739,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP8PropertyMultipleAttributes */', - [ + 'php8-property-with-multiple-attributes' => [ + 'identifier' => '/* testPHP8PropertyMultipleAttributes */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => false, @@ -750,9 +750,9 @@ public function dataGetMemberProperties() 'nullable_type' => true, ], ], - [ - '/* testPHP8PropertyMultilineAttribute */', - [ + 'php8-property-with-multiline-attribute' => [ + 'identifier' => '/* testPHP8PropertyMultilineAttribute */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -761,13 +761,13 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testEnumProperty */', - [], + 'invalid-property-in-enum' => [ + 'identifier' => '/* testEnumProperty */', + 'expected' => [], ], - [ - '/* testPHP81IntersectionTypes */', - [ + 'php8.1-single-intersection-type' => [ + 'identifier' => '/* testPHP81IntersectionTypes */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -776,9 +776,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP81MoreIntersectionTypes */', - [ + 'php8.1-multi-intersection-type' => [ + 'identifier' => '/* testPHP81MoreIntersectionTypes */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -787,9 +787,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP81IllegalIntersectionTypes */', - [ + 'php8.1-illegal-intersection-type' => [ + 'identifier' => '/* testPHP81IllegalIntersectionTypes */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -798,9 +798,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP81NullableIntersectionType */', - [ + 'php8.1-nullable-intersection-type' => [ + 'identifier' => '/* testPHP81NullableIntersectionType */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -809,9 +809,9 @@ public function dataGetMemberProperties() 'nullable_type' => true, ], ], - [ - '/* testPHP82PseudoTypeTrue */', - [ + 'php8.2-pseudo-type-true' => [ + 'identifier' => '/* testPHP82PseudoTypeTrue */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => true, 'is_static' => false, @@ -820,9 +820,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP82NullablePseudoTypeTrue */', - [ + 'php8.2-pseudo-type-true-nullable' => [ + 'identifier' => '/* testPHP82NullablePseudoTypeTrue */', + 'expected' => [ 'scope' => 'protected', 'scope_specified' => true, 'is_static' => true, @@ -831,9 +831,9 @@ public function dataGetMemberProperties() 'nullable_type' => true, ], ], - [ - '/* testPHP82PseudoTypeTrueInUnion */', - [ + 'php8.2-pseudo-type-true-in-union' => [ + 'identifier' => '/* testPHP82PseudoTypeTrueInUnion */', + 'expected' => [ 'scope' => 'private', 'scope_specified' => true, 'is_static' => false, @@ -842,9 +842,9 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], - [ - '/* testPHP82PseudoTypeFalseAndTrue */', - [ + 'php8.2-pseudo-type-invalid-true-false-union' => [ + 'identifier' => '/* testPHP82PseudoTypeFalseAndTrue */', + 'expected' => [ 'scope' => 'public', 'scope_specified' => false, 'is_static' => false, @@ -883,18 +883,18 @@ public function testNotClassPropertyException($identifier) * * @see testNotClassPropertyException() * - * @return array + * @return array> */ public function dataNotClassProperty() { return [ - ['/* testMethodParam */'], - ['/* testImportedGlobal */'], - ['/* testLocalVariable */'], - ['/* testGlobalVariable */'], - ['/* testNestedMethodParam 1 */'], - ['/* testNestedMethodParam 2 */'], - ['/* testEnumMethodParamNotProperty */'], + 'method parameter' => ['/* testMethodParam */'], + 'variable import using global keyword' => ['/* testImportedGlobal */'], + 'function local variable' => ['/* testLocalVariable */'], + 'global variable' => ['/* testGlobalVariable */'], + 'method parameter in anon class nested in ternary' => ['/* testNestedMethodParam 1 */'], + 'method parameter in anon class nested in function call' => ['/* testNestedMethodParam 2 */'], + 'method parameter in enum' => ['/* testEnumMethodParamNotProperty */'], ]; }//end dataNotClassProperty() From 7907530c71b1d7fcd81a01287d30eba0c8482a05 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 1 Jan 2024 08:55:41 +0100 Subject: [PATCH 3/4] Tests/GetMemberPropertiesTest: more thoroughly test existing tests This adds testing of the `type_token` and `type_end_token` return value indexes to the pre-existing tests, same as was already being tested in PHPCSUtils. --- tests/Core/File/GetMemberPropertiesTest.php | 159 +++++++++++++++++++- 1 file changed, 157 insertions(+), 2 deletions(-) diff --git a/tests/Core/File/GetMemberPropertiesTest.php b/tests/Core/File/GetMemberPropertiesTest.php index e069c20a59..333dc98ae7 100644 --- a/tests/Core/File/GetMemberPropertiesTest.php +++ b/tests/Core/File/GetMemberPropertiesTest.php @@ -35,8 +35,14 @@ public function testGetMemberProperties($identifier, $expected) $variable = $this->getTargetToken($identifier, T_VARIABLE); $result = self::$phpcsFile->getMemberProperties($variable); - // Unset those indexes which are not being tested. - unset($result['type_token'], $result['type_end_token']); + // Convert offsets to absolute positions in the token stream. + if (isset($expected['type_token']) === true && is_int($expected['type_token']) === true) { + $expected['type_token'] += $variable; + } + + if (isset($expected['type_end_token']) === true && is_int($expected['type_end_token']) === true) { + $expected['type_end_token'] += $variable; + } $this->assertSame($expected, $result); @@ -46,6 +52,10 @@ public function testGetMemberProperties($identifier, $expected) /** * Data provider for the GetMemberProperties test. * + * Note: the `expected - type_token` and `expected - type_end_token` indexes should + * contain either `false` (no type) or the _offset_ of the type start/end token in + * relation to the `T_VARIABLE` token which is passed to the getMemberProperties() method. + * * @see testGetMemberProperties() * * @return array>> @@ -61,6 +71,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -72,6 +84,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '?int', + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => true, ], ], @@ -83,6 +97,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -94,6 +110,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'string', + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -105,6 +123,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -116,6 +136,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'bool', + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -127,6 +149,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -138,6 +162,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'array', + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -149,6 +175,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -160,6 +188,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => '?string', + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => true, ], ], @@ -171,6 +201,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -182,6 +214,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -193,6 +227,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -204,6 +240,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -215,6 +253,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -226,6 +266,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -237,6 +279,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -248,6 +292,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -259,6 +305,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -270,6 +318,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'float', + 'type_token' => -6, + 'type_end_token' => -6, 'nullable_type' => false, ], ], @@ -281,6 +331,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'float', + 'type_token' => -13, + 'type_end_token' => -13, 'nullable_type' => false, ], ], @@ -292,6 +344,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => '?string', + 'type_token' => -6, + 'type_end_token' => -6, 'nullable_type' => true, ], ], @@ -303,6 +357,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => '?string', + 'type_token' => -17, + 'type_end_token' => -17, 'nullable_type' => true, ], ], @@ -314,6 +370,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -325,6 +383,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -336,6 +396,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -347,6 +409,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -358,6 +422,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -369,6 +435,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -380,6 +448,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -391,6 +461,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -402,6 +474,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -413,6 +487,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -424,6 +500,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '?array', + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => true, ], ], @@ -435,6 +513,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '\MyNamespace\MyClass', + 'type_token' => -5, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -446,6 +526,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '?ClassName', + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => true, ], ], @@ -457,6 +539,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '?Folder\ClassName', + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => true, ], ], @@ -468,6 +552,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '\MyNamespace\MyClass\Foo', + 'type_token' => -18, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -479,6 +565,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -494,6 +582,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -505,6 +595,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '', + 'type_token' => false, + 'type_end_token' => false, 'nullable_type' => false, ], ], @@ -516,6 +608,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => 'miXed', + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -527,6 +621,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '?mixed', + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => true, ], ], @@ -538,6 +634,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '?namespace\Name', + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => true, ], ], @@ -549,6 +647,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'int|float', + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -560,6 +660,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'MyClassA|\Package\MyClassB', + 'type_token' => -7, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -571,6 +673,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'array|bool|int|float|NULL|object|string', + 'type_token' => -14, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -582,6 +686,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'false|mixed|self|parent|iterable|Resource', + 'type_token' => -12, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -592,7 +698,10 @@ public function dataGetMemberProperties() 'scope_specified' => true, 'is_static' => false, 'is_readonly' => false, + // Missing static, but that's OK as not an allowed syntax. 'type' => 'callable|void', + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -604,6 +713,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '?int|float', + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => true, ], ], @@ -615,6 +726,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'null', + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -626,6 +739,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'false', + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -637,6 +752,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'bool|FALSE', + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -648,6 +765,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'object|ClassName', + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -659,6 +778,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'iterable|array|Traversable', + 'type_token' => -6, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -670,6 +791,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'int|string|INT', + 'type_token' => -10, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -681,6 +804,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => true, 'type' => 'int', + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -692,6 +817,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => true, 'type' => '?array', + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => true, ], ], @@ -703,6 +830,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => true, 'type' => 'string|int', + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -714,6 +843,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => true, 'type' => 'string|null', + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -725,6 +856,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => true, 'type' => 'string|int', + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -736,6 +869,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'string', + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -747,6 +882,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '?int|float', + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => true, ], ], @@ -758,6 +895,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'mixed', + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -773,6 +912,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'Foo&Bar', + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -784,6 +925,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'Foo&Bar&Baz', + 'type_token' => -6, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -795,6 +938,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'int&string', + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -806,6 +951,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => '?Foo&Bar', + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => true, ], ], @@ -817,6 +964,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'true', + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -828,6 +977,8 @@ public function dataGetMemberProperties() 'is_static' => true, 'is_readonly' => false, 'type' => '?true', + 'type_token' => -2, + 'type_end_token' => -2, 'nullable_type' => true, ], ], @@ -839,6 +990,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => false, 'type' => 'int|string|true', + 'type_token' => -6, + 'type_end_token' => -2, 'nullable_type' => false, ], ], @@ -850,6 +1003,8 @@ public function dataGetMemberProperties() 'is_static' => false, 'is_readonly' => true, 'type' => 'true|FALSE', + 'type_token' => -4, + 'type_end_token' => -2, 'nullable_type' => false, ], ], From fcc764b300b229d405af7a2c7d168cc2ef2bd8ff Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 1 Jan 2024 09:05:49 +0100 Subject: [PATCH 4/4] Tests/GetMemberPropertiesTest: add extra tests This adds some extra tests which were already in use in PHPCSUtils. --- tests/Core/File/GetMemberPropertiesTest.inc | 23 ++++++- tests/Core/File/GetMemberPropertiesTest.php | 66 +++++++++++++++++++++ 2 files changed, 88 insertions(+), 1 deletion(-) diff --git a/tests/Core/File/GetMemberPropertiesTest.inc b/tests/Core/File/GetMemberPropertiesTest.inc index 61ab56564c..f69a685ecf 100644 --- a/tests/Core/File/GetMemberPropertiesTest.inc +++ b/tests/Core/File/GetMemberPropertiesTest.inc @@ -39,7 +39,10 @@ class TestMemberProperties var static $varG = true; /* testPublicStatic */ - public static $varH = true; + public // comment + // phpcs:ignore Stnd.Cat.Sniff -- For reasons. + static + $varH = true; /* testProtectedStatic */ static protected $varI = true; @@ -255,6 +258,16 @@ $anon = class() { /* testPHP81OnlyReadonlyWithUnionType */ readonly string|int $onlyReadonly; + + /* testPHP81OnlyReadonlyWithUnionTypeMultiple */ + readonly \InterfaceA|\Sub\InterfaceB|false + $onlyReadonly; + + /* testPHP81ReadonlyAndStatic */ + readonly private static ?string $readonlyAndStatic; + + /* testPHP81ReadonlyMixedCase */ + public ReadONLY static $readonlyMixedCase; }; $anon = class { @@ -318,3 +331,11 @@ $anon = class() { // Intentional fatal error - Type contains both true and false, bool should be used instead, but that's not the concern of the method. readonly true|FALSE $pseudoTypeFalseAndTrue; }; + +class WhitespaceAndCommentsInTypes { + /* testUnionTypeWithWhitespaceAndComment */ + public int | /*comment*/ string $hasWhitespaceAndComment; + + /* testIntersectionTypeWithWhitespaceAndComment */ + public \Foo /*comment*/ & Bar $hasWhitespaceAndComment; +} diff --git a/tests/Core/File/GetMemberPropertiesTest.php b/tests/Core/File/GetMemberPropertiesTest.php index 333dc98ae7..24a170ae92 100644 --- a/tests/Core/File/GetMemberPropertiesTest.php +++ b/tests/Core/File/GetMemberPropertiesTest.php @@ -861,6 +861,45 @@ public function dataGetMemberProperties() 'nullable_type' => false, ], ], + 'php8.1-readonly-property-with-multi-union-type-no-visibility' => [ + 'identifier' => '/* testPHP81OnlyReadonlyWithUnionTypeMultiple */', + 'expected' => [ + 'scope' => 'public', + 'scope_specified' => false, + 'is_static' => false, + 'is_readonly' => true, + 'type' => '\InterfaceA|\Sub\InterfaceB|false', + 'type_token' => -11, + 'type_end_token' => -3, + 'nullable_type' => false, + ], + ], + 'php8.1-readonly-and-static-property' => [ + 'identifier' => '/* testPHP81ReadonlyAndStatic */', + 'expected' => [ + 'scope' => 'private', + 'scope_specified' => true, + 'is_static' => true, + 'is_readonly' => true, + 'type' => '?string', + 'type_token' => -2, + 'type_end_token' => -2, + 'nullable_type' => true, + ], + ], + 'php8.1-readonly-mixed-case-keyword' => [ + 'identifier' => '/* testPHP81ReadonlyMixedCase */', + 'expected' => [ + 'scope' => 'public', + 'scope_specified' => true, + 'is_static' => true, + 'is_readonly' => true, + 'type' => '', + 'type_token' => false, + 'type_end_token' => false, + 'nullable_type' => false, + ], + ], 'php8-property-with-single-attribute' => [ 'identifier' => '/* testPHP8PropertySingleAttribute */', 'expected' => [ @@ -956,6 +995,33 @@ public function dataGetMemberProperties() 'nullable_type' => true, ], ], + + 'php8.0-union-type-with-whitespace-and-comment' => [ + 'identifier' => '/* testUnionTypeWithWhitespaceAndComment */', + 'expected' => [ + 'scope' => 'public', + 'scope_specified' => true, + 'is_static' => false, + 'is_readonly' => false, + 'type' => 'int|string', + 'type_token' => -8, + 'type_end_token' => -2, + 'nullable_type' => false, + ], + ], + 'php8.1-intersection-type-with-whitespace-and-comment' => [ + 'identifier' => '/* testIntersectionTypeWithWhitespaceAndComment */', + 'expected' => [ + 'scope' => 'public', + 'scope_specified' => true, + 'is_static' => false, + 'is_readonly' => false, + 'type' => '\Foo&Bar', + 'type_token' => -9, + 'type_end_token' => -2, + 'nullable_type' => false, + ], + ], 'php8.2-pseudo-type-true' => [ 'identifier' => '/* testPHP82PseudoTypeTrue */', 'expected' => [