|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Bug13735; |
| 4 | + |
| 5 | +use function PHPStan\Testing\assertType; |
| 6 | +use function rand; |
| 7 | + |
| 8 | +class Bug13735Test |
| 9 | +{ |
| 10 | + private ?Foo $foo = null; |
| 11 | + public static ?Foo $staticFoo = null; |
| 12 | + |
| 13 | + public function testFoo(): void |
| 14 | + { |
| 15 | + $this->foo = new Foo(); |
| 16 | + assertType('Bug13735\Foo', $this->foo); |
| 17 | + self::assertTrue(true); |
| 18 | + assertType('Bug13735\Foo', $this->foo); |
| 19 | + |
| 20 | + assertType('bool', $this->foo->aBool); |
| 21 | + $this->foo->aBool = true; |
| 22 | + assertType('true', $this->foo->aBool); |
| 23 | + self::assertTrue(true); |
| 24 | + assertType('true', $this->foo->aBool); |
| 25 | + } |
| 26 | + |
| 27 | + public function testCallFoo(): void |
| 28 | + { |
| 29 | + if ($this->getFoo() === null) { |
| 30 | + return; |
| 31 | + } |
| 32 | + |
| 33 | + // the getFoo() method could reference a static property in its body, |
| 34 | + // so self::assertTrue() still needs to invalidate $this->getFoo(). |
| 35 | + assertType('Bug13735\Foo', $this->getFoo()); |
| 36 | + self::assertTrue(true); |
| 37 | + assertType('Bug13735\Foo|null', $this->getFoo()); |
| 38 | + } |
| 39 | + |
| 40 | + public function testStaticFoo(): void |
| 41 | + { |
| 42 | + self::$staticFoo = new Foo(); |
| 43 | + assertType('Bug13735\Foo', self::$staticFoo); |
| 44 | + self::assertTrue(true); |
| 45 | + assertType('Bug13735\Foo|null', self::$staticFoo); |
| 46 | + } |
| 47 | + |
| 48 | + public static function assertTrue(mixed $condition, string $message = ''): void |
| 49 | + { |
| 50 | + } |
| 51 | + |
| 52 | + public function getFoo(): ?Foo { |
| 53 | + return rand(0 ,1) ? null : new Foo(); |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +class Foo { |
| 58 | + public bool $aBool = false; |
| 59 | +} |
0 commit comments