@@ -143,6 +143,7 @@ public function testGetSubresource()
143
143
$ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
144
144
$ classMetadataProphecy ->getIdentifier ()->shouldBeCalled ()->willReturn ($ identifiers );
145
145
$ classMetadataProphecy ->getTypeOfField ('id ' )->shouldBeCalled ()->willReturn ('integer ' );
146
+ $ classMetadataProphecy ->hasAssociation ('relatedDummies ' )->willReturn (true )->shouldBeCalled ();
146
147
$ classMetadataProphecy ->getAssociationMapping ('relatedDummies ' )->shouldBeCalled ()->willReturn (['type ' => ClassMetadata::MANY_TO_MANY ]);
147
148
148
149
$ managerProphecy ->getClassMetadata (Dummy::class)->shouldBeCalled ()->willReturn ($ classMetadataProphecy ->reveal ());
@@ -202,6 +203,7 @@ public function testGetSubSubresourceItem()
202
203
$ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
203
204
$ classMetadataProphecy ->getIdentifier ()->shouldBeCalled ()->willReturn ($ identifiers );
204
205
$ classMetadataProphecy ->getTypeOfField ('id ' )->shouldBeCalled ()->willReturn ('integer ' );
206
+ $ classMetadataProphecy ->hasAssociation ('relatedDummies ' )->willReturn (true )->shouldBeCalled ();
205
207
$ classMetadataProphecy ->getAssociationMapping ('relatedDummies ' )->shouldBeCalled ()->willReturn (['type ' => ClassMetadata::MANY_TO_MANY ]);
206
208
207
209
$ dummyManagerProphecy = $ this ->prophesize (EntityManager::class);
@@ -229,6 +231,7 @@ public function testGetSubSubresourceItem()
229
231
$ rClassMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
230
232
$ rClassMetadataProphecy ->getIdentifier ()->shouldBeCalled ()->willReturn ($ identifiers );
231
233
$ rClassMetadataProphecy ->getTypeOfField ('id ' )->shouldBeCalled ()->willReturn ('integer ' );
234
+ $ rClassMetadataProphecy ->hasAssociation ('thirdLevel ' )->shouldBeCalled ()->willReturn (true );
232
235
$ rClassMetadataProphecy ->getAssociationMapping ('thirdLevel ' )->shouldBeCalled ()->willReturn (['type ' => ClassMetadata::MANY_TO_ONE ]);
233
236
234
237
$ rDummyManagerProphecy = $ this ->prophesize (EntityManager::class);
@@ -290,6 +293,7 @@ public function testQueryResultExtension()
290
293
$ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
291
294
$ classMetadataProphecy ->getIdentifier ()->shouldBeCalled ()->willReturn ($ identifiers );
292
295
$ classMetadataProphecy ->getTypeOfField ('id ' )->shouldBeCalled ()->willReturn ('integer ' );
296
+ $ classMetadataProphecy ->hasAssociation ('relatedDummies ' )->willReturn (true )->shouldBeCalled ();
293
297
$ classMetadataProphecy ->getAssociationMapping ('relatedDummies ' )->shouldBeCalled ()->willReturn (['type ' => ClassMetadata::MANY_TO_MANY ]);
294
298
295
299
$ managerProphecy ->getClassMetadata (Dummy::class)->shouldBeCalled ()->willReturn ($ classMetadataProphecy ->reveal ());
@@ -363,4 +367,96 @@ public function testThrowResourceClassNotSupportedException()
363
367
$ dataProvider = new SubresourceDataProvider ($ managerRegistryProphecy ->reveal (), $ propertyNameCollectionFactory , $ propertyMetadataFactory );
364
368
$ dataProvider ->getSubresource (Dummy::class, ['id ' => 1 ], []);
365
369
}
370
+
371
+ public function testGetSubresourceCollectionItem ()
372
+ {
373
+ $ managerRegistryProphecy = $ this ->prophesize (ManagerRegistry::class);
374
+ $ identifiers = ['id ' ];
375
+ $ funcProphecy = $ this ->prophesize (Func::class);
376
+ $ func = $ funcProphecy ->reveal ();
377
+
378
+ // First manager (Dummy)
379
+ $ dummyDQL = 'dql ' ;
380
+
381
+ $ qb = $ this ->prophesize (QueryBuilder::class);
382
+ $ qb ->select ('relatedDummies_a3 ' )->shouldBeCalled ()->willReturn ($ qb );
383
+ $ qb ->from (Dummy::class, 'id_a2 ' )->shouldBeCalled ()->willReturn ($ qb );
384
+ $ qb ->innerJoin ('id_a2.relatedDummies ' , 'relatedDummies_a3 ' )->shouldBeCalled ()->willReturn ($ qb );
385
+ $ qb ->andWhere ('id_a2.id = :id_p2 ' )->shouldBeCalled ()->willReturn ($ qb );
386
+
387
+ $ dummyFunc = new Func ('in ' , ['any ' ]);
388
+
389
+ $ dummyExpProphecy = $ this ->prophesize (Expr::class);
390
+ $ dummyExpProphecy ->in ('relatedDummies_a1 ' , $ dummyDQL )->willReturn ($ dummyFunc )->shouldBeCalled ();
391
+
392
+ $ qb ->expr ()->shouldBeCalled ()->willReturn ($ dummyExpProphecy ->reveal ());
393
+
394
+ $ qb ->getDQL ()->shouldBeCalled ()->willReturn ($ dummyDQL );
395
+
396
+ $ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
397
+ $ classMetadataProphecy ->getIdentifier ()->shouldBeCalled ()->willReturn ($ identifiers );
398
+ $ classMetadataProphecy ->getTypeOfField ('id ' )->shouldBeCalled ()->willReturn ('integer ' );
399
+ $ classMetadataProphecy ->hasAssociation ('relatedDummies ' )->willReturn (true )->shouldBeCalled ();
400
+ $ classMetadataProphecy ->getAssociationMapping ('relatedDummies ' )->shouldBeCalled ()->willReturn (['type ' => ClassMetadata::MANY_TO_MANY ]);
401
+
402
+ $ dummyManagerProphecy = $ this ->prophesize (EntityManager::class);
403
+ $ dummyManagerProphecy ->createQueryBuilder ()->shouldBeCalled ()->willReturn ($ qb ->reveal ());
404
+ $ dummyManagerProphecy ->getClassMetadata (Dummy::class)->shouldBeCalled ()->willReturn ($ classMetadataProphecy ->reveal ());
405
+ $ this ->assertIdentifierManagerMethodCalls ($ dummyManagerProphecy );
406
+
407
+ $ managerRegistryProphecy ->getManagerForClass (Dummy::class)->shouldBeCalled ()->willReturn ($ dummyManagerProphecy ->reveal ());
408
+
409
+ // Second manager (RelatedDummy)
410
+ $ relatedDQL = 'relateddql ' ;
411
+
412
+ $ rqb = $ this ->prophesize (QueryBuilder::class);
413
+ $ rqb ->select ('relatedDummies_a1 ' )->shouldBeCalled ()->willReturn ($ rqb );
414
+ $ rqb ->from (RelatedDummy::class, 'relatedDummies_a1 ' )->shouldBeCalled ()->willReturn ($ rqb );
415
+ $ rqb ->andWhere ('relatedDummies_a1.id = :id_p1 ' )->shouldBeCalled ()->willReturn ($ rqb );
416
+ $ rqb ->andWhere ($ dummyFunc )->shouldBeCalled ()->willReturn ($ rqb );
417
+ $ rqb ->getDQL ()->shouldBeCalled ()->willReturn ($ relatedDQL );
418
+
419
+ $ relatedExpProphecy = $ this ->prophesize (Expr::class);
420
+ $ relatedExpProphecy ->in ('o ' , $ relatedDQL )->willReturn ($ func )->shouldBeCalled ();
421
+
422
+ $ rqb ->expr ()->shouldBeCalled ()->willReturn ($ relatedExpProphecy ->reveal ());
423
+
424
+ $ rClassMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
425
+ $ rClassMetadataProphecy ->getIdentifier ()->shouldBeCalled ()->willReturn ($ identifiers );
426
+ $ rClassMetadataProphecy ->getTypeOfField ('id ' )->shouldBeCalled ()->willReturn ('integer ' );
427
+ $ rClassMetadataProphecy ->hasAssociation ('id ' )->shouldBeCalled ()->willReturn (false );
428
+ $ rClassMetadataProphecy ->isIdentifier ('id ' )->shouldBeCalled ()->willReturn (true );
429
+
430
+ $ rDummyManagerProphecy = $ this ->prophesize (EntityManager::class);
431
+ $ rDummyManagerProphecy ->createQueryBuilder ()->shouldBeCalled ()->willReturn ($ rqb ->reveal ());
432
+ $ rDummyManagerProphecy ->getClassMetadata (RelatedDummy::class)->shouldBeCalled ()->willReturn ($ rClassMetadataProphecy ->reveal ());
433
+ $ this ->assertIdentifierManagerMethodCalls ($ rDummyManagerProphecy );
434
+
435
+ $ managerRegistryProphecy ->getManagerForClass (RelatedDummy::class)->shouldBeCalled ()->willReturn ($ rDummyManagerProphecy ->reveal ());
436
+
437
+ $ result = new \StdClass ();
438
+ $ queryProphecy = $ this ->prophesize (AbstractQuery::class);
439
+ $ queryProphecy ->getOneOrNullResult ()->shouldBeCalled ()->willReturn ($ result );
440
+
441
+ $ queryBuilder = $ this ->prophesize (QueryBuilder::class);
442
+
443
+ $ queryBuilder ->andWhere ($ func )->shouldBeCalled ()->willReturn ($ queryBuilder );
444
+
445
+ $ queryBuilder ->getQuery ()->shouldBeCalled ()->willReturn ($ queryProphecy ->reveal ());
446
+ $ queryBuilder ->setParameter ('id_p1 ' , 2 )->shouldBeCalled ()->willReturn ($ queryBuilder );
447
+ $ queryBuilder ->setParameter ('id_p2 ' , 1 )->shouldBeCalled ()->willReturn ($ queryBuilder );
448
+
449
+ $ repositoryProphecy = $ this ->prophesize (EntityRepository::class);
450
+ $ repositoryProphecy ->createQueryBuilder ('o ' )->shouldBeCalled ()->willReturn ($ queryBuilder ->reveal ());
451
+
452
+ $ rDummyManagerProphecy ->getRepository (RelatedDummy::class)->shouldBeCalled ()->willReturn ($ repositoryProphecy ->reveal ());
453
+
454
+ list ($ propertyNameCollectionFactory , $ propertyMetadataFactory ) = $ this ->getMetadataProphecies ([Dummy::class => $ identifiers , RelatedDummy::class => $ identifiers ]);
455
+
456
+ $ dataProvider = new SubresourceDataProvider ($ managerRegistryProphecy ->reveal (), $ propertyNameCollectionFactory , $ propertyMetadataFactory );
457
+
458
+ $ context = ['property ' => 'id ' , 'identifiers ' => [['id ' , Dummy::class, true ], ['relatedDummies ' , RelatedDummy::class, true ]], 'collection ' => false ];
459
+
460
+ $ this ->assertEquals ($ result , $ dataProvider ->getSubresource (RelatedDummy::class, ['id ' => 1 , 'relatedDummies ' => 2 ], $ context ));
461
+ }
366
462
}
0 commit comments