@@ -773,6 +773,72 @@ public function testNotInAttributes()
773
773
$ eagerExtensionTest ->applyToCollection ($ queryBuilder , new QueryNameGenerator (), Dummy::class);
774
774
}
775
775
776
+ public function testOnlyOneRelationNotInAttributes ()
777
+ {
778
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
779
+ $ resourceMetadataFactoryProphecy ->create (Dummy::class)->willReturn (new ResourceMetadata ());
780
+
781
+ $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
782
+
783
+ $ relatedNameCollection = new PropertyNameCollection (['id ' , 'name ' ]);
784
+ $ propertyNameCollectionFactoryProphecy ->create (RelatedDummy::class)->willReturn ($ relatedNameCollection )->shouldBeCalled ();
785
+
786
+ $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
787
+ $ relationPropertyMetadata = new PropertyMetadata ();
788
+ $ relationPropertyMetadata = $ relationPropertyMetadata ->withReadableLink (false );
789
+
790
+ $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'relatedDummies ' , ['serializer_groups ' => ['foo ' ]])->willReturn ($ relationPropertyMetadata )->shouldBeCalled ();
791
+ $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'relatedDummy ' , ['serializer_groups ' => ['foo ' ]])->willReturn ($ relationPropertyMetadata )->shouldBeCalled ();
792
+
793
+ $ idPropertyMetadata = new PropertyMetadata ();
794
+ $ idPropertyMetadata = $ idPropertyMetadata ->withIdentifier (true );
795
+ $ namePropertyMetadata = new PropertyMetadata ();
796
+ $ namePropertyMetadata = $ namePropertyMetadata ->withReadable (true );
797
+
798
+ $ propertyMetadataFactoryProphecy ->create (RelatedDummy::class, 'id ' , ['serializer_groups ' => ['foo ' ]])->willReturn ($ idPropertyMetadata )->shouldBeCalled ();
799
+ $ propertyMetadataFactoryProphecy ->create (RelatedDummy::class, 'name ' , ['serializer_groups ' => ['foo ' ]])->willReturn ($ namePropertyMetadata )->shouldBeCalled ();
800
+
801
+ $ queryBuilderProphecy = $ this ->prophesize (QueryBuilder::class);
802
+
803
+ $ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
804
+ $ classMetadataProphecy ->associationMappings = [
805
+ 'relatedDummies ' => ['fetch ' => ClassMetadataInfo::FETCH_EAGER , 'joinColumns ' => [['nullable ' => true ]], 'targetEntity ' => RelatedDummy::class],
806
+ 'relatedDummy ' => ['fetch ' => ClassMetadataInfo::FETCH_EAGER , 'joinColumns ' => [['nullable ' => true ]], 'targetEntity ' => RelatedDummy::class],
807
+ ];
808
+
809
+ $ relatedClassMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
810
+
811
+ foreach ($ relatedNameCollection as $ property ) {
812
+ if ('id ' !== $ property ) {
813
+ $ relatedClassMetadataProphecy ->hasField ($ property )->willReturn (true )->shouldBeCalled ();
814
+ }
815
+ }
816
+
817
+ $ relatedClassMetadataProphecy ->associationMappings = [];
818
+
819
+ $ emProphecy = $ this ->prophesize (EntityManager::class);
820
+ $ emProphecy ->getClassMetadata (Dummy::class)->shouldBeCalled ()->willReturn ($ classMetadataProphecy ->reveal ());
821
+ $ emProphecy ->getClassMetadata (RelatedDummy::class)->shouldBeCalled ()->willReturn ($ relatedClassMetadataProphecy ->reveal ());
822
+
823
+ $ queryBuilderProphecy ->getRootAliases ()->willReturn (['o ' ]);
824
+ $ queryBuilderProphecy ->getEntityManager ()->willReturn ($ emProphecy );
825
+
826
+ $ queryBuilderProphecy ->leftJoin ('o.relatedDummy ' , 'relatedDummy_a1 ' )->shouldBeCalled (1 );
827
+ $ queryBuilderProphecy ->addSelect ('partial relatedDummy_a1.{id,name} ' )->shouldBeCalled (1 );
828
+
829
+ $ request = Request::create ('/api/dummies ' , 'GET ' , []);
830
+
831
+ $ requestStack = new RequestStack ();
832
+ $ requestStack ->push ($ request );
833
+
834
+ $ serializerContextBuilderProphecy = $ this ->prophesize (SerializerContextBuilderInterface::class);
835
+ $ serializerContextBuilderProphecy ->createFromRequest ($ request , true )->shouldBeCalled ()->willReturn ([AbstractNormalizer::GROUPS => ['foo ' ], AbstractNormalizer::ATTRIBUTES => ['relatedDummy ' => ['id ' , 'name ' ]]]);
836
+
837
+ $ queryBuilder = $ queryBuilderProphecy ->reveal ();
838
+ $ eagerExtensionTest = new EagerLoadingExtension ($ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), 30 , false , $ requestStack , $ serializerContextBuilderProphecy ->reveal (), true );
839
+ $ eagerExtensionTest ->applyToCollection ($ queryBuilder , new QueryNameGenerator (), Dummy::class);
840
+ }
841
+
776
842
public function testApplyToCollectionNoPartial ()
777
843
{
778
844
$ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
0 commit comments