File tree Expand file tree Collapse file tree 2 files changed +64
-0
lines changed
tests/PHPStan/Rules/Methods Expand file tree Collapse file tree 2 files changed +64
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types = 1 );
2
+
3
+ namespace PHPStan \Rules \Methods ;
4
+
5
+ use PHPStan \Testing \TypeInferenceTestCase ;
6
+
7
+ class AssertIfTrueOnThisTest extends TypeInferenceTestCase
8
+ {
9
+
10
+ public static function dataFileAsserts (): iterable
11
+ {
12
+ yield from self ::gatherAssertTypes (__DIR__ . '/data/bug-13358.php ' );
13
+ }
14
+
15
+ /**
16
+ * @dataProvider dataFileAsserts
17
+ * @param mixed ...$args
18
+ */
19
+ public function testFileAsserts (string $ assertType , string $ file , ...$ args ): void
20
+ {
21
+ $ this ->assertFileAsserts ($ assertType , $ file , ...$ args );
22
+ }
23
+
24
+ }
Original file line number Diff line number Diff line change
1
+ <?php declare (strict_types=1 );
2
+
3
+ namespace Bug13358 ;
4
+
5
+ use function PHPStan \Testing \assertType ;
6
+
7
+ /**
8
+ * @phpstan-sealed SystemActor|AnonymousVisitorActor
9
+ */
10
+ abstract class Actor
11
+ {
12
+ /**
13
+ * @phpstan-assert-if-true SystemActor $this
14
+ */
15
+ public function isSystem (): bool
16
+ {
17
+ return $ this instanceof SystemActor;
18
+ }
19
+
20
+ /**
21
+ * @phpstan-assert-if-true AnonymousVisitorActor $this
22
+ */
23
+ public function isAnonymousVisitor (): bool
24
+ {
25
+ return $ this instanceof AnonymousVisitorActor;
26
+ }
27
+ }
28
+
29
+ class SystemActor extends Actor {}
30
+ class AnonymousVisitorActor extends Actor {}
31
+
32
+ function test (AnonymousVisitorActor |SystemActor $ actor ): void {
33
+ assertType ('Bug13358\AnonymousVisitorActor|Bug13358\SystemActor ' , $ actor );
34
+
35
+ if ($ actor ->isSystem ()) {
36
+ assertType ('Bug13358\SystemActor ' , $ actor );
37
+ } else {
38
+ assertType ('Bug13358\AnonymousVisitorActor ' , $ actor );
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments