Skip to content

Commit 1f6cc71

Browse files
committed
chore: move test to separate file
1 parent b944c2c commit 1f6cc71

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

stubs/ReflectionClass.stub

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ class ReflectionClass
5050
}
5151

5252
/**
53-
* @phpstan-assert-if-true class-string<UnitEnum> $this->getName()
53+
* @phpstan-assert-if-true class-string<\UnitEnum> $this->name
54+
* @phpstan-assert-if-true ReflectionClass<\UnitEnum> $this
55+
* @phpstan-assert-if-false !class-string<\UnitEnum> $this->name
5456
*/
5557
public function isEnum(): bool
5658
{

tests/PHPStan/Analyser/NodeScopeResolverTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ private static function findTestFiles(): iterable
238238
yield __DIR__ . '/../Rules/Methods/data/bug-4801.php';
239239
yield __DIR__ . '/../Rules/Arrays/data/narrow-superglobal.php';
240240
yield __DIR__ . '/../Rules/Methods/data/bug-12927.php';
241+
yield __DIR__ . '/data/reflectionclass-isEnum.php';
241242
}
242243

243244
/**

tests/PHPStan/Analyser/data/enum-reflection-php81.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
namespace EnumReflection81;
44

5-
use ReflectionClass;
65
use ReflectionEnum;
7-
use ReflectionEnumBackedCase;
8-
use ReflectionEnumUnitCase;
96
use function PHPStan\Testing\assertType;
107

118
enum Foo: int
@@ -22,16 +19,3 @@ function testNarrowGetBackingTypeAfterIsBacked() {
2219
assertType('ReflectionType', $r->getBackingType());
2320
}
2421
}
25-
26-
function testNarrowClassAfterIsEnum() {
27-
/**
28-
* @var class-string
29-
*/
30-
$classString = Foo::class;
31-
$r = new ReflectionClass($classString);
32-
assertType('class-string', $classString);
33-
if ($r->isEnum()) {
34-
assertType('class-string<\UnitEnum>', $classString);
35-
}
36-
}
37-
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php // lint >= 8.1
2+
3+
namespace ReflectionClassIsEnum;
4+
5+
use ReflectionClass;
6+
use function PHPStan\Testing\assertType;
7+
8+
/**
9+
* @param class-string $class
10+
*/
11+
function testNarrowClassAfterIsEnum(string $class): void {
12+
$r = new ReflectionClass($class);
13+
assertType('class-string<object>', $r->name);
14+
if ($r->isEnum()) {
15+
assertType('ReflectionClass<\UnitEnum>', $r);
16+
assertType('class-string<\UnitEnum>', $r->name);
17+
}
18+
}
19+

0 commit comments

Comments
 (0)