@@ -19,7 +19,7 @@ public static function dataPropertyHooks(): iterable
19
19
$ reflectionProvider = self ::createReflectionProvider ();
20
20
21
21
yield [
22
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\Foo ' ) ,
22
+ 'PropertyHooksTypes \\Foo ' ,
23
23
'i ' ,
24
24
'set ' ,
25
25
['int ' ],
@@ -28,7 +28,7 @@ public static function dataPropertyHooks(): iterable
28
28
];
29
29
30
30
yield [
31
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\Foo ' ) ,
31
+ 'PropertyHooksTypes \\Foo ' ,
32
32
'i ' ,
33
33
'get ' ,
34
34
[],
@@ -37,7 +37,7 @@ public static function dataPropertyHooks(): iterable
37
37
];
38
38
39
39
yield [
40
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\Foo ' ) ,
40
+ 'PropertyHooksTypes \\Foo ' ,
41
41
'l ' ,
42
42
'get ' ,
43
43
[],
@@ -46,7 +46,7 @@ public static function dataPropertyHooks(): iterable
46
46
];
47
47
48
48
yield [
49
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\Foo ' ) ,
49
+ 'PropertyHooksTypes \\Foo ' ,
50
50
'n ' ,
51
51
'set ' ,
52
52
['array<string>|int ' ],
@@ -55,7 +55,7 @@ public static function dataPropertyHooks(): iterable
55
55
];
56
56
57
57
yield [
58
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooShort ' ) ,
58
+ 'PropertyHooksTypes \\FooShort ' ,
59
59
'i ' ,
60
60
'set ' ,
61
61
['int ' ],
@@ -64,7 +64,7 @@ public static function dataPropertyHooks(): iterable
64
64
];
65
65
66
66
yield [
67
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooShort ' ) ,
67
+ 'PropertyHooksTypes \\FooShort ' ,
68
68
'k ' ,
69
69
'set ' ,
70
70
['int|string ' ],
@@ -73,7 +73,7 @@ public static function dataPropertyHooks(): iterable
73
73
];
74
74
75
75
yield [
76
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooShort ' ) ,
76
+ 'PropertyHooksTypes \\FooShort ' ,
77
77
'l ' ,
78
78
'set ' ,
79
79
['array<string> ' ],
@@ -82,7 +82,7 @@ public static function dataPropertyHooks(): iterable
82
82
];
83
83
84
84
yield [
85
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooShort ' ) ,
85
+ 'PropertyHooksTypes \\FooShort ' ,
86
86
'm ' ,
87
87
'set ' ,
88
88
['array<string> ' ],
@@ -91,7 +91,7 @@ public static function dataPropertyHooks(): iterable
91
91
];
92
92
93
93
yield [
94
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooShort ' ) ,
94
+ 'PropertyHooksTypes \\FooShort ' ,
95
95
'n ' ,
96
96
'set ' ,
97
97
['array<string>|int ' ],
@@ -100,7 +100,7 @@ public static function dataPropertyHooks(): iterable
100
100
];
101
101
102
102
yield [
103
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooConstructor ' ) ,
103
+ 'PropertyHooksTypes \\FooConstructor ' ,
104
104
'i ' ,
105
105
'set ' ,
106
106
['int ' ],
@@ -109,7 +109,7 @@ public static function dataPropertyHooks(): iterable
109
109
];
110
110
111
111
yield [
112
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooConstructor ' ) ,
112
+ 'PropertyHooksTypes \\FooConstructor ' ,
113
113
'j ' ,
114
114
'set ' ,
115
115
['int ' ],
@@ -118,7 +118,7 @@ public static function dataPropertyHooks(): iterable
118
118
];
119
119
120
120
yield [
121
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooConstructor ' ) ,
121
+ 'PropertyHooksTypes \\FooConstructor ' ,
122
122
'k ' ,
123
123
'set ' ,
124
124
['int|string ' ],
@@ -127,7 +127,7 @@ public static function dataPropertyHooks(): iterable
127
127
];
128
128
129
129
yield [
130
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooConstructor ' ) ,
130
+ 'PropertyHooksTypes \\FooConstructor ' ,
131
131
'l ' ,
132
132
'set ' ,
133
133
['array<string> ' ],
@@ -136,7 +136,7 @@ public static function dataPropertyHooks(): iterable
136
136
];
137
137
138
138
yield [
139
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooConstructor ' ) ,
139
+ 'PropertyHooksTypes \\FooConstructor ' ,
140
140
'l ' ,
141
141
'get ' ,
142
142
[],
@@ -145,7 +145,7 @@ public static function dataPropertyHooks(): iterable
145
145
];
146
146
147
147
yield [
148
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooConstructor ' ) ,
148
+ 'PropertyHooksTypes \\FooConstructor ' ,
149
149
'm ' ,
150
150
'set ' ,
151
151
['array<string> ' ],
@@ -154,7 +154,7 @@ public static function dataPropertyHooks(): iterable
154
154
];
155
155
156
156
yield [
157
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooConstructor ' ) ,
157
+ 'PropertyHooksTypes \\FooConstructor ' ,
158
158
'n ' ,
159
159
'set ' ,
160
160
['array<string>|int ' ],
@@ -163,7 +163,7 @@ public static function dataPropertyHooks(): iterable
163
163
];
164
164
165
165
yield [
166
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooConstructorWithParam ' ) ,
166
+ 'PropertyHooksTypes \\FooConstructorWithParam ' ,
167
167
'l ' ,
168
168
'set ' ,
169
169
['array<string> ' ],
@@ -172,7 +172,7 @@ public static function dataPropertyHooks(): iterable
172
172
];
173
173
174
174
yield [
175
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooConstructorWithParam ' ) ,
175
+ 'PropertyHooksTypes \\FooConstructorWithParam ' ,
176
176
'l ' ,
177
177
'get ' ,
178
178
[],
@@ -181,7 +181,7 @@ public static function dataPropertyHooks(): iterable
181
181
];
182
182
183
183
yield [
184
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooConstructorWithParam ' ) ,
184
+ 'PropertyHooksTypes \\FooConstructorWithParam ' ,
185
185
'm ' ,
186
186
'set ' ,
187
187
['array<string> ' ],
@@ -190,7 +190,7 @@ public static function dataPropertyHooks(): iterable
190
190
];
191
191
192
192
yield [
193
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooGenerics ' ) ,
193
+ 'PropertyHooksTypes \\FooGenerics ' ,
194
194
'm ' ,
195
195
'set ' ,
196
196
['array<T of stdClass (class PropertyHooksTypes\FooGenerics, parameter)> ' ],
@@ -199,7 +199,7 @@ public static function dataPropertyHooks(): iterable
199
199
];
200
200
201
201
yield [
202
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooGenerics ' ) ,
202
+ 'PropertyHooksTypes \\FooGenerics ' ,
203
203
'n ' ,
204
204
'set ' ,
205
205
['array<T of stdClass (class PropertyHooksTypes\FooGenerics, parameter)>|int ' ],
@@ -208,7 +208,7 @@ public static function dataPropertyHooks(): iterable
208
208
];
209
209
210
210
yield [
211
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooGenerics ' ) ,
211
+ 'PropertyHooksTypes \\FooGenerics ' ,
212
212
'm ' ,
213
213
'get ' ,
214
214
[],
@@ -217,80 +217,112 @@ public static function dataPropertyHooks(): iterable
217
217
];
218
218
219
219
yield [
220
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooGenerics ' ) ,
220
+ 'PropertyHooksTypes \\FooGenerics ' ,
221
221
'n ' ,
222
222
'get ' ,
223
223
[],
224
224
'int ' ,
225
225
true ,
226
226
];
227
227
228
- $ specificFooGenerics = (new GenericObjectType ('PropertyHooksTypes \\FooGenerics ' , [new IntegerType ()]))->getClassReflection ();
229
-
230
228
yield [
231
- $ specificFooGenerics ,
229
+ ' PropertyHooksTypes \\ FooGenerics ' ,
232
230
'n ' ,
233
- 'set ' ,
234
- [' array<int>|int ' ],
235
- 'void ' ,
231
+ 'get ' ,
232
+ [],
233
+ 'int ' ,
236
234
true ,
237
235
];
238
236
239
237
yield [
240
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooGenerics ' ) ,
241
- 'n ' ,
238
+ 'PropertyHooksTypes \\FooGenerics ' ,
239
+ 'm ' ,
242
240
'get ' ,
243
241
[],
244
- 'int ' ,
242
+ 'array<T of stdClass (class PropertyHooksTypes\FooGenerics, parameter)> ' ,
245
243
true ,
246
244
];
247
245
248
246
yield [
249
- $ specificFooGenerics ,
250
- 'm ' ,
247
+ ' PropertyHooksTypes \\ FooGenericsConstructor ' ,
248
+ 'l ' ,
251
249
'set ' ,
252
- ['array<int > ' ],
250
+ ['array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter) > ' ],
253
251
'void ' ,
254
252
true ,
255
253
];
256
254
257
255
yield [
258
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooGenerics ' ) ,
256
+ 'PropertyHooksTypes \\FooGenericsConstructor ' ,
259
257
'm ' ,
260
- 'get ' ,
261
- [],
262
- 'array<T of stdClass (class PropertyHooksTypes\FooGenerics, parameter)> ' ,
258
+ 'set ' ,
259
+ [' array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter)> ' ],
260
+ 'void ' ,
263
261
true ,
264
262
];
265
263
266
264
yield [
267
- $ reflectionProvider -> getClass ( 'PropertyHooksTypes \\FooGenericsConstructor ' ) ,
268
- 'l ' ,
265
+ 'PropertyHooksTypes \\FooGenericsConstructor ' ,
266
+ 'n ' ,
269
267
'set ' ,
270
- ['array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter)> ' ],
268
+ ['array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter)>|int ' ],
271
269
'void ' ,
272
270
true ,
273
271
];
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 ()]);
274
306
275
307
yield [
276
- $ reflectionProvider -> getClass ( ' PropertyHooksTypes \\ FooGenericsConstructor ' ) ,
308
+ $ specificFooGenerics ,
277
309
'm ' ,
278
310
'set ' ,
279
- ['array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter) > ' ],
311
+ ['array<int > ' ],
280
312
'void ' ,
281
313
true ,
282
314
];
283
315
284
316
yield [
285
- $ reflectionProvider -> getClass ( ' PropertyHooksTypes \\ FooGenericsConstructor ' ) ,
317
+ $ specificFooGenerics ,
286
318
'n ' ,
287
319
'set ' ,
288
- ['array<T of stdClass (class PropertyHooksTypes\FooGenericsConstructor, parameter) >|int ' ],
320
+ ['array<int >|int ' ],
289
321
'void ' ,
290
322
true ,
291
323
];
292
324
293
- $ specificFooGenericsConstructor = ( new GenericObjectType ('PropertyHooksTypes \\FooGenericsConstructor ' , [new IntegerType ()]))-> getClassReflection ( );
325
+ $ specificFooGenericsConstructor = new GenericObjectType ('PropertyHooksTypes \\FooGenericsConstructor ' , [new IntegerType ()]);
294
326
295
327
yield [
296
328
$ specificFooGenericsConstructor ,
@@ -324,16 +356,18 @@ public static function dataPropertyHooks(): iterable
324
356
* @param ExtendedPropertyReflection::HOOK_* $hookName
325
357
* @param string[] $parameterTypes
326
358
*/
327
- #[DataProvider('dataPropertyHooks ' )]
328
- public function testPropertyHooks (
329
- ClassReflection $ classReflection ,
359
+ #[DataProvider('dataPropertyHooksFromType ' )]
360
+ public function testPropertyHooksFromType (
361
+ GenericObjectType $ type ,
330
362
string $ propertyName ,
331
363
string $ hookName ,
332
364
array $ parameterTypes ,
333
365
string $ returnType ,
334
366
bool $ isVirtual ,
335
367
): void
336
368
{
369
+ $ classReflection = $ type ->getClassReflection ();
370
+ $ this ->assertNotNull ($ classReflection );
337
371
$ propertyReflection = $ classReflection ->getNativeProperty ($ propertyName );
338
372
$ this ->assertSame ($ isVirtual , $ propertyReflection ->isVirtual ()->yes ());
339
373
0 commit comments