-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathbug-8985.php
More file actions
111 lines (79 loc) · 2.45 KB
/
bug-8985.php
File metadata and controls
111 lines (79 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php // lint >= 8.0
declare(strict_types = 1);
namespace Bug8985;
use function PHPStan\Testing\assertType;
class Entity
{
public string $value;
public function __construct(string $value)
{
$this->value = $value;
}
public function getValue(): string
{
return $this->value;
}
}
class Repository
{
/** @return array<int, Entity> */
public function getAll(): array
{
return [new Entity('test')];
}
public string $name = 'default';
/** @return array<int, Entity> */
public static function staticGetAll(): array
{
return [new Entity('test')];
}
public function getEntity(): Entity
{
return new Entity('test');
}
public const MY_CONST = 'const_value';
}
function testMethodCall(): void {
assert((new Repository())->getAll() === []);
$all = (new Repository())->getAll();
assertType('array<int, Bug8985\Entity>', $all);
$value = $all[0]->getValue();
}
function testNullsafeMethodCall(): void {
assert((new Repository())?->getEntity()?->getValue() === 'specific');
assertType('string', (new Repository())?->getEntity()?->getValue());
}
function testPropertyFetch(): void {
assert((new Repository())->name === 'foo');
assertType('string', (new Repository())->name);
}
function testNullsafePropertyFetch(): void {
assert((new Repository())?->name === 'foo');
assertType('string', (new Repository())?->name);
}
function testArrayDimFetch(): void {
assert((new Repository())->getAll()[0]->getValue() === 'specific');
assertType('string', (new Repository())->getAll()[0]->getValue());
}
function testStaticCall(): void {
assert((new Repository())::staticGetAll() === []);
assertType('array<int, Bug8985\Entity>', (new Repository())::staticGetAll());
}
function testChainedMethodCalls(): void {
assert((new Repository())->getEntity()->getValue() === 'specific');
assertType('string', (new Repository())->getEntity()->getValue());
}
function testChainedPropertyOnMethodCall(): void {
assert((new Repository())->getEntity()->value === 'specific');
assertType('string', (new Repository())->getEntity()->value);
}
function testClassConstFetch(): void {
assert((new Repository())::MY_CONST === 'const_value');
assertType("'const_value'", (new Repository())::MY_CONST);
}
function testClassConstFetchOnUnknownClass(string $class, string $anotherClass): void {
assert((new $class())::MY_CONST === 'const_value');
assertType("'const_value'", (new $class())::MY_CONST);
$class = $anotherClass;
assertType("*ERROR*", (new $class())::MY_CONST);
}