|
21 | 21 | class AccessStaticPropertiesRuleTest extends RuleTestCase |
22 | 22 | { |
23 | 23 |
|
| 24 | + private bool $checkUnionTypes = true; |
| 25 | + |
24 | 26 | protected function getRule(): Rule |
25 | 27 | { |
26 | 28 | $reflectionProvider = self::createReflectionProvider(); |
27 | 29 | $ruleLevelHelper = new RuleLevelHelper( |
28 | 30 | $reflectionProvider, |
29 | 31 | checkNullables: true, |
30 | 32 | checkThisOnly: false, |
31 | | - checkUnionTypes: true, |
| 33 | + checkUnionTypes: $this->checkUnionTypes, |
32 | 34 | checkExplicitMixed: false, |
33 | 35 | checkImplicitMixed: false, |
34 | 36 | checkBenevolentUnionTypes: false, |
@@ -396,4 +398,95 @@ public function testBug15002(): void |
396 | 398 | $this->analyse([__DIR__ . '/../Methods/data/bug-15002.php'], []); |
397 | 399 | } |
398 | 400 |
|
| 401 | + #[RequiresPhp('>= 8.0.0')] |
| 402 | + public function testStaticPropertyAccessOnStringUnions(): void |
| 403 | + { |
| 404 | + $this->analyse([__DIR__ . '/data/static-property-string-unions.php'], [ |
| 405 | + [ |
| 406 | + 'Access to an undefined static property StaticPropertyStringUnions\Baz::$create.', |
| 407 | + 32, |
| 408 | + ], |
| 409 | + [ |
| 410 | + 'Access to an undefined static property StaticPropertyStringUnions\Baz|StaticPropertyStringUnions\Foo::$create.', |
| 411 | + 38, |
| 412 | + ], |
| 413 | + [ |
| 414 | + 'Access to an undefined static property StaticPropertyStringUnions\Baz|StaticPropertyStringUnions\Foo::$create.', |
| 415 | + 50, |
| 416 | + ], |
| 417 | + [ |
| 418 | + 'Access to an undefined static property StaticPropertyStringUnions\Baz|StaticPropertyStringUnions\Foo::$create.', |
| 419 | + 58, |
| 420 | + ], |
| 421 | + [ |
| 422 | + 'Access to an undefined static property StaticPropertyStringUnions\Baz::$create.', |
| 423 | + 66, |
| 424 | + ], |
| 425 | + [ |
| 426 | + 'Static access to instance property StaticPropertyStringUnions\Foo::$doBar.', |
| 427 | + 80, |
| 428 | + ], |
| 429 | + [ |
| 430 | + 'Access to an undefined static property StaticPropertyStringUnions\Baz::$missing.', |
| 431 | + 118, |
| 432 | + ], |
| 433 | + [ |
| 434 | + 'Access to an undefined static property StaticPropertyStringUnions\Baz::$missing.', |
| 435 | + 119, |
| 436 | + ], |
| 437 | + [ |
| 438 | + 'Access to an undefined static property StaticPropertyStringUnions\Baz::$missing.', |
| 439 | + 120, |
| 440 | + ], |
| 441 | + [ |
| 442 | + 'Access to private property $privateProperty of class StaticPropertyStringUnions\WithNonPublic.', |
| 443 | + 126, |
| 444 | + ], |
| 445 | + [ |
| 446 | + 'Access to protected property $protectedProperty of class StaticPropertyStringUnions\WithNonPublic.', |
| 447 | + 127, |
| 448 | + ], |
| 449 | + ]); |
| 450 | + } |
| 451 | + |
| 452 | + #[RequiresPhp('>= 8.0.0')] |
| 453 | + public function testStaticPropertyAccessOnStringUnionsWithoutCheckUnionTypes(): void |
| 454 | + { |
| 455 | + $this->checkUnionTypes = false; |
| 456 | + $this->analyse([__DIR__ . '/data/static-property-string-unions.php'], [ |
| 457 | + [ |
| 458 | + 'Access to an undefined static property StaticPropertyStringUnions\Baz::$create.', |
| 459 | + 32, |
| 460 | + ], |
| 461 | + [ |
| 462 | + 'Access to an undefined static property StaticPropertyStringUnions\Baz::$create.', |
| 463 | + 66, |
| 464 | + ], |
| 465 | + [ |
| 466 | + 'Static access to instance property StaticPropertyStringUnions\Foo::$doBar.', |
| 467 | + 80, |
| 468 | + ], |
| 469 | + [ |
| 470 | + 'Access to an undefined static property StaticPropertyStringUnions\Baz::$missing.', |
| 471 | + 118, |
| 472 | + ], |
| 473 | + [ |
| 474 | + 'Access to an undefined static property StaticPropertyStringUnions\Baz::$missing.', |
| 475 | + 119, |
| 476 | + ], |
| 477 | + [ |
| 478 | + 'Access to an undefined static property StaticPropertyStringUnions\Baz::$missing.', |
| 479 | + 120, |
| 480 | + ], |
| 481 | + [ |
| 482 | + 'Access to private property $privateProperty of class StaticPropertyStringUnions\WithNonPublic.', |
| 483 | + 126, |
| 484 | + ], |
| 485 | + [ |
| 486 | + 'Access to protected property $protectedProperty of class StaticPropertyStringUnions\WithNonPublic.', |
| 487 | + 127, |
| 488 | + ], |
| 489 | + ]); |
| 490 | + } |
| 491 | + |
399 | 492 | } |
0 commit comments