@@ -15,9 +15,13 @@ class InvalidKeyInArrayDimFetchRuleTest extends RuleTestCase
15
15
16
16
private bool $ reportCastedArrayKey = false ;
17
17
18
+ private bool $ checkUnionType = true ;
19
+
20
+ private bool $ checkNullable = true ;
21
+
18
22
protected function getRule (): Rule
19
23
{
20
- $ ruleLevelHelper = new RuleLevelHelper (self ::createReflectionProvider (), true , false , true , false , false , false , true );
24
+ $ ruleLevelHelper = new RuleLevelHelper (self ::createReflectionProvider (), $ this -> checkNullable , false , $ this -> checkUnionType , false , false , false , true );
21
25
return new InvalidKeyInArrayDimFetchRule ($ ruleLevelHelper , true , $ this ->reportCastedArrayKey );
22
26
}
23
27
@@ -63,6 +67,46 @@ public function testInvalidKey(): void
63
67
]);
64
68
}
65
69
70
+ public function testInvalidKeyOnLevel6 (): void
71
+ {
72
+ $ this ->checkNullable = false ;
73
+ $ this ->checkUnionType = false ;
74
+ $ this ->analyse ([__DIR__ . '/data/invalid-key-array-dim-fetch.php ' ], [
75
+ [
76
+ 'Invalid array key type DateTimeImmutable. ' ,
77
+ 7 ,
78
+ ],
79
+ [
80
+ 'Invalid array key type array. ' ,
81
+ 8 ,
82
+ ],
83
+ [
84
+ 'Invalid array key type DateTimeImmutable. ' ,
85
+ 31 ,
86
+ ],
87
+ [
88
+ 'Invalid array key type DateTimeImmutable. ' ,
89
+ 45 ,
90
+ ],
91
+ [
92
+ 'Invalid array key type DateTimeImmutable. ' ,
93
+ 46 ,
94
+ ],
95
+ [
96
+ 'Invalid array key type DateTimeImmutable. ' ,
97
+ 47 ,
98
+ ],
99
+ [
100
+ 'Invalid array key type stdClass. ' ,
101
+ 47 ,
102
+ ],
103
+ [
104
+ 'Invalid array key type DateTimeImmutable. ' ,
105
+ 48 ,
106
+ ],
107
+ ]);
108
+ }
109
+
66
110
public function testInvalidKeyReportingCastedArrayKey (): void
67
111
{
68
112
$ this ->reportCastedArrayKey = true ;
@@ -126,6 +170,63 @@ public function testInvalidKeyReportingCastedArrayKey(): void
126
170
]);
127
171
}
128
172
173
+ public function testInvalidKeyReportingCastedArrayKeyOnLevel6 (): void
174
+ {
175
+ $ this ->checkNullable = false ;
176
+ $ this ->checkUnionType = false ;
177
+ $ this ->reportCastedArrayKey = true ;
178
+ $ this ->analyse ([__DIR__ . '/data/invalid-key-array-dim-fetch.php ' ], [
179
+ [
180
+ 'Invalid array key type null. ' ,
181
+ 6 ,
182
+ ],
183
+ [
184
+ 'Invalid array key type DateTimeImmutable. ' ,
185
+ 7 ,
186
+ ],
187
+ [
188
+ 'Invalid array key type array. ' ,
189
+ 8 ,
190
+ ],
191
+ [
192
+ 'Invalid array key type float. ' ,
193
+ 10 ,
194
+ ],
195
+ [
196
+ 'Invalid array key type true. ' ,
197
+ 12 ,
198
+ ],
199
+ [
200
+ 'Invalid array key type false. ' ,
201
+ 13 ,
202
+ ],
203
+ [
204
+ 'Invalid array key type DateTimeImmutable. ' ,
205
+ 31 ,
206
+ ],
207
+ [
208
+ 'Invalid array key type DateTimeImmutable. ' ,
209
+ 45 ,
210
+ ],
211
+ [
212
+ 'Invalid array key type DateTimeImmutable. ' ,
213
+ 46 ,
214
+ ],
215
+ [
216
+ 'Invalid array key type DateTimeImmutable. ' ,
217
+ 47 ,
218
+ ],
219
+ [
220
+ 'Invalid array key type stdClass. ' ,
221
+ 47 ,
222
+ ],
223
+ [
224
+ 'Invalid array key type DateTimeImmutable. ' ,
225
+ 48 ,
226
+ ],
227
+ ]);
228
+ }
229
+
129
230
#[RequiresPhp('>= 8.1 ' )]
130
231
public function testBug6315 (): void
131
232
{
0 commit comments