1616class NullCoalesceRuleTest extends RuleTestCase
1717{
1818
19- private bool $ treatPhpDocTypesAsCertain ;
20-
2119 protected function getRule (): Rule
2220 {
2321 return new NullCoalesceRule (new IssetCheck (
2422 new PropertyDescriptor (),
2523 new PropertyReflectionFinder (),
2624 true ,
27- $ this ->treatPhpDocTypesAsCertain ,
25+ $ this ->shouldTreatPhpDocTypesAsCertain () ,
2826 ));
2927 }
3028
31- protected function shouldTreatPhpDocTypesAsCertain (): bool
32- {
33- return $ this ->treatPhpDocTypesAsCertain ;
34- }
35-
3629 public function shouldNarrowMethodScopeFromConstructor (): bool
3730 {
3831 return true ;
3932 }
4033
4134 public function testCoalesceRule (): void
4235 {
43- $ this ->treatPhpDocTypesAsCertain = true ;
4436 $ errors = [
4537 [
4638 'Property CoalesceRule\FooCoalesce::$string (string) on left side of ?? is not nullable. ' ,
@@ -146,7 +138,6 @@ public function testCoalesceRule(): void
146138
147139 public function testCoalesceAssignRule (): void
148140 {
149- $ this ->treatPhpDocTypesAsCertain = true ;
150141 $ this ->analyse ([__DIR__ . '/data/null-coalesce-assign.php ' ], [
151142 [
152143 'Property CoalesceAssignRule\FooCoalesce::$string (string) on left side of ??= is not nullable. ' ,
@@ -209,13 +200,11 @@ public function testCoalesceAssignRule(): void
209200
210201 public function testNullsafe (): void
211202 {
212- $ this ->treatPhpDocTypesAsCertain = true ;
213203 $ this ->analyse ([__DIR__ . '/data/null-coalesce-nullsafe.php ' ], []);
214204 }
215205
216206 public function testVariableCertaintyInNullCoalesce (): void
217207 {
218- $ this ->treatPhpDocTypesAsCertain = true ;
219208 $ this ->analyse ([__DIR__ . '/data/variable-certainty-null.php ' ], [
220209 [
221210 'Variable $scalar on left side of ?? always exists and is not nullable. ' ,
@@ -234,7 +223,6 @@ public function testVariableCertaintyInNullCoalesce(): void
234223
235224 public function testVariableCertaintyInNullCoalesceAssign (): void
236225 {
237- $ this ->treatPhpDocTypesAsCertain = true ;
238226 $ this ->analyse ([__DIR__ . '/data/variable-certainty-null-assign.php ' ], [
239227 [
240228 'Variable $scalar on left side of ??= always exists and is not nullable. ' ,
@@ -253,7 +241,6 @@ public function testVariableCertaintyInNullCoalesceAssign(): void
253241
254242 public function testNullCoalesceInGlobalScope (): void
255243 {
256- $ this ->treatPhpDocTypesAsCertain = true ;
257244 $ this ->analyse ([__DIR__ . '/data/null-coalesce-global-scope.php ' ], [
258245 [
259246 'Variable $bar on left side of ?? always exists and is not nullable. ' ,
@@ -264,15 +251,12 @@ public function testNullCoalesceInGlobalScope(): void
264251
265252 public function testBug5933 (): void
266253 {
267- $ this ->treatPhpDocTypesAsCertain = true ;
268254 $ this ->analyse ([__DIR__ . '/data/bug-5933.php ' ], []);
269255 }
270256
271257 #[RequiresPhp('>= 8.0 ' )]
272258 public function testBug7109 (): void
273259 {
274- $ this ->treatPhpDocTypesAsCertain = true ;
275-
276260 $ this ->analyse ([__DIR__ . '/../Properties/data/bug-7109.php ' ], [
277261 [
278262 'Using nullsafe property access "?->aaa" on left side of ?? is unnecessary. Use -> instead. ' ,
@@ -299,8 +283,6 @@ public function testBug7109(): void
299283
300284 public function testBug7190 (): void
301285 {
302- $ this ->treatPhpDocTypesAsCertain = true ;
303-
304286 $ this ->analyse ([__DIR__ . '/../Properties/data/bug-7190.php ' ], [
305287 [
306288 'Offset int on array<int, int> on left side of ?? always exists and is not nullable. ' ,
@@ -311,8 +293,6 @@ public function testBug7190(): void
311293
312294 public function testBug7318 (): void
313295 {
314- $ this ->treatPhpDocTypesAsCertain = true ;
315-
316296 $ this ->analyse ([__DIR__ . '/../Properties/data/bug-7318.php ' ], [
317297 [
318298 "Offset 'unique' on array{unique: bool} on left side of ?? always exists and is not nullable. " ,
@@ -323,50 +303,37 @@ public function testBug7318(): void
323303
324304 public function testBug7968 (): void
325305 {
326- $ this ->treatPhpDocTypesAsCertain = true ;
327-
328306 $ this ->analyse ([__DIR__ . '/data/bug-7968.php ' ], []);
329307 }
330308
331309 public function testBug8084 (): void
332310 {
333- $ this ->treatPhpDocTypesAsCertain = true ;
334-
335311 $ this ->analyse ([__DIR__ . '/data/bug-8084.php ' ], []);
336312 }
337313
338314 public function testBug10577 (): void
339315 {
340- $ this ->treatPhpDocTypesAsCertain = true ;
341-
342316 $ this ->analyse ([__DIR__ . '/data/bug-10577.php ' ], []);
343317 }
344318
345319 public function testBug11708 (): void
346320 {
347- $ this ->treatPhpDocTypesAsCertain = true ;
348-
349321 $ this ->analyse ([__DIR__ . '/data/bug-11708.php ' ], []);
350322 }
351323
352324 public function testBug10610 (): void
353325 {
354- $ this ->treatPhpDocTypesAsCertain = true ;
355-
356326 $ this ->analyse ([__DIR__ . '/data/bug-10610.php ' ], []);
357327 }
358328
359329 #[RequiresPhp('>= 8.4 ' )]
360330 public function testBug12553 (): void
361331 {
362- $ this ->treatPhpDocTypesAsCertain = true ;
363332 $ this ->analyse ([__DIR__ . '/data/bug-12553.php ' ], []);
364333 }
365334
366335 public function testIssetAfterRememberedConstructor (): void
367336 {
368- $ this ->treatPhpDocTypesAsCertain = true ;
369-
370337 $ this ->analyse ([__DIR__ . '/data/isset-after-remembered-constructor.php ' ], [
371338 [
372339 'Property IssetOrCoalesceOnNonNullableInitializedProperty\User::$string on left side of ?? is not nullable nor uninitialized. ' ,
0 commit comments