|
2 | 2 |
|
3 | 3 | namespace PHPStan\Type\BeberleiAssert;
|
4 | 4 |
|
5 |
| -use PHPStan\Rules\Rule; |
| 5 | +use PHPStan\Testing\TypeInferenceTestCase; |
6 | 6 |
|
7 |
| -/** |
8 |
| - * @extends \PHPStan\Testing\RuleTestCase<VariableTypeReportingRule> |
9 |
| - */ |
10 |
| -class AssertTypeSpecifyingExtensionTest extends \PHPStan\Testing\RuleTestCase |
| 7 | +class AssertTypeSpecifyingExtensionTest extends TypeInferenceTestCase |
11 | 8 | {
|
12 | 9 |
|
13 |
| - protected function getRule(): Rule |
14 |
| - { |
15 |
| - return new VariableTypeReportingRule(); |
16 |
| - } |
17 |
| - |
18 |
| - /** |
19 |
| - * @return \PHPStan\Type\StaticMethodTypeSpecifyingExtension[] |
20 |
| - */ |
21 |
| - protected function getStaticMethodTypeSpecifyingExtensions(): array |
22 |
| - { |
23 |
| - return [ |
24 |
| - new AssertTypeSpecifyingExtension(), |
25 |
| - ]; |
26 |
| - } |
27 |
| - |
28 |
| - /** |
29 |
| - * @return \PHPStan\Type\MethodTypeSpecifyingExtension[] |
30 |
| - */ |
31 |
| - protected function getMethodTypeSpecifyingExtensions(): array |
32 |
| - { |
33 |
| - return [ |
34 |
| - new AssertionChainTypeSpecifyingExtension(), |
35 |
| - ]; |
36 |
| - } |
37 |
| - |
38 |
| - /** |
39 |
| - * @return \PHPStan\Type\DynamicMethodReturnTypeExtension[] |
40 |
| - */ |
41 |
| - public function getDynamicMethodReturnTypeExtensions(): array |
42 |
| - { |
43 |
| - return [ |
44 |
| - new AssertionChainDynamicReturnTypeExtension(), |
45 |
| - ]; |
46 |
| - } |
47 |
| - |
48 | 10 | /**
|
49 |
| - * @return \PHPStan\Type\DynamicStaticMethodReturnTypeExtension[] |
| 11 | + * @return iterable<mixed> |
50 | 12 | */
|
51 |
| - public function getDynamicStaticMethodReturnTypeExtensions(): array |
| 13 | + public function dataFileAsserts(): iterable |
52 | 14 | {
|
53 |
| - return [ |
54 |
| - new AssertThatDynamicMethodReturnTypeExtension(), |
55 |
| - ]; |
| 15 | + yield from $this->gatherAssertTypes(__DIR__ . '/data/data.php'); |
56 | 16 | }
|
57 | 17 |
|
58 | 18 | /**
|
59 |
| - * @return \PHPStan\Type\DynamicFunctionReturnTypeExtension[] |
| 19 | + * @dataProvider dataFileAsserts |
| 20 | + * @param string $assertType |
| 21 | + * @param string $file |
| 22 | + * @param mixed ...$args |
60 | 23 | */
|
61 |
| - public function getDynamicFunctionReturnTypeExtensions(): array |
| 24 | + public function testFileAsserts( |
| 25 | + string $assertType, |
| 26 | + string $file, |
| 27 | + ...$args |
| 28 | + ): void |
62 | 29 | {
|
63 |
| - return [ |
64 |
| - new AssertThatFunctionDynamicReturnTypeExtension(), |
65 |
| - ]; |
| 30 | + $this->assertFileAsserts($assertType, $file, ...$args); |
66 | 31 | }
|
67 | 32 |
|
68 |
| - public function testExtension(): void |
| 33 | + public static function getAdditionalConfigFiles(): array |
69 | 34 | {
|
70 |
| - $this->analyse([__DIR__ . '/data/data.php'], [ |
71 |
| - [ |
72 |
| - 'Variable $a is: mixed', |
73 |
| - 12, |
74 |
| - ], |
75 |
| - [ |
76 |
| - 'Variable $a is: int', |
77 |
| - 15, |
78 |
| - ], |
79 |
| - [ |
80 |
| - 'Variable $b is: int|null', |
81 |
| - 18, |
82 |
| - ], |
83 |
| - [ |
84 |
| - 'Variable $c is: array<int>', |
85 |
| - 21, |
86 |
| - ], |
87 |
| - [ |
88 |
| - 'Variable $d is: iterable<int>', |
89 |
| - 24, |
90 |
| - ], |
91 |
| - [ |
92 |
| - 'Variable $e is: string', |
93 |
| - 27, |
94 |
| - ], |
95 |
| - [ |
96 |
| - 'Variable $f is: float', |
97 |
| - 30, |
98 |
| - ], |
99 |
| - [ |
100 |
| - 'Variable $g is: float|int|(string&numeric)', |
101 |
| - 33, |
102 |
| - ], |
103 |
| - [ |
104 |
| - 'Variable $h is: bool', |
105 |
| - 36, |
106 |
| - ], |
107 |
| - [ |
108 |
| - 'Variable $i is: bool|float|int|string', |
109 |
| - 39, |
110 |
| - ], |
111 |
| - [ |
112 |
| - 'Variable $j is: object', |
113 |
| - 42, |
114 |
| - ], |
115 |
| - [ |
116 |
| - 'Variable $k is: resource', |
117 |
| - 45, |
118 |
| - ], |
119 |
| - [ |
120 |
| - 'Variable $l is: callable(): mixed', |
121 |
| - 48, |
122 |
| - ], |
123 |
| - [ |
124 |
| - 'Variable $m is: array', |
125 |
| - 51, |
126 |
| - ], |
127 |
| - [ |
128 |
| - 'Variable $n is: string', |
129 |
| - 54, |
130 |
| - ], |
131 |
| - [ |
132 |
| - 'Variable $p is: PHPStan\Type\BeberleiAssert\Foo', |
133 |
| - 57, |
134 |
| - ], |
135 |
| - [ |
136 |
| - 'Variable $q is: PHPStan\Type\BeberleiAssert\Foo', |
137 |
| - 62, |
138 |
| - ], |
139 |
| - [ |
140 |
| - 'Variable $r is: true', |
141 |
| - 65, |
142 |
| - ], |
143 |
| - [ |
144 |
| - 'Variable $s is: false', |
145 |
| - 68, |
146 |
| - ], |
147 |
| - [ |
148 |
| - 'Variable $t is: null', |
149 |
| - 71, |
150 |
| - ], |
151 |
| - [ |
152 |
| - 'Variable $u is: int', |
153 |
| - 74, |
154 |
| - ], |
155 |
| - [ |
156 |
| - 'Variable $v is: array<PHPStan\Type\BeberleiAssert\Foo>', |
157 |
| - 79, |
158 |
| - ], |
159 |
| - [ |
160 |
| - 'Variable $w is: array<int>', |
161 |
| - 84, |
162 |
| - ], |
163 |
| - [ |
164 |
| - 'Variable $x is: 1', |
165 |
| - 87, |
166 |
| - ], |
167 |
| - [ |
168 |
| - 'Variable $y is: -1|1', |
169 |
| - 95, |
170 |
| - ], |
171 |
| - [ |
172 |
| - 'Variable $y is: -1', |
173 |
| - 97, |
174 |
| - ], |
175 |
| - [ |
176 |
| - 'Variable $z is: array(1, -2|2, -3|3)', |
177 |
| - 104, |
178 |
| - ], |
179 |
| - [ |
180 |
| - 'Variable $aa is: class-string<PHPStan\Type\BeberleiAssert\Foo>|PHPStan\Type\BeberleiAssert\Foo', |
181 |
| - 107, |
182 |
| - ], |
183 |
| - [ |
184 |
| - 'Variable $ab is: array', // should be array<PHPStan\Type\BeberleiAssert\Foo> |
185 |
| - 110, |
186 |
| - ], |
187 |
| - [ |
188 |
| - 'Variable $ac is: string', |
189 |
| - 113, |
190 |
| - ], |
191 |
| - [ |
192 |
| - 'Variable $that is: Assert\AssertionChain<int|null>', |
193 |
| - 119, |
194 |
| - ], |
195 |
| - [ |
196 |
| - 'Variable $thatOrNull is: Assert\AssertionChain<int|null>', |
197 |
| - 122, |
198 |
| - ], |
199 |
| - [ |
200 |
| - 'Variable $a is: int', |
201 |
| - 123, |
202 |
| - ], |
203 |
| - [ |
204 |
| - 'Variable $assertNullOr is: Assert\AssertionChain<mixed>-nullOr', |
205 |
| - 126, |
206 |
| - ], |
207 |
| - [ |
208 |
| - 'Variable $b is: string|null', |
209 |
| - 128, |
210 |
| - ], |
211 |
| - [ |
212 |
| - 'Variable $assertNullOr2 is: Assert\AssertionChain<mixed>-nullOr', |
213 |
| - 131, |
214 |
| - ], |
215 |
| - [ |
216 |
| - 'Variable $c is: string|null', |
217 |
| - 133, |
218 |
| - ], |
219 |
| - [ |
220 |
| - 'Variable $assertAll is: Assert\AssertionChain<array>-all', |
221 |
| - 136, |
222 |
| - ], |
223 |
| - [ |
224 |
| - 'Variable $d is: array<string>', |
225 |
| - 138, |
226 |
| - ], |
227 |
| - [ |
228 |
| - 'Variable $assertAll2 is: Assert\AssertionChain<iterable>-all', |
229 |
| - 141, |
230 |
| - ], |
231 |
| - [ |
232 |
| - 'Variable $e is: iterable<string>', |
233 |
| - 143, |
234 |
| - ], |
235 |
| - [ |
236 |
| - 'Variable $f is: array<string>', |
237 |
| - 148, |
238 |
| - ], |
239 |
| - [ |
240 |
| - 'Variable $assertThatFunction is: Assert\AssertionChain<mixed>', |
241 |
| - 151, |
242 |
| - ], |
243 |
| - [ |
244 |
| - 'Variable $assertThatNullOrFunction is: Assert\AssertionChain<mixed>-nullOr', |
245 |
| - 154, |
246 |
| - ], |
247 |
| - [ |
248 |
| - 'Variable $assertThatAllFunction is: Assert\AssertionChain<mixed>-all', |
249 |
| - 157, |
250 |
| - ], |
251 |
| - [ |
252 |
| - 'Variable $a is: array<stdClass>', |
253 |
| - 167, |
254 |
| - ], |
255 |
| - [ |
256 |
| - 'Variable $a is: float|int|(string&numeric)', |
257 |
| - 173, |
258 |
| - ], |
259 |
| - ]); |
| 35 | + return [__DIR__ . '/../../../extension.neon']; |
260 | 36 | }
|
261 | 37 |
|
262 | 38 | }
|
0 commit comments