@@ -143,47 +143,393 @@ public function testReturnTypeOfQueryMethodsWithExplicitObjectHydrationMode(Enti
143
143
}
144
144
145
145
/**
146
- * Test that we properly infer the return type of Query methods with explicit hydration mode that is not HYDRATE_OBJECT
146
+ * Test that we properly infer the return type of Query methods with explicit hydration mode of HYDRATE_ARRAY
147
147
*
148
- * We are never able to infer the return type here
148
+ * We can infer the return type by changing every object by an array
149
149
*/
150
- public function testReturnTypeOfQueryMethodsWithExplicitNonObjectHydrationMode (EntityManagerInterface $ em ): void
150
+ public function testReturnTypeOfQueryMethodsWithExplicitArrayHydrationMode (EntityManagerInterface $ em ): void
151
151
{
152
152
$ query = $ em ->createQuery ('
153
153
SELECT m
154
154
FROM QueryResult\Entities\Many m
155
155
' );
156
156
157
157
assertType (
158
- 'mixed ' ,
158
+ 'array<array> ' ,
159
159
$ query ->getResult (AbstractQuery::HYDRATE_ARRAY )
160
160
);
161
161
assertType (
162
- 'iterable ' ,
162
+ 'array<array> ' ,
163
+ $ query ->getArrayResult ()
164
+ );
165
+ assertType (
166
+ 'iterable<array> ' ,
163
167
$ query ->toIterable ([], AbstractQuery::HYDRATE_ARRAY )
164
168
);
165
169
assertType (
166
- 'mixed ' ,
170
+ 'array<array> ' ,
167
171
$ query ->execute (null , AbstractQuery::HYDRATE_ARRAY )
168
172
);
169
173
assertType (
170
- 'mixed ' ,
174
+ 'array<array> ' ,
171
175
$ query ->executeIgnoreQueryCache (null , AbstractQuery::HYDRATE_ARRAY )
172
176
);
173
177
assertType (
174
- 'mixed ' ,
178
+ 'array<array> ' ,
175
179
$ query ->executeUsingQueryCache (null , AbstractQuery::HYDRATE_ARRAY )
176
180
);
177
181
assertType (
178
- 'mixed ' ,
182
+ 'array ' ,
179
183
$ query ->getSingleResult (AbstractQuery::HYDRATE_ARRAY )
180
184
);
181
185
assertType (
182
- 'mixed ' ,
186
+ 'array|null ' ,
187
+ $ query ->getOneOrNullResult (AbstractQuery::HYDRATE_ARRAY )
188
+ );
189
+
190
+ $ query = $ em ->createQuery ('
191
+ SELECT m.intColumn, m.stringNullColumn
192
+ FROM QueryResult\Entities\Many m
193
+ ' );
194
+
195
+ assertType (
196
+ 'array<array{intColumn: int, stringNullColumn: string|null}> ' ,
197
+ $ query ->getResult (AbstractQuery::HYDRATE_ARRAY )
198
+ );
199
+ assertType (
200
+ 'array<array{intColumn: int, stringNullColumn: string|null}> ' ,
201
+ $ query ->getArrayResult ()
202
+ );
203
+ assertType (
204
+ 'array<array{intColumn: int, stringNullColumn: string|null}> ' ,
205
+ $ query ->execute (null , AbstractQuery::HYDRATE_ARRAY )
206
+ );
207
+ assertType (
208
+ 'array<array{intColumn: int, stringNullColumn: string|null}> ' ,
209
+ $ query ->executeIgnoreQueryCache (null , AbstractQuery::HYDRATE_ARRAY )
210
+ );
211
+ assertType (
212
+ 'array<array{intColumn: int, stringNullColumn: string|null}> ' ,
213
+ $ query ->executeUsingQueryCache (null , AbstractQuery::HYDRATE_ARRAY )
214
+ );
215
+ assertType (
216
+ 'array{intColumn: int, stringNullColumn: string|null} ' ,
217
+ $ query ->getSingleResult (AbstractQuery::HYDRATE_ARRAY )
218
+ );
219
+ assertType (
220
+ 'array{intColumn: int, stringNullColumn: string|null}|null ' ,
183
221
$ query ->getOneOrNullResult (AbstractQuery::HYDRATE_ARRAY )
184
222
);
185
223
}
186
224
225
+ /**
226
+ * Test that we properly infer the return type of Query methods with explicit hydration mode of HYDRATE_SCALAR
227
+ */
228
+ public function testReturnTypeOfQueryMethodsWithExplicitScalarHydrationMode (EntityManagerInterface $ em ): void
229
+ {
230
+ $ query = $ em ->createQuery ('
231
+ SELECT m
232
+ FROM QueryResult\Entities\Many m
233
+ ' );
234
+
235
+ assertType (
236
+ 'array<array> ' ,
237
+ $ query ->getResult (AbstractQuery::HYDRATE_SCALAR )
238
+ );
239
+ assertType (
240
+ 'array<array> ' ,
241
+ $ query ->getScalarResult ()
242
+ );
243
+ assertType (
244
+ 'iterable<array> ' ,
245
+ $ query ->toIterable ([], AbstractQuery::HYDRATE_SCALAR )
246
+ );
247
+ assertType (
248
+ 'array<array> ' ,
249
+ $ query ->execute (null , AbstractQuery::HYDRATE_SCALAR )
250
+ );
251
+ assertType (
252
+ 'array<array> ' ,
253
+ $ query ->executeIgnoreQueryCache (null , AbstractQuery::HYDRATE_SCALAR )
254
+ );
255
+ assertType (
256
+ 'array<array> ' ,
257
+ $ query ->executeUsingQueryCache (null , AbstractQuery::HYDRATE_SCALAR )
258
+ );
259
+ assertType (
260
+ 'array ' ,
261
+ $ query ->getSingleResult (AbstractQuery::HYDRATE_SCALAR )
262
+ );
263
+ assertType (
264
+ 'array|null ' ,
265
+ $ query ->getOneOrNullResult (AbstractQuery::HYDRATE_SCALAR )
266
+ );
267
+
268
+ $ query = $ em ->createQuery ('
269
+ SELECT m.intColumn, m.stringNullColumn
270
+ FROM QueryResult\Entities\Many m
271
+ ' );
272
+
273
+ assertType (
274
+ 'array<array{intColumn: int, stringNullColumn: string|null}> ' ,
275
+ $ query ->getResult (AbstractQuery::HYDRATE_SCALAR )
276
+ );
277
+ assertType (
278
+ 'array<array{intColumn: int, stringNullColumn: string|null}> ' ,
279
+ $ query ->getScalarResult ()
280
+ );
281
+ assertType (
282
+ 'array<array{intColumn: int, stringNullColumn: string|null}> ' ,
283
+ $ query ->execute (null , AbstractQuery::HYDRATE_SCALAR )
284
+ );
285
+ assertType (
286
+ 'array<array{intColumn: int, stringNullColumn: string|null}> ' ,
287
+ $ query ->executeIgnoreQueryCache (null , AbstractQuery::HYDRATE_SCALAR )
288
+ );
289
+ assertType (
290
+ 'array<array{intColumn: int, stringNullColumn: string|null}> ' ,
291
+ $ query ->executeUsingQueryCache (null , AbstractQuery::HYDRATE_SCALAR )
292
+ );
293
+ assertType (
294
+ 'array{intColumn: int, stringNullColumn: string|null} ' ,
295
+ $ query ->getSingleResult (AbstractQuery::HYDRATE_SCALAR )
296
+ );
297
+ assertType (
298
+ 'array{intColumn: int, stringNullColumn: string|null}|null ' ,
299
+ $ query ->getOneOrNullResult (AbstractQuery::HYDRATE_SCALAR )
300
+ );
301
+ }
302
+
303
+ /**
304
+ * Test that we properly infer the return type of Query methods with explicit hydration mode of HYDRATE_SCALAR
305
+ */
306
+ public function testReturnTypeOfQueryMethodsWithExplicitSingleScalarHydrationMode (EntityManagerInterface $ em ): void
307
+ {
308
+ $ query = $ em ->createQuery ('
309
+ SELECT m
310
+ FROM QueryResult\Entities\Many m
311
+ ' );
312
+
313
+ assertType (
314
+ 'array<array> ' ,
315
+ $ query ->getResult (AbstractQuery::HYDRATE_SINGLE_SCALAR )
316
+ );
317
+ assertType (
318
+ 'array<array> ' ,
319
+ $ query ->getSingleScalarResult ()
320
+ );
321
+ assertType (
322
+ 'iterable<array> ' ,
323
+ $ query ->toIterable ([], AbstractQuery::HYDRATE_SINGLE_SCALAR )
324
+ );
325
+ assertType (
326
+ 'array<array> ' ,
327
+ $ query ->execute (null , AbstractQuery::HYDRATE_SINGLE_SCALAR )
328
+ );
329
+ assertType (
330
+ 'array<array> ' ,
331
+ $ query ->executeIgnoreQueryCache (null , AbstractQuery::HYDRATE_SINGLE_SCALAR )
332
+ );
333
+ assertType (
334
+ 'array<array> ' ,
335
+ $ query ->executeUsingQueryCache (null , AbstractQuery::HYDRATE_SINGLE_SCALAR )
336
+ );
337
+ assertType (
338
+ 'array ' ,
339
+ $ query ->getSingleResult (AbstractQuery::HYDRATE_SINGLE_SCALAR )
340
+ );
341
+ assertType (
342
+ 'array|null ' ,
343
+ $ query ->getOneOrNullResult (AbstractQuery::HYDRATE_SINGLE_SCALAR )
344
+ );
345
+
346
+ $ query = $ em ->createQuery ('
347
+ SELECT m.intColumn
348
+ FROM QueryResult\Entities\Many m
349
+ ' );
350
+
351
+ assertType (
352
+ 'array<array{intColumn: int}> ' ,
353
+ $ query ->getResult (AbstractQuery::HYDRATE_SINGLE_SCALAR )
354
+ );
355
+ assertType (
356
+ 'array<array{intColumn: int}> ' ,
357
+ $ query ->getSingleScalarResult ()
358
+ );
359
+ assertType (
360
+ 'array<array{intColumn: int}> ' ,
361
+ $ query ->execute (null , AbstractQuery::HYDRATE_SINGLE_SCALAR )
362
+ );
363
+ assertType (
364
+ 'array<array{intColumn: int}> ' ,
365
+ $ query ->executeIgnoreQueryCache (null , AbstractQuery::HYDRATE_SINGLE_SCALAR )
366
+ );
367
+ assertType (
368
+ 'array<array{intColumn: int}> ' ,
369
+ $ query ->executeUsingQueryCache (null , AbstractQuery::HYDRATE_SINGLE_SCALAR )
370
+ );
371
+ assertType (
372
+ 'array{intColumn: int} ' ,
373
+ $ query ->getSingleResult (AbstractQuery::HYDRATE_SINGLE_SCALAR )
374
+ );
375
+ assertType (
376
+ 'array{intColumn: int}|null ' ,
377
+ $ query ->getOneOrNullResult (AbstractQuery::HYDRATE_SINGLE_SCALAR )
378
+ );
379
+ }
380
+
381
+ /**
382
+ * Test that we properly infer the return type of Query methods with explicit hydration mode of HYDRATE_SIMPLEOBJECT
383
+ *
384
+ * We are never able to infer the return type here
385
+ */
386
+ public function testReturnTypeOfQueryMethodsWithExplicitSimpleObjectHydrationMode (EntityManagerInterface $ em ): void
387
+ {
388
+ $ query = $ em ->createQuery ('
389
+ SELECT m
390
+ FROM QueryResult\Entities\Many m
391
+ ' );
392
+
393
+ assertType (
394
+ 'array<QueryResult\Entities\Many> ' ,
395
+ $ query ->getResult (AbstractQuery::HYDRATE_SIMPLEOBJECT )
396
+ );
397
+ assertType (
398
+ 'iterable<QueryResult\Entities\Many> ' ,
399
+ $ query ->toIterable ([], AbstractQuery::HYDRATE_SIMPLEOBJECT )
400
+ );
401
+ assertType (
402
+ 'array<QueryResult\Entities\Many> ' ,
403
+ $ query ->execute (null , AbstractQuery::HYDRATE_SIMPLEOBJECT )
404
+ );
405
+ assertType (
406
+ 'array<QueryResult\Entities\Many> ' ,
407
+ $ query ->executeIgnoreQueryCache (null , AbstractQuery::HYDRATE_SIMPLEOBJECT )
408
+ );
409
+ assertType (
410
+ 'array<QueryResult\Entities\Many> ' ,
411
+ $ query ->executeUsingQueryCache (null , AbstractQuery::HYDRATE_SIMPLEOBJECT )
412
+ );
413
+ assertType (
414
+ 'QueryResult\Entities\Many ' ,
415
+ $ query ->getSingleResult (AbstractQuery::HYDRATE_SIMPLEOBJECT )
416
+ );
417
+ assertType (
418
+ 'QueryResult\Entities\Many|null ' ,
419
+ $ query ->getOneOrNullResult (AbstractQuery::HYDRATE_SIMPLEOBJECT )
420
+ );
421
+
422
+ $ query = $ em ->createQuery ('
423
+ SELECT m.intColumn, m.stringNullColumn
424
+ FROM QueryResult\Entities\Many m
425
+ ' );
426
+
427
+ assertType (
428
+ 'array ' ,
429
+ $ query ->getResult (AbstractQuery::HYDRATE_SIMPLEOBJECT )
430
+ );
431
+ assertType (
432
+ 'array ' ,
433
+ $ query ->execute (null , AbstractQuery::HYDRATE_SIMPLEOBJECT )
434
+ );
435
+ assertType (
436
+ 'array ' ,
437
+ $ query ->executeIgnoreQueryCache (null , AbstractQuery::HYDRATE_SIMPLEOBJECT )
438
+ );
439
+ assertType (
440
+ 'array ' ,
441
+ $ query ->executeUsingQueryCache (null , AbstractQuery::HYDRATE_SIMPLEOBJECT )
442
+ );
443
+ assertType (
444
+ 'mixed ' ,
445
+ $ query ->getSingleResult (AbstractQuery::HYDRATE_SIMPLEOBJECT )
446
+ );
447
+ assertType (
448
+ 'mixed ' ,
449
+ $ query ->getOneOrNullResult (AbstractQuery::HYDRATE_SIMPLEOBJECT )
450
+ );
451
+ }
452
+
453
+ /**
454
+ * Test that we properly infer the return type of Query methods with explicit hydration mode of HYDRATE_SCALAR_COLUMN
455
+ *
456
+ * We are never able to infer the return type here
457
+ */
458
+ public function testReturnTypeOfQueryMethodsWithExplicitScalarColumnHydrationMode (EntityManagerInterface $ em ): void
459
+ {
460
+ $ query = $ em ->createQuery ('
461
+ SELECT m
462
+ FROM QueryResult\Entities\Many m
463
+ ' );
464
+
465
+ assertType (
466
+ 'array ' ,
467
+ $ query ->getResult (AbstractQuery::HYDRATE_SCALAR_COLUMN )
468
+ );
469
+ assertType (
470
+ 'array ' ,
471
+ $ query ->getSingleColumnResult ()
472
+ );
473
+ assertType (
474
+ 'iterable ' ,
475
+ $ query ->toIterable ([], AbstractQuery::HYDRATE_SCALAR_COLUMN )
476
+ );
477
+ assertType (
478
+ 'array ' ,
479
+ $ query ->execute (null , AbstractQuery::HYDRATE_SCALAR_COLUMN )
480
+ );
481
+ assertType (
482
+ 'array ' ,
483
+ $ query ->executeIgnoreQueryCache (null , AbstractQuery::HYDRATE_SCALAR_COLUMN )
484
+ );
485
+ assertType (
486
+ 'array ' ,
487
+ $ query ->executeUsingQueryCache (null , AbstractQuery::HYDRATE_SCALAR_COLUMN )
488
+ );
489
+ assertType (
490
+ 'mixed ' ,
491
+ $ query ->getSingleResult (AbstractQuery::HYDRATE_SCALAR_COLUMN )
492
+ );
493
+ assertType (
494
+ 'mixed ' ,
495
+ $ query ->getOneOrNullResult (AbstractQuery::HYDRATE_SCALAR_COLUMN )
496
+ );
497
+
498
+ $ query = $ em ->createQuery ('
499
+ SELECT m.intColumn
500
+ FROM QueryResult\Entities\Many m
501
+ ' );
502
+
503
+ assertType (
504
+ 'array<int> ' ,
505
+ $ query ->getResult (AbstractQuery::HYDRATE_SCALAR_COLUMN )
506
+ );
507
+ assertType (
508
+ 'array<int> ' ,
509
+ $ query ->getSingleColumnResult ()
510
+ );
511
+ assertType (
512
+ 'array<int> ' ,
513
+ $ query ->execute (null , AbstractQuery::HYDRATE_SCALAR_COLUMN )
514
+ );
515
+ assertType (
516
+ 'array<int> ' ,
517
+ $ query ->executeIgnoreQueryCache (null , AbstractQuery::HYDRATE_SCALAR_COLUMN )
518
+ );
519
+ assertType (
520
+ 'array<int> ' ,
521
+ $ query ->executeUsingQueryCache (null , AbstractQuery::HYDRATE_SCALAR_COLUMN )
522
+ );
523
+ assertType (
524
+ 'int ' ,
525
+ $ query ->getSingleResult (AbstractQuery::HYDRATE_SCALAR_COLUMN )
526
+ );
527
+ assertType (
528
+ 'int|null ' ,
529
+ $ query ->getOneOrNullResult (AbstractQuery::HYDRATE_SCALAR_COLUMN )
530
+ );
531
+ }
532
+
187
533
/**
188
534
* Test that we properly infer the return type of Query methods with explicit hydration mode that is not a constant value
189
535
*
0 commit comments