Skip to content

Commit c01d260

Browse files
committed
test narrowing oft *_exists() functions
1 parent bb3f89c commit c01d260

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

Diff for: tests/PHPStan/Analyser/nsrt/remember-readonly-constructor-narrowed.php

+29-1
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,46 @@ public function doFoo() {
2323

2424
readonly class HelloWorldReadonlyClass {
2525
private int $i;
26+
private string $class;
27+
private string $interface;
28+
private string $enum;
29+
private string $trait;
2630

27-
public function __construct()
31+
public function __construct(string $class, string $interface, string $enum, string $trait)
2832
{
2933
if (rand(0,1)) {
3034
$this->i = 4;
3135
} else {
3236
$this->i = 10;
3337
}
38+
39+
if (!class_exists($class)) {
40+
throw new \LogicException();
41+
}
42+
$this->class = $class;
43+
44+
if (!interface_exists($interface)) {
45+
throw new \LogicException();
46+
}
47+
$this->interface = $interface;
48+
49+
if (!enum_exists($enum)) {
50+
throw new \LogicException();
51+
}
52+
$this->enum = $enum;
53+
54+
if (!trait_exists($trait)) {
55+
throw new \LogicException();
56+
}
57+
$this->trait = $trait;
3458
}
3559

3660
public function doFoo() {
3761
assertType('4|10', $this->i);
62+
assertType('class-string', $this->class);
63+
assertType('class-string', $this->interface);
64+
assertType('class-string<UnitEnum>', $this->enum);
65+
assertType('class-string', $this->trait);
3866
}
3967
}
4068

0 commit comments

Comments
 (0)