/
InvalidPhpDocVarTagTypeRuleTest.php
154 lines (144 loc) · 4.75 KB
/
InvalidPhpDocVarTagTypeRuleTest.php
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php declare(strict_types = 1);
namespace PHPStan\Rules\PhpDoc;
use PHPStan\Rules\ClassCaseSensitivityCheck;
use PHPStan\Rules\Generics\GenericObjectTypeCheck;
use PHPStan\Rules\MissingTypehintCheck;
use PHPStan\Rules\Rule;
use PHPStan\Testing\RuleTestCase;
use PHPStan\Type\FileTypeMapper;
use const PHP_VERSION_ID;
/**
* @extends RuleTestCase<InvalidPhpDocVarTagTypeRule>
*/
class InvalidPhpDocVarTagTypeRuleTest extends RuleTestCase
{
protected function getRule(): Rule
{
$broker = $this->createReflectionProvider();
return new InvalidPhpDocVarTagTypeRule(
self::getContainer()->getByType(FileTypeMapper::class),
$broker,
new ClassCaseSensitivityCheck($broker, true),
new GenericObjectTypeCheck(),
new MissingTypehintCheck($broker, true, true, true, []),
new UnresolvableTypeHelper(),
true,
true,
);
}
public function testRule(): void
{
$this->analyse([__DIR__ . '/data/invalid-var-tag-type.php'], [
[
'PHPDoc tag @var for variable $test contains unresolvable type.',
13,
],
[
'PHPDoc tag @var contains unresolvable type.',
16,
],
[
'PHPDoc tag @var for variable $test contains unknown class InvalidVarTagType\aray.',
20,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'PHPDoc tag @var for variable $value contains unresolvable type.',
22,
],
[
'PHPDoc tag @var for variable $staticVar contains unresolvable type.',
27,
],
[
'Class InvalidVarTagType\Foo referenced with incorrect case: InvalidVarTagType\foo.',
31,
],
[
'PHPDoc tag @var for variable $test has invalid type InvalidVarTagType\FooTrait.',
34,
],
[
'PHPDoc tag @var for variable $test contains generic type InvalidPhpDoc\Foo<stdClass> but class InvalidPhpDoc\Foo is not generic.',
40,
],
[
'Generic type InvalidPhpDocDefinitions\FooGeneric<int> in PHPDoc tag @var for variable $test does not specify all template types of class InvalidPhpDocDefinitions\FooGeneric: T, U',
46,
],
[
'Generic type InvalidPhpDocDefinitions\FooGeneric<int, InvalidArgumentException, string> in PHPDoc tag @var for variable $test specifies 3 template types, but class InvalidPhpDocDefinitions\FooGeneric supports only 2: T, U',
49,
],
[
'Type Throwable in generic type InvalidPhpDocDefinitions\FooGeneric<int, Throwable> in PHPDoc tag @var for variable $test is not subtype of template type U of Exception of class InvalidPhpDocDefinitions\FooGeneric.',
52,
],
[
'Type stdClass in generic type InvalidPhpDocDefinitions\FooGeneric<int, stdClass> in PHPDoc tag @var for variable $test is not subtype of template type U of Exception of class InvalidPhpDocDefinitions\FooGeneric.',
55,
],
[
'PHPDoc tag @var for variable $test has no value type specified in iterable type array.',
58,
MissingTypehintCheck::TURN_OFF_MISSING_ITERABLE_VALUE_TYPE_TIP,
],
[
'PHPDoc tag @var for variable $test contains generic class InvalidPhpDocDefinitions\FooGeneric but does not specify its types: T, U',
61,
'You can turn this off by setting <fg=cyan>checkGenericClassInNonGenericObjectType: false</> in your <fg=cyan>%configurationFile%</>.',
],
[
'PHPDoc tag @var for variable $foo contains unknown class InvalidVarTagType\Blabla.',
67,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
]);
}
public function testBug4486(): void
{
$this->analyse([__DIR__ . '/data/bug-4486.php'], [
[
'PHPDoc tag @var for variable $one contains unknown class Some\Namespaced\ClassName1.',
10,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'PHPDoc tag @var for variable $two contains unknown class Some\Namespaced\ClassName2.',
10,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'PHPDoc tag @var for variable $three contains unknown class Some\Namespaced\ClassName1.',
15,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
]);
}
public function testBug4486Namespace(): void
{
$this->analyse([__DIR__ . '/data/bug-4486-ns.php'], [
[
'PHPDoc tag @var for variable $one contains unknown class Bug4486Namespace\ClassName1.',
6,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
[
'PHPDoc tag @var for variable $two contains unknown class Bug4486Namespace\ClassName1.',
10,
'Learn more at https://phpstan.org/user-guide/discovering-symbols',
],
]);
}
public function testBug6252(): void
{
if (PHP_VERSION_ID < 80000) {
$this->markTestSkipped('Test requires PHP 8.0.');
}
$this->analyse([__DIR__ . '/data/bug-6252.php'], []);
}
public function testBug6348(): void
{
$this->analyse([__DIR__ . '/data/bug-6348.php'], []);
}
}