22
33namespace PHPStan \Rules \Properties ;
44
5+ use PHPStan \Php \PhpVersion ;
56use PHPStan \Rules \Rule ;
67use PHPStan \Testing \RuleTestCase ;
8+ use const PHP_VERSION_ID ;
79
810/**
911 * @extends RuleTestCase<PropertiesInInterfaceRule>
@@ -13,21 +15,107 @@ class PropertiesInInterfaceRuleTest extends RuleTestCase
1315
1416 protected function getRule (): Rule
1517 {
16- return new PropertiesInInterfaceRule ();
18+ return new PropertiesInInterfaceRule (new PhpVersion ( PHP_VERSION_ID ) );
1719 }
1820
19- public function testRule (): void
21+ public function testPhp83AndPropertiesInInterface (): void
2022 {
23+ if (PHP_VERSION_ID >= 80400 ) {
24+ $ this ->markTestSkipped ('Test requires PHP 8.3 or earlier. ' );
25+ }
26+ if (PHP_VERSION_ID < 80000 ) {
27+ $ this ->markTestSkipped ('Property hooks cause syntax error on PHP 7.4 ' );
28+ }
29+
30+ $ this ->analyse ([__DIR__ . '/data/properties-in-interface.php ' ], [
31+ [
32+ 'Interfaces cannot include properties. ' ,
33+ 7 ,
34+ ],
35+ [
36+ 'Interfaces cannot include properties. ' ,
37+ 9 ,
38+ ],
39+ [
40+ 'Interfaces cannot include properties. ' ,
41+ 11 ,
42+ ],
43+ ]);
44+ }
45+
46+ public function testPhp83AndPropertyHooksInInterface (): void
47+ {
48+ if (PHP_VERSION_ID >= 80400 ) {
49+ $ this ->markTestSkipped ('Test requires PHP 8.3 or earlier. ' );
50+ }
51+ if (PHP_VERSION_ID < 80000 ) {
52+ $ this ->markTestSkipped ('Property hooks cause syntax error on PHP 7.4 ' );
53+ }
54+
55+ $ this ->analyse ([__DIR__ . '/data/property-hooks-in-interface.php ' ], [
56+ [
57+ 'Interfaces cannot include properties. ' ,
58+ 7 ,
59+ ],
60+ [
61+ 'Interfaces cannot include properties. ' ,
62+ 9 ,
63+ ],
64+ ]);
65+ }
66+
67+ public function testPhp84AndPropertiesInInterface (): void
68+ {
69+ if (PHP_VERSION_ID < 80400 ) {
70+ $ this ->markTestSkipped ('Test requires PHP 8.4 or later. ' );
71+ }
72+
2173 $ this ->analyse ([__DIR__ . '/data/properties-in-interface.php ' ], [
2274 [
23- 'Interfaces may not include properties. ' ,
75+ 'Interfaces can only include hooked properties. ' ,
76+ 9 ,
77+ ],
78+ [
79+ 'Interfaces can only include hooked properties. ' ,
80+ 11 ,
81+ ],
82+ ]);
83+ }
84+
85+ public function testPhp84AndNonPublicPropertyHooksInInterface (): void
86+ {
87+ if (PHP_VERSION_ID < 80400 ) {
88+ $ this ->markTestSkipped ('Test requires PHP 8.4 or later. ' );
89+ }
90+
91+ $ this ->analyse ([__DIR__ . '/data/property-hooks-visibility-in-interface.php ' ], [
92+ [
93+ 'Interfaces cannot include non-public properties. ' ,
2494 7 ,
2595 ],
2696 [
27- 'Interfaces may not include properties. ' ,
97+ 'Interfaces cannot include non-public properties. ' ,
2898 9 ,
2999 ],
30100 ]);
31101 }
32102
103+ public function testPhp84AndPropertyHooksWithBodiesInInterface (): void
104+ {
105+ if (PHP_VERSION_ID < 80400 ) {
106+ $ this ->markTestSkipped ('Test requires PHP 8.4 or later. ' );
107+ }
108+
109+ $ this ->analyse ([__DIR__ . '/data/property-hooks-bodies-in-interface.php ' ], [
110+ [
111+ 'Interfaces cannot include property hooks with bodies. ' ,
112+ 7 ,
113+ ],
114+ [
115+ 'Interfaces cannot include property hooks with bodies. ' ,
116+ 13 ,
117+ ],
118+ ]);
119+ }
120+
33121}
0 commit comments