Skip to content

Commit 7b89fac

Browse files
committed
Regression test
Closes phpstan/phpstan#11033
1 parent 46d9d4e commit 7b89fac

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ private static function findTestFiles(): iterable
112112
yield __DIR__ . '/../Rules/Functions/data/varying-acceptor.php';
113113
yield __DIR__ . '/../Rules/Methods/data/bug-4415.php';
114114
yield __DIR__ . '/../Rules/Methods/data/bug-5372.php';
115+
yield __DIR__ . '/../Rules/PhpDoc/data/bug-11033.php';
115116
yield __DIR__ . '/../Rules/Arrays/data/bug-5372_2.php';
116117
yield __DIR__ . '/../Rules/Methods/data/bug-5562.php';
117118

tests/PHPStan/Rules/PhpDoc/IncompatiblePropertyPhpDocTypeRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,4 +193,9 @@ public function testGenericCallables(): void
193193
]);
194194
}
195195

196+
public function testBug11033(): void
197+
{
198+
$this->analyse([__DIR__ . '/data/bug-11033.php'], []);
199+
}
200+
196201
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Bug11033;
4+
5+
use function PHPStan\Testing\assertType;
6+
7+
/**
8+
* @phpstan-template T of GotoTarget
9+
*
10+
* @phpstan-type CandidateNotesData array{candidate: string, note: string}
11+
* @phpstan-type PersonalmanagerData array{token: string}
12+
*
13+
* @phpstan-type GotoRouteDataTypes array{
14+
* 'personalmanager': PersonalmanagerData,
15+
* 'my-pending-reviews': null,
16+
* 'candidate-notes': CandidateNotesData,
17+
* 'dashboard': null,
18+
* }
19+
*/
20+
final class GotoRoute
21+
{
22+
/**
23+
* @phpstan-var T
24+
*/
25+
public GotoTarget $target;
26+
27+
/**
28+
* @phpstan-var GotoRouteDataTypes[value-of<T>]
29+
*/
30+
public ?array $data = null;
31+
}
32+
33+
enum GotoTarget: string
34+
{
35+
case PERSONALMANAGER = 'personalmanager';
36+
case MY_PENDING_REVIEWS = 'my-pending-reviews';
37+
case CANDIDATE_NOTES = 'candidate-notes';
38+
case DASHBOARD = 'dashboard';
39+
}
40+
41+
function (): void {
42+
/** @var GotoRoute<GotoTarget::PERSONALMANAGER> $goto */
43+
$goto = new GotoRoute();
44+
assertType('array{token: string}', $goto->data);
45+
};
46+
47+
function (): void {
48+
/** @var GotoRoute<GotoTarget::DASHBOARD> $goto */
49+
$goto = new GotoRoute();
50+
assertType('null', $goto->data);
51+
};

0 commit comments

Comments
 (0)