Skip to content

Commit 98071b0

Browse files
phpstan-botclaude
andcommitted
Add regression tests for phpstan/phpstan#7152 and phpstan/phpstan#13332
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5d34b4b commit 98071b0

5 files changed

Lines changed: 140 additions & 0 deletions

File tree

tests/PHPStan/Rules/Generics/ClassAncestorsRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,4 +290,9 @@ public function testBug7021(): void
290290
$this->analyse([__DIR__ . '/data/bug-7021.php'], []);
291291
}
292292

293+
public function testBug7152(): void
294+
{
295+
$this->analyse([__DIR__ . '/data/bug-7152.php'], []);
296+
}
297+
293298
}

tests/PHPStan/Rules/Generics/ClassTemplateTypeRuleTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,4 +151,20 @@ public function testBug10049(): void
151151
]);
152152
}
153153

154+
public function testBug11314(): void
155+
{
156+
$this->analyse([__DIR__ . '/data/bug-11314.php'], []);
157+
}
158+
159+
#[RequiresPhp('>= 8.1.0')]
160+
public function testBug13332(): void
161+
{
162+
$this->analyse([__DIR__ . '/data/bug-13332.php'], []);
163+
}
164+
165+
public function testBug7152(): void
166+
{
167+
$this->analyse([__DIR__ . '/data/bug-7152.php'], []);
168+
}
169+
154170
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug11314Generics;
4+
5+
/**
6+
* @phpstan-type Breed 'Siamese'|'British Shorthair'|'Maine Coon'
7+
*/
8+
class Cat
9+
{
10+
/**
11+
* @var Breed
12+
*/
13+
public string $breed;
14+
}
15+
16+
/**
17+
* @phpstan-import-type Breed from Cat
18+
*
19+
* @template T of Breed
20+
*/
21+
class Cat2
22+
{
23+
/**
24+
* @var Breed
25+
*/
26+
public string $breed;
27+
}
28+
29+
/**
30+
* @phpstan-import-type Breed from Cat
31+
*/
32+
class Cat3
33+
{
34+
/**
35+
* @var Breed
36+
*/
37+
public string $breed;
38+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php // lint >= 8.1
2+
3+
declare(strict_types = 1);
4+
5+
namespace Bug13332Generics;
6+
7+
enum TestEnum {
8+
case A;
9+
case B;
10+
}
11+
12+
/**
13+
* @phpstan-type KeyType string|int|\UnitEnum|object
14+
*
15+
* @template K of KeyType
16+
*/
17+
class TestError
18+
{
19+
/** @param K $key */
20+
public function __construct(private readonly mixed $key)
21+
{
22+
}
23+
24+
/** @return self<TestEnum> */
25+
public static function makeEnum(): self
26+
{
27+
return new self(TestEnum::A);
28+
}
29+
30+
/** @return self<string> */
31+
public static function makeString(): self
32+
{
33+
return new self('foo');
34+
}
35+
}
36+
37+
/**
38+
* @template K of string|int|\UnitEnum|object
39+
*/
40+
class TestOk
41+
{
42+
/** @param K $key */
43+
public function __construct(private readonly mixed $key)
44+
{
45+
}
46+
47+
/** @return self<TestEnum> */
48+
public static function makeEnum(): self
49+
{
50+
return new self(TestEnum::A);
51+
}
52+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug7152Generics;
4+
5+
/**
6+
* @template T of array<mixed>
7+
*/
8+
class Root
9+
{
10+
/** @var T */
11+
public array $value;
12+
}
13+
14+
/**
15+
* @phpstan-type Foo array<int>
16+
* @template T of Foo
17+
* @extends Root<T>
18+
*/
19+
class Middle extends Root
20+
{
21+
}
22+
23+
/**
24+
* @template T of array<int>
25+
* @extends Root<T>
26+
*/
27+
class Middle2 extends Root
28+
{
29+
}

0 commit comments

Comments
 (0)