@@ -358,7 +358,7 @@ public function testFetchEagerWithNoForceEager()
358
358
$ this ->assertEquals ($ this ->toDQLString ($ expected ), $ qb ->getDQL ());
359
359
}
360
360
361
- public function testCompositeIdentifiersWithoutAssociation ()
361
+ public function testCompositeIdentifiersWithAssociation ()
362
362
{
363
363
$ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
364
364
$ resourceMetadataFactoryProphecy ->create (CompositeRelation::class)->willReturn (new ResourceMetadata (CompositeRelation::class));
@@ -416,6 +416,48 @@ public function testCompositeIdentifiersWithoutAssociation()
416
416
$ this ->assertEquals ($ this ->toDQLString ($ expected ), $ qb ->getDQL ());
417
417
}
418
418
419
+ public function testCompositeIdentifiersWithoutAssociation ()
420
+ {
421
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
422
+ $ resourceMetadataFactoryProphecy ->create (CompositeRelation::class)->willReturn (new ResourceMetadata (CompositeRelation::class));
423
+
424
+ $ classMetadataProphecy = $ this ->prophesize (ClassMetadataInfo::class);
425
+ $ classMetadataProphecy ->getIdentifier ()->willReturn (['foo ' , 'bar ' ]);
426
+ $ classMetadataProphecy ->getAssociationMappings ()->willReturn (['item ' => ['fetch ' => ClassMetadataInfo::FETCH_EAGER ]]);
427
+ $ classMetadataProphecy ->hasAssociation ('foo ' )->shouldBeCalled ()->willReturn (false );
428
+ $ classMetadataProphecy ->hasAssociation ('bar ' )->shouldBeCalled ()->willReturn (false );
429
+
430
+ $ classMetadata = $ classMetadataProphecy ->reveal ();
431
+ $ classMetadata ->isIdentifierComposite = true ;
432
+
433
+ $ em = $ this ->prophesize (EntityManager::class);
434
+ $ em ->getClassMetadata (CompositeRelation::class)->shouldBeCalled ()->willReturn ($ classMetadata );
435
+
436
+ $ qb = new QueryBuilder ($ em ->reveal ());
437
+
438
+ $ qb ->select ('o ' )
439
+ ->from (CompositeRelation::class, 'o ' )
440
+ ->innerJoin ('o.compositeItem ' , 'item ' )
441
+ ->innerJoin ('o.compositeLabel ' , 'label ' )
442
+ ->where ('item.field1 = :foo AND o.bar = :bar ' )
443
+ ->setParameter ('foo ' , 1 )
444
+ ->setParameter ('bar ' , 2 );
445
+
446
+ $ queryNameGenerator = $ this ->prophesize (QueryNameGeneratorInterface::class);
447
+ $ filterEagerLoadingExtension = new FilterEagerLoadingExtension ($ resourceMetadataFactoryProphecy ->reveal (), true );
448
+ $ filterEagerLoadingExtension ->applyToCollection ($ qb , $ queryNameGenerator ->reveal (), CompositeRelation::class, 'get ' );
449
+
450
+ $ expected = <<<SQL
451
+ SELECT o
452
+ FROM ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\CompositeRelation o
453
+ INNER JOIN o.compositeItem item
454
+ INNER JOIN o.compositeLabel label
455
+ WHERE item.field1 = :foo AND o.bar = :bar
456
+ SQL ;
457
+
458
+ $ this ->assertEquals ($ this ->toDQLString ($ expected ), $ qb ->getDQL ());
459
+ }
460
+
419
461
private function toDQLString (string $ dql ): string
420
462
{
421
463
return preg_replace (['/\s+/ ' , '/\(\s/ ' , '/\s\)/ ' ], [' ' , '( ' , ') ' ], $ dql );
0 commit comments