2
2
3
3
namespace PHPStan \Rules \Properties ;
4
4
5
+ use PHPStan \Php \PhpVersion ;
5
6
use PHPStan \Rules \Rule ;
6
7
use PHPStan \Testing \RuleTestCase ;
8
+ use const PHP_VERSION_ID ;
7
9
8
10
/**
9
11
* @extends RuleTestCase<PropertiesInInterfaceRule>
@@ -13,21 +15,107 @@ class PropertiesInInterfaceRuleTest extends RuleTestCase
13
15
14
16
protected function getRule (): Rule
15
17
{
16
- return new PropertiesInInterfaceRule ();
18
+ return new PropertiesInInterfaceRule (new PhpVersion ( PHP_VERSION_ID ) );
17
19
}
18
20
19
- public function testRule (): void
21
+ public function testPhp83AndPropertiesInInterface (): void
20
22
{
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
+
21
73
$ this ->analyse ([__DIR__ . '/data/properties-in-interface.php ' ], [
22
74
[
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. ' ,
24
94
7 ,
25
95
],
26
96
[
27
- 'Interfaces may not include properties. ' ,
97
+ 'Interfaces cannot include non-public properties. ' ,
28
98
9 ,
29
99
],
30
100
]);
31
101
}
32
102
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
+
33
121
}
0 commit comments