Skip to content

Commit 227722f

Browse files
committed
Revert "Improve ClassReflectionPropertyHooksTest for PHPUnit 11"
This reverts commit 199466f.
1 parent acee3a4 commit 227722f

File tree

1 file changed

+50
-84
lines changed

1 file changed

+50
-84
lines changed

tests/PHPStan/Reflection/ClassReflectionPropertyHooksTest.php

Lines changed: 50 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public static function dataPropertyHooks(): iterable
1919
$reflectionProvider = self::createReflectionProvider();
2020

2121
yield [
22-
'PropertyHooksTypes\\Foo',
22+
$reflectionProvider->getClass('PropertyHooksTypes\\Foo'),
2323
'i',
2424
'set',
2525
['int'],
@@ -28,7 +28,7 @@ public static function dataPropertyHooks(): iterable
2828
];
2929

3030
yield [
31-
'PropertyHooksTypes\\Foo',
31+
$reflectionProvider->getClass('PropertyHooksTypes\\Foo'),
3232
'i',
3333
'get',
3434
[],
@@ -37,7 +37,7 @@ public static function dataPropertyHooks(): iterable
3737
];
3838

3939
yield [
40-
'PropertyHooksTypes\\Foo',
40+
$reflectionProvider->getClass('PropertyHooksTypes\\Foo'),
4141
'l',
4242
'get',
4343
[],
@@ -46,7 +46,7 @@ public static function dataPropertyHooks(): iterable
4646
];
4747

4848
yield [
49-
'PropertyHooksTypes\\Foo',
49+
$reflectionProvider->getClass('PropertyHooksTypes\\Foo'),
5050
'n',
5151
'set',
5252
['array<string>|int'],
@@ -55,7 +55,7 @@ public static function dataPropertyHooks(): iterable
5555
];
5656

5757
yield [
58-
'PropertyHooksTypes\\FooShort',
58+
$reflectionProvider->getClass('PropertyHooksTypes\\FooShort'),
5959
'i',
6060
'set',
6161
['int'],
@@ -64,7 +64,7 @@ public static function dataPropertyHooks(): iterable
6464
];
6565

6666
yield [
67-
'PropertyHooksTypes\\FooShort',
67+
$reflectionProvider->getClass('PropertyHooksTypes\\FooShort'),
6868
'k',
6969
'set',
7070
['int|string'],
@@ -73,7 +73,7 @@ public static function dataPropertyHooks(): iterable
7373
];
7474

7575
yield [
76-
'PropertyHooksTypes\\FooShort',
76+
$reflectionProvider->getClass('PropertyHooksTypes\\FooShort'),
7777
'l',
7878
'set',
7979
['array<string>'],
@@ -82,7 +82,7 @@ public static function dataPropertyHooks(): iterable
8282
];
8383

8484
yield [
85-
'PropertyHooksTypes\\FooShort',
85+
$reflectionProvider->getClass('PropertyHooksTypes\\FooShort'),
8686
'm',
8787
'set',
8888
['array<string>'],
@@ -91,7 +91,7 @@ public static function dataPropertyHooks(): iterable
9191
];
9292

9393
yield [
94-
'PropertyHooksTypes\\FooShort',
94+
$reflectionProvider->getClass('PropertyHooksTypes\\FooShort'),
9595
'n',
9696
'set',
9797
['array<string>|int'],
@@ -100,7 +100,7 @@ public static function dataPropertyHooks(): iterable
100100
];
101101

102102
yield [
103-
'PropertyHooksTypes\\FooConstructor',
103+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
104104
'i',
105105
'set',
106106
['int'],
@@ -109,7 +109,7 @@ public static function dataPropertyHooks(): iterable
109109
];
110110

111111
yield [
112-
'PropertyHooksTypes\\FooConstructor',
112+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
113113
'j',
114114
'set',
115115
['int'],
@@ -118,7 +118,7 @@ public static function dataPropertyHooks(): iterable
118118
];
119119

120120
yield [
121-
'PropertyHooksTypes\\FooConstructor',
121+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
122122
'k',
123123
'set',
124124
['int|string'],
@@ -127,7 +127,7 @@ public static function dataPropertyHooks(): iterable
127127
];
128128

129129
yield [
130-
'PropertyHooksTypes\\FooConstructor',
130+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
131131
'l',
132132
'set',
133133
['array<string>'],
@@ -136,7 +136,7 @@ public static function dataPropertyHooks(): iterable
136136
];
137137

138138
yield [
139-
'PropertyHooksTypes\\FooConstructor',
139+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
140140
'l',
141141
'get',
142142
[],
@@ -145,7 +145,7 @@ public static function dataPropertyHooks(): iterable
145145
];
146146

147147
yield [
148-
'PropertyHooksTypes\\FooConstructor',
148+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
149149
'm',
150150
'set',
151151
['array<string>'],
@@ -154,7 +154,7 @@ public static function dataPropertyHooks(): iterable
154154
];
155155

156156
yield [
157-
'PropertyHooksTypes\\FooConstructor',
157+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructor'),
158158
'n',
159159
'set',
160160
['array<string>|int'],
@@ -163,7 +163,7 @@ public static function dataPropertyHooks(): iterable
163163
];
164164

165165
yield [
166-
'PropertyHooksTypes\\FooConstructorWithParam',
166+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructorWithParam'),
167167
'l',
168168
'set',
169169
['array<string>'],
@@ -172,7 +172,7 @@ public static function dataPropertyHooks(): iterable
172172
];
173173

174174
yield [
175-
'PropertyHooksTypes\\FooConstructorWithParam',
175+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructorWithParam'),
176176
'l',
177177
'get',
178178
[],
@@ -181,7 +181,7 @@ public static function dataPropertyHooks(): iterable
181181
];
182182

183183
yield [
184-
'PropertyHooksTypes\\FooConstructorWithParam',
184+
$reflectionProvider->getClass('PropertyHooksTypes\\FooConstructorWithParam'),
185185
'm',
186186
'set',
187187
['array<string>'],
@@ -190,7 +190,7 @@ public static function dataPropertyHooks(): iterable
190190
];
191191

192192
yield [
193-
'PropertyHooksTypes\\FooGenerics',
193+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
194194
'm',
195195
'set',
196196
['array<T of stdClass (class PropertyHooksTypes\FooGenerics, parameter)>'],
@@ -199,7 +199,7 @@ public static function dataPropertyHooks(): iterable
199199
];
200200

201201
yield [
202-
'PropertyHooksTypes\\FooGenerics',
202+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
203203
'n',
204204
'set',
205205
['array<T of stdClass (class PropertyHooksTypes\FooGenerics, parameter)>|int'],
@@ -208,7 +208,7 @@ public static function dataPropertyHooks(): iterable
208208
];
209209

210210
yield [
211-
'PropertyHooksTypes\\FooGenerics',
211+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
212212
'm',
213213
'get',
214214
[],
@@ -217,112 +217,80 @@ public static function dataPropertyHooks(): iterable
217217
];
218218

219219
yield [
220-
'PropertyHooksTypes\\FooGenerics',
220+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
221221
'n',
222222
'get',
223223
[],
224224
'int',
225225
true,
226226
];
227227

228+
$specificFooGenerics = (new GenericObjectType('PropertyHooksTypes\\FooGenerics', [new IntegerType()]))->getClassReflection();
229+
228230
yield [
229-
'PropertyHooksTypes\\FooGenerics',
231+
$specificFooGenerics,
230232
'n',
231-
'get',
232-
[],
233-
'int',
233+
'set',
234+
['array<int>|int'],
235+
'void',
234236
true,
235237
];
236238

237239
yield [
238-
'PropertyHooksTypes\\FooGenerics',
239-
'm',
240+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
241+
'n',
240242
'get',
241243
[],
242-
'array<T of stdClass (class PropertyHooksTypes\FooGenerics, parameter)>',
244+
'int',
243245
true,
244246
];
245247

246248
yield [
247-
'PropertyHooksTypes\\FooGenericsConstructor',
248-
'l',
249+
$specificFooGenerics,
250+
'm',
249251
'set',
250-
['array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter)>'],
252+
['array<int>'],
251253
'void',
252254
true,
253255
];
254256

255257
yield [
256-
'PropertyHooksTypes\\FooGenericsConstructor',
258+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenerics'),
257259
'm',
258-
'set',
259-
['array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter)>'],
260-
'void',
260+
'get',
261+
[],
262+
'array<T of stdClass (class PropertyHooksTypes\FooGenerics, parameter)>',
261263
true,
262264
];
263265

264266
yield [
265-
'PropertyHooksTypes\\FooGenericsConstructor',
266-
'n',
267+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenericsConstructor'),
268+
'l',
267269
'set',
268-
['array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter)>|int'],
270+
['array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter)>'],
269271
'void',
270272
true,
271273
];
272-
}
273-
274-
/**
275-
* @param ExtendedPropertyReflection::HOOK_* $hookName
276-
* @param string[] $parameterTypes
277-
*/
278-
#[DataProvider('dataPropertyHooks')]
279-
public function testPropertyHooks(
280-
string $className,
281-
string $propertyName,
282-
string $hookName,
283-
array $parameterTypes,
284-
string $returnType,
285-
bool $isVirtual,
286-
): void
287-
{
288-
$reflectionProvider = $this->createReflectionProvider();
289-
$classReflection = $reflectionProvider->getClass($className);
290-
$propertyReflection = $classReflection->getNativeProperty($propertyName);
291-
$this->assertSame($isVirtual, $propertyReflection->isVirtual()->yes());
292-
293-
$hookReflection = $propertyReflection->getHook($hookName);
294-
$hookVariant = $hookReflection->getOnlyVariant();
295-
$this->assertSame($returnType, $hookVariant->getReturnType()->describe(VerbosityLevel::precise()));
296-
$this->assertCount(count($parameterTypes), $hookVariant->getParameters());
297-
298-
foreach ($hookVariant->getParameters() as $i => $parameter) {
299-
$this->assertSame($parameterTypes[$i], $parameter->getType()->describe(VerbosityLevel::precise()));
300-
}
301-
}
302-
303-
public static function dataPropertyHooksFromType(): iterable
304-
{
305-
$specificFooGenerics = new GenericObjectType('PropertyHooksTypes\\FooGenerics', [new IntegerType()]);
306274

307275
yield [
308-
$specificFooGenerics,
276+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenericsConstructor'),
309277
'm',
310278
'set',
311-
['array<int>'],
279+
['array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter)>'],
312280
'void',
313281
true,
314282
];
315283

316284
yield [
317-
$specificFooGenerics,
285+
$reflectionProvider->getClass('PropertyHooksTypes\\FooGenericsConstructor'),
318286
'n',
319287
'set',
320-
['array<int>|int'],
288+
['array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter)>|int'],
321289
'void',
322290
true,
323291
];
324292

325-
$specificFooGenericsConstructor = new GenericObjectType('PropertyHooksTypes\\FooGenericsConstructor', [new IntegerType()]);
293+
$specificFooGenericsConstructor = (new GenericObjectType('PropertyHooksTypes\\FooGenericsConstructor', [new IntegerType()]))->getClassReflection();
326294

327295
yield [
328296
$specificFooGenericsConstructor,
@@ -356,18 +324,16 @@ public static function dataPropertyHooksFromType(): iterable
356324
* @param ExtendedPropertyReflection::HOOK_* $hookName
357325
* @param string[] $parameterTypes
358326
*/
359-
#[DataProvider('dataPropertyHooksFromType')]
360-
public function testPropertyHooksFromType(
361-
GenericObjectType $type,
327+
#[DataProvider('dataPropertyHooks')]
328+
public function testPropertyHooks(
329+
ClassReflection $classReflection,
362330
string $propertyName,
363331
string $hookName,
364332
array $parameterTypes,
365333
string $returnType,
366334
bool $isVirtual,
367335
): void
368336
{
369-
$classReflection = $type->getClassReflection();
370-
$this->assertNotNull($classReflection);
371337
$propertyReflection = $classReflection->getNativeProperty($propertyName);
372338
$this->assertSame($isVirtual, $propertyReflection->isVirtual()->yes());
373339

0 commit comments

Comments
 (0)