31
31
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \EmbeddableDummy ;
32
32
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \RelatedDummy ;
33
33
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \UnknownDummy ;
34
+ use Doctrine \ORM \AbstractQuery ;
34
35
use Doctrine \ORM \EntityManager ;
35
36
use Doctrine \ORM \Mapping \ClassMetadata ;
36
37
use Doctrine \ORM \Mapping \ClassMetadataInfo ;
@@ -122,6 +123,9 @@ public function testApplyToCollection()
122
123
$ queryBuilderProphecy ->addSelect ('partial relatedDummy_a1.{id,name,embeddedDummy.name} ' )->shouldBeCalled (1 );
123
124
$ queryBuilderProphecy ->addSelect ('partial relatedDummy2_a2.{id,name,embeddedDummy.name} ' )->shouldBeCalled (1 );
124
125
126
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
127
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (3 );
128
+
125
129
$ queryBuilder = $ queryBuilderProphecy ->reveal ();
126
130
$ eagerExtensionTest = new EagerLoadingExtension ($ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), 30 , false , null , null , true );
127
131
$ eagerExtensionTest ->applyToCollection ($ queryBuilder , new QueryNameGenerator (), Dummy::class, null , $ context );
@@ -228,6 +232,9 @@ public function testApplyToItem()
228
232
$ queryBuilderProphecy ->addSelect ('partial relatedDummy4_a5.{id} ' )->shouldBeCalled (1 );
229
233
$ queryBuilderProphecy ->addSelect ('singleInheritanceRelation_a6 ' )->shouldBeCalled (1 );
230
234
235
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
236
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (7 );
237
+
231
238
$ queryBuilder = $ queryBuilderProphecy ->reveal ();
232
239
$ orderExtensionTest = new EagerLoadingExtension ($ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), 30 , false , null , null , true );
233
240
@@ -253,6 +260,8 @@ public function testCreateItemWithOperationName()
253
260
$ emProphecy ->getClassMetadata (Dummy::class)->shouldBeCalled ()->willReturn ($ classMetadataProphecy ->reveal ());
254
261
$ queryBuilderProphecy ->getRootAliases ()->willReturn (['o ' ]);
255
262
$ queryBuilderProphecy ->getEntityManager ()->willReturn ($ emProphecy );
263
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
264
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (1 );
256
265
257
266
$ orderExtensionTest = new EagerLoadingExtension ($ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), 30 , false , null , null , true );
258
267
$ orderExtensionTest ->applyToItem ($ queryBuilderProphecy ->reveal (), new QueryNameGenerator (), Dummy::class, [], 'item_operation ' , ['groups ' => ['foo ' ]]);
@@ -277,6 +286,8 @@ public function testCreateCollectionWithOperationName()
277
286
$ emProphecy ->getClassMetadata (Dummy::class)->shouldBeCalled ()->willReturn ($ classMetadataProphecy ->reveal ());
278
287
$ queryBuilderProphecy ->getRootAliases ()->willReturn (['o ' ]);
279
288
$ queryBuilderProphecy ->getEntityManager ()->willReturn ($ emProphecy );
289
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
290
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (1 );
280
291
281
292
$ eagerExtensionTest = new EagerLoadingExtension ($ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), 30 , false , null , null , true );
282
293
$ eagerExtensionTest ->applyToCollection ($ queryBuilderProphecy ->reveal (), new QueryNameGenerator (), Dummy::class, 'collection_operation ' , ['groups ' => ['foo ' ]]);
@@ -300,6 +311,8 @@ public function testDenormalizeItemWithCorrectResourceClass()
300
311
$ queryBuilderProphecy = $ this ->prophesize (QueryBuilder::class);
301
312
$ queryBuilderProphecy ->getRootAliases ()->willReturn (['o ' ]);
302
313
$ queryBuilderProphecy ->getEntityManager ()->willReturn ($ emProphecy );
314
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
315
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (1 );
303
316
304
317
$ eagerExtensionTest = new EagerLoadingExtension ($ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), 30 , false , null , null , true );
305
318
$ eagerExtensionTest ->applyToItem ($ queryBuilderProphecy ->reveal (), new QueryNameGenerator (), RelatedDummy::class, ['id ' => 1 ], 'item_operation ' , ['resource_class ' => Dummy::class]);
@@ -322,6 +335,8 @@ public function testDenormalizeItemWithExistingGroups()
322
335
$ queryBuilderProphecy = $ this ->prophesize (QueryBuilder::class);
323
336
$ queryBuilderProphecy ->getRootAliases ()->willReturn (['o ' ]);
324
337
$ queryBuilderProphecy ->getEntityManager ()->willReturn ($ emProphecy );
338
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
339
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (1 );
325
340
326
341
$ eagerExtensionTest = new EagerLoadingExtension ($ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), 30 , false , null , null , true );
327
342
$ eagerExtensionTest ->applyToItem ($ queryBuilderProphecy ->reveal (), new QueryNameGenerator (), RelatedDummy::class, ['id ' => 1 ], 'item_operation ' , [AbstractNormalizer::GROUPS => 'some_groups ' ]);
@@ -442,6 +457,8 @@ public function testMaxDepth()
442
457
443
458
$ queryBuilderProphecy ->innerJoin (Argument::type ('string ' ), Argument::type ('string ' ))->shouldBeCalledTimes (2 );
444
459
$ queryBuilderProphecy ->addSelect (Argument::type ('string ' ))->shouldBeCalled ();
460
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
461
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (3 );
445
462
446
463
$ eagerExtensionTest = new EagerLoadingExtension ($ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), 30 , false , null , null , true , $ classMetadataFactoryProphecy ->reveal ());
447
464
$ eagerExtensionTest ->applyToCollection ($ queryBuilderProphecy ->reveal (), new QueryNameGenerator (), Dummy::class);
@@ -487,6 +504,9 @@ public function testForceEager()
487
504
$ queryBuilderProphecy ->getRootAliases ()->willReturn (['o ' ]);
488
505
$ queryBuilderProphecy ->getEntityManager ()->willReturn ($ emProphecy );
489
506
507
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
508
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (2 );
509
+
490
510
$ orderExtensionTest = new EagerLoadingExtension ($ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), 30 , true , null , null , true );
491
511
$ orderExtensionTest ->applyToItem ($ queryBuilderProphecy ->reveal (), new QueryNameGenerator (), Dummy::class, []);
492
512
}
@@ -523,6 +543,9 @@ public function testExtraLazy()
523
543
$ queryBuilderProphecy ->getRootAliases ()->willReturn (['o ' ]);
524
544
$ queryBuilderProphecy ->getEntityManager ()->willReturn ($ emProphecy );
525
545
546
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
547
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (1 );
548
+
526
549
$ orderExtensionTest = new EagerLoadingExtension ($ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), 30 , true , null , null , true );
527
550
$ orderExtensionTest ->applyToItem ($ queryBuilderProphecy ->reveal (), new QueryNameGenerator (), Dummy::class, []);
528
551
}
@@ -546,6 +569,8 @@ public function testResourceClassNotFoundException()
546
569
$ queryBuilderProphecy = $ this ->prophesize (QueryBuilder::class);
547
570
$ queryBuilderProphecy ->getRootAliases ()->willReturn (['o ' ]);
548
571
$ queryBuilderProphecy ->getEntityManager ()->willReturn ($ emProphecy );
572
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
573
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (1 );
549
574
550
575
$ orderExtensionTest = new EagerLoadingExtension ($ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), 30 , true , null , null , true );
551
576
$ orderExtensionTest ->applyToItem ($ queryBuilderProphecy ->reveal (), new QueryNameGenerator (), Dummy::class, [], null );
@@ -570,6 +595,8 @@ public function testPropertyNotFoundException()
570
595
$ queryBuilderProphecy = $ this ->prophesize (QueryBuilder::class);
571
596
$ queryBuilderProphecy ->getRootAliases ()->willReturn (['o ' ]);
572
597
$ queryBuilderProphecy ->getEntityManager ()->willReturn ($ emProphecy );
598
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
599
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (1 );
573
600
574
601
$ orderExtensionTest = new EagerLoadingExtension ($ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), 30 , true , null , null , true );
575
602
$ orderExtensionTest ->applyToItem ($ queryBuilderProphecy ->reveal (), new QueryNameGenerator (), Dummy::class, []);
@@ -599,6 +626,8 @@ public function testResourceClassNotFoundExceptionPropertyNameCollection()
599
626
$ queryBuilderProphecy ->getRootAliases ()->willReturn (['o ' ]);
600
627
$ queryBuilderProphecy ->getEntityManager ()->willReturn ($ emProphecy );
601
628
$ queryBuilderProphecy ->innerJoin ('o.relation ' , 'relation_a1 ' )->shouldBeCalled (1 );
629
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
630
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (1 );
602
631
603
632
$ orderExtensionTest = new EagerLoadingExtension ($ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), 30 , true , null , null , true );
604
633
$ orderExtensionTest ->applyToItem ($ queryBuilderProphecy ->reveal (), new QueryNameGenerator (), Dummy::class, []);
@@ -654,6 +683,8 @@ public function testApplyToCollectionWithSerializerContextBuilder()
654
683
655
684
$ queryBuilderProphecy ->leftJoin ('o.relatedDummy ' , 'relatedDummy_a1 ' )->shouldBeCalled (1 );
656
685
$ queryBuilderProphecy ->addSelect ('partial relatedDummy_a1.{id,name} ' )->shouldBeCalled (1 );
686
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
687
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (2 );
657
688
658
689
$ request = Request::create ('/api/dummies ' , 'GET ' , []);
659
690
@@ -718,6 +749,8 @@ public function testAttributes()
718
749
719
750
$ queryBuilderProphecy ->leftJoin ('o.relatedDummy ' , 'relatedDummy_a1 ' )->shouldBeCalled (1 );
720
751
$ queryBuilderProphecy ->addSelect ('partial relatedDummy_a1.{id,name} ' )->shouldBeCalled (1 );
752
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
753
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (2 );
721
754
722
755
$ request = Request::create ('/api/dummies ' , 'GET ' , []);
723
756
@@ -759,6 +792,8 @@ public function testNotInAttributes()
759
792
760
793
$ queryBuilderProphecy ->getRootAliases ()->willReturn (['o ' ]);
761
794
$ queryBuilderProphecy ->getEntityManager ()->willReturn ($ emProphecy );
795
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
796
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (1 );
762
797
763
798
$ request = Request::create ('/api/dummies ' , 'GET ' , []);
764
799
@@ -808,6 +843,8 @@ public function testApplyToCollectionNoPartial()
808
843
$ queryBuilderProphecy ->innerJoin ('o.relatedDummy2 ' , 'relatedDummy2_a2 ' )->shouldBeCalled (1 );
809
844
$ queryBuilderProphecy ->addSelect ('relatedDummy_a1 ' )->shouldBeCalled (1 );
810
845
$ queryBuilderProphecy ->addSelect ('relatedDummy2_a2 ' )->shouldBeCalled (1 );
846
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
847
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (3 );
811
848
812
849
$ queryBuilder = $ queryBuilderProphecy ->reveal ();
813
850
$ eagerExtensionTest = new EagerLoadingExtension ($ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), 30 );
@@ -864,6 +901,8 @@ private function doTestApplyToCollectionWithANonRedableButFetchEagerProperty(boo
864
901
$ queryBuilderProphecy ->innerJoin ('o.relatedDummy2 ' , 'relatedDummy2_a2 ' )->shouldBeCalled (1 );
865
902
$ queryBuilderProphecy ->addSelect ('relatedDummy_a1 ' )->shouldBeCalled (1 );
866
903
$ queryBuilderProphecy ->addSelect ('relatedDummy2_a2 ' )->shouldBeCalled (1 );
904
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
905
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (3 );
867
906
868
907
$ queryBuilder = $ queryBuilderProphecy ->reveal ();
869
908
$ eagerExtensionTest = new EagerLoadingExtension ($ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), 30 );
@@ -918,6 +957,8 @@ private function doTestApplyToCollectionWithARedableButNotFetchEagerProperty(boo
918
957
$ queryBuilderProphecy ->innerJoin ('o.relatedDummy2 ' , 'relatedDummy2_a2 ' )->shouldNotBeCalled ();
919
958
$ queryBuilderProphecy ->addSelect ('relatedDummy_a1 ' )->shouldNotBeCalled ();
920
959
$ queryBuilderProphecy ->addSelect ('relatedDummy2_a2 ' )->shouldNotBeCalled ();
960
+ $ queryAbstractProphecy = $ this ->prophesize (AbstractQuery::class);
961
+ $ queryBuilderProphecy ->getQuery ()->willReturn ($ queryAbstractProphecy )->shouldBeCalledTimes (1 );
921
962
922
963
$ queryBuilder = $ queryBuilderProphecy ->reveal ();
923
964
$ eagerExtensionTest = new EagerLoadingExtension ($ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), 30 );
0 commit comments