Skip to content

Commit fcc764b

Browse files
committed
Tests/GetMemberPropertiesTest: add extra tests
This adds some extra tests which were already in use in PHPCSUtils.
1 parent 7907530 commit fcc764b

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

tests/Core/File/GetMemberPropertiesTest.inc

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,10 @@ class TestMemberProperties
3939
var static $varG = true;
4040

4141
/* testPublicStatic */
42-
public static $varH = true;
42+
public // comment
43+
// phpcs:ignore Stnd.Cat.Sniff -- For reasons.
44+
static
45+
$varH = true;
4346

4447
/* testProtectedStatic */
4548
static protected $varI = true;
@@ -255,6 +258,16 @@ $anon = class() {
255258

256259
/* testPHP81OnlyReadonlyWithUnionType */
257260
readonly string|int $onlyReadonly;
261+
262+
/* testPHP81OnlyReadonlyWithUnionTypeMultiple */
263+
readonly \InterfaceA|\Sub\InterfaceB|false
264+
$onlyReadonly;
265+
266+
/* testPHP81ReadonlyAndStatic */
267+
readonly private static ?string $readonlyAndStatic;
268+
269+
/* testPHP81ReadonlyMixedCase */
270+
public ReadONLY static $readonlyMixedCase;
258271
};
259272

260273
$anon = class {
@@ -318,3 +331,11 @@ $anon = class() {
318331
// Intentional fatal error - Type contains both true and false, bool should be used instead, but that's not the concern of the method.
319332
readonly true|FALSE $pseudoTypeFalseAndTrue;
320333
};
334+
335+
class WhitespaceAndCommentsInTypes {
336+
/* testUnionTypeWithWhitespaceAndComment */
337+
public int | /*comment*/ string $hasWhitespaceAndComment;
338+
339+
/* testIntersectionTypeWithWhitespaceAndComment */
340+
public \Foo /*comment*/ & Bar $hasWhitespaceAndComment;
341+
}

tests/Core/File/GetMemberPropertiesTest.php

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,45 @@ public function dataGetMemberProperties()
861861
'nullable_type' => false,
862862
],
863863
],
864+
'php8.1-readonly-property-with-multi-union-type-no-visibility' => [
865+
'identifier' => '/* testPHP81OnlyReadonlyWithUnionTypeMultiple */',
866+
'expected' => [
867+
'scope' => 'public',
868+
'scope_specified' => false,
869+
'is_static' => false,
870+
'is_readonly' => true,
871+
'type' => '\InterfaceA|\Sub\InterfaceB|false',
872+
'type_token' => -11,
873+
'type_end_token' => -3,
874+
'nullable_type' => false,
875+
],
876+
],
877+
'php8.1-readonly-and-static-property' => [
878+
'identifier' => '/* testPHP81ReadonlyAndStatic */',
879+
'expected' => [
880+
'scope' => 'private',
881+
'scope_specified' => true,
882+
'is_static' => true,
883+
'is_readonly' => true,
884+
'type' => '?string',
885+
'type_token' => -2,
886+
'type_end_token' => -2,
887+
'nullable_type' => true,
888+
],
889+
],
890+
'php8.1-readonly-mixed-case-keyword' => [
891+
'identifier' => '/* testPHP81ReadonlyMixedCase */',
892+
'expected' => [
893+
'scope' => 'public',
894+
'scope_specified' => true,
895+
'is_static' => true,
896+
'is_readonly' => true,
897+
'type' => '',
898+
'type_token' => false,
899+
'type_end_token' => false,
900+
'nullable_type' => false,
901+
],
902+
],
864903
'php8-property-with-single-attribute' => [
865904
'identifier' => '/* testPHP8PropertySingleAttribute */',
866905
'expected' => [
@@ -956,6 +995,33 @@ public function dataGetMemberProperties()
956995
'nullable_type' => true,
957996
],
958997
],
998+
999+
'php8.0-union-type-with-whitespace-and-comment' => [
1000+
'identifier' => '/* testUnionTypeWithWhitespaceAndComment */',
1001+
'expected' => [
1002+
'scope' => 'public',
1003+
'scope_specified' => true,
1004+
'is_static' => false,
1005+
'is_readonly' => false,
1006+
'type' => 'int|string',
1007+
'type_token' => -8,
1008+
'type_end_token' => -2,
1009+
'nullable_type' => false,
1010+
],
1011+
],
1012+
'php8.1-intersection-type-with-whitespace-and-comment' => [
1013+
'identifier' => '/* testIntersectionTypeWithWhitespaceAndComment */',
1014+
'expected' => [
1015+
'scope' => 'public',
1016+
'scope_specified' => true,
1017+
'is_static' => false,
1018+
'is_readonly' => false,
1019+
'type' => '\Foo&Bar',
1020+
'type_token' => -9,
1021+
'type_end_token' => -2,
1022+
'nullable_type' => false,
1023+
],
1024+
],
9591025
'php8.2-pseudo-type-true' => [
9601026
'identifier' => '/* testPHP82PseudoTypeTrue */',
9611027
'expected' => [

0 commit comments

Comments
 (0)