32
32
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \UnknownDummy ;
33
33
use Doctrine \ORM \EntityManager ;
34
34
use Doctrine \ORM \Mapping \ClassMetadata ;
35
+ use Doctrine \ORM \Mapping \ClassMetadataInfo ;
35
36
use Doctrine \ORM \QueryBuilder ;
36
37
use PHPUnit \Framework \TestCase ;
37
38
use Prophecy \Argument ;
@@ -89,8 +90,8 @@ public function testApplyToCollection()
89
90
90
91
$ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
91
92
$ classMetadataProphecy ->associationMappings = [
92
- 'relatedDummy ' => ['fetch ' => 3 , 'joinColumns ' => [['nullable ' => true ]], 'targetEntity ' => RelatedDummy::class],
93
- 'relatedDummy2 ' => ['fetch ' => 3 , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => RelatedDummy::class],
93
+ 'relatedDummy ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'joinColumns ' => [['nullable ' => true ]], 'targetEntity ' => RelatedDummy::class],
94
+ 'relatedDummy2 ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => RelatedDummy::class],
94
95
];
95
96
96
97
$ relatedClassMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
@@ -171,12 +172,12 @@ public function testApplyToItem()
171
172
172
173
$ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
173
174
$ classMetadataProphecy ->associationMappings = [
174
- 'relatedDummy ' => ['fetch ' => 3 , 'joinColumns ' => [['nullable ' => true ]], 'targetEntity ' => RelatedDummy::class],
175
- 'relatedDummy2 ' => ['fetch ' => 3 , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => UnknownDummy::class],
176
- 'relatedDummy3 ' => ['fetch ' => 3 , 'joinTable ' => ['joinColumns ' => [['nullable ' => false ]]], 'targetEntity ' => UnknownDummy::class],
177
- 'relatedDummy4 ' => ['fetch ' => 3 , 'targetEntity ' => UnknownDummy::class],
178
- 'relatedDummy5 ' => ['fetch ' => 2 , 'targetEntity ' => UnknownDummy::class],
179
- 'singleInheritanceRelation ' => ['fetch ' => 3 , 'targetEntity ' => AbstractDummy::class],
175
+ 'relatedDummy ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'joinColumns ' => [['nullable ' => true ]], 'targetEntity ' => RelatedDummy::class],
176
+ 'relatedDummy2 ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => UnknownDummy::class],
177
+ 'relatedDummy3 ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'joinTable ' => ['joinColumns ' => [['nullable ' => false ]]], 'targetEntity ' => UnknownDummy::class],
178
+ 'relatedDummy4 ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'targetEntity ' => UnknownDummy::class],
179
+ 'relatedDummy5 ' => ['fetch ' => ClassMetadataInfo:: FETCH_LAZY , 'targetEntity ' => UnknownDummy::class],
180
+ 'singleInheritanceRelation ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'targetEntity ' => AbstractDummy::class],
180
181
];
181
182
182
183
$ relatedClassMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
@@ -189,7 +190,7 @@ public function testApplyToItem()
189
190
$ relatedClassMetadataProphecy ->hasField ('embeddedDummy.name ' )->willReturn (true )->shouldBeCalled ();
190
191
191
192
$ relatedClassMetadataProphecy ->associationMappings = [
192
- 'relation ' => ['fetch ' => 3 , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => UnknownDummy::class],
193
+ 'relation ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => UnknownDummy::class],
193
194
];
194
195
195
196
$ relatedClassMetadataProphecy ->embeddedClasses = ['embeddedDummy ' => ['class ' => EmbeddableDummy::class]];
@@ -349,12 +350,12 @@ public function testMaxJoinsReached()
349
350
350
351
$ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
351
352
$ classMetadataProphecy ->associationMappings = [
352
- 'relatedDummy ' => ['fetch ' => 3 , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => RelatedDummy::class],
353
+ 'relatedDummy ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => RelatedDummy::class],
353
354
];
354
355
355
356
$ relatedClassMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
356
357
$ relatedClassMetadataProphecy ->associationMappings = [
357
- 'dummy ' => ['fetch ' => 3 , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => Dummy::class],
358
+ 'dummy ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => Dummy::class],
358
359
];
359
360
360
361
$ emProphecy = $ this ->prophesize (EntityManager::class);
@@ -401,12 +402,12 @@ public function testMaxDepth()
401
402
402
403
$ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
403
404
$ classMetadataProphecy ->associationMappings = [
404
- 'relatedDummy ' => ['fetch ' => 3 , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => RelatedDummy::class],
405
+ 'relatedDummy ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => RelatedDummy::class],
405
406
];
406
407
407
408
$ relatedClassMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
408
409
$ relatedClassMetadataProphecy ->associationMappings = [
409
- 'dummy ' => ['fetch ' => 3 , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => Dummy::class],
410
+ 'dummy ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => Dummy::class],
410
411
];
411
412
412
413
$ dummyClassMetadataInterfaceProphecy = $ this ->prophesize (ClassMetadataInterface::class);
@@ -464,7 +465,7 @@ public function testForceEager()
464
465
465
466
$ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
466
467
$ classMetadataProphecy ->associationMappings = [
467
- 'relation ' => ['fetch ' => 2 , 'targetEntity ' => UnknownDummy::class, 'joinColumns ' => [['nullable ' => false ]]],
468
+ 'relation ' => ['fetch ' => ClassMetadataInfo:: FETCH_LAZY , 'targetEntity ' => UnknownDummy::class, 'joinColumns ' => [['nullable ' => false ]]],
468
469
];
469
470
470
471
$ unknownClassMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
@@ -484,6 +485,42 @@ public function testForceEager()
484
485
$ orderExtensionTest ->applyToItem ($ queryBuilderProphecy ->reveal (), new QueryNameGenerator (), Dummy::class, []);
485
486
}
486
487
488
+ public function testExtraLazy ()
489
+ {
490
+ $ resourceMetadata = new ResourceMetadata ();
491
+ $ resourceMetadata = $ resourceMetadata ->withAttributes (['normalization_context ' => [AbstractNormalizer::GROUPS => 'foobar ' ]]);
492
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
493
+ $ resourceMetadataFactoryProphecy ->create (Dummy::class)->willReturn ($ resourceMetadata );
494
+
495
+ $ propertyNameCollectionFactoryProphecy = $ this ->prophesize (PropertyNameCollectionFactoryInterface::class);
496
+ //$propertyNameCollectionFactoryProphecy->create(UnknownDummy::class)->willReturn(new PropertyNameCollection(['id']))->shouldBeCalled();
497
+
498
+ $ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
499
+ $ relationPropertyMetadata = new PropertyMetadata ();
500
+ $ relationPropertyMetadata = $ relationPropertyMetadata ->withReadableLink (true );
501
+
502
+ $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'relation ' , ['serializer_groups ' => 'foobar ' ])->willReturn ($ relationPropertyMetadata )->shouldBeCalled ();
503
+
504
+ $ queryBuilderProphecy = $ this ->prophesize (QueryBuilder::class);
505
+
506
+ $ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
507
+ $ classMetadataProphecy ->associationMappings = [
508
+ 'relation ' => ['fetch ' => ClassMetadataInfo::FETCH_EXTRA_LAZY , 'targetEntity ' => UnknownDummy::class, 'joinColumns ' => [['nullable ' => false ]]],
509
+ ];
510
+
511
+ $ unknownClassMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
512
+ $ unknownClassMetadataProphecy ->associationMappings = [];
513
+
514
+ $ emProphecy = $ this ->prophesize (EntityManager::class);
515
+ $ emProphecy ->getClassMetadata (Dummy::class)->shouldBeCalled ()->willReturn ($ classMetadataProphecy ->reveal ());
516
+
517
+ $ queryBuilderProphecy ->getRootAliases ()->willReturn (['o ' ]);
518
+ $ queryBuilderProphecy ->getEntityManager ()->willReturn ($ emProphecy );
519
+
520
+ $ orderExtensionTest = new EagerLoadingExtension ($ propertyNameCollectionFactoryProphecy ->reveal (), $ propertyMetadataFactoryProphecy ->reveal (), $ resourceMetadataFactoryProphecy ->reveal (), 30 , true , null , null , true );
521
+ $ orderExtensionTest ->applyToItem ($ queryBuilderProphecy ->reveal (), new QueryNameGenerator (), Dummy::class, []);
522
+ }
523
+
487
524
public function testResourceClassNotFoundException ()
488
525
{
489
526
$ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
@@ -496,7 +533,7 @@ public function testResourceClassNotFoundException()
496
533
497
534
$ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
498
535
$ classMetadataProphecy ->associationMappings = [
499
- 'relation ' => ['fetch ' => 2 , 'targetEntity ' => UnknownDummy::class, 'joinColumns ' => [['nullable ' => false ]]],
536
+ 'relation ' => ['fetch ' => ClassMetadataInfo:: FETCH_LAZY , 'targetEntity ' => UnknownDummy::class, 'joinColumns ' => [['nullable ' => false ]]],
500
537
];
501
538
$ emProphecy = $ this ->prophesize (EntityManager::class);
502
539
$ emProphecy ->getClassMetadata (Dummy::class)->shouldBeCalled ()->willReturn ($ classMetadataProphecy ->reveal ());
@@ -520,7 +557,7 @@ public function testPropertyNotFoundException()
520
557
521
558
$ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
522
559
$ classMetadataProphecy ->associationMappings = [
523
- 'relation ' => ['fetch ' => 2 , 'targetEntity ' => UnknownDummy::class, 'joinColumns ' => [['nullable ' => false ]]],
560
+ 'relation ' => ['fetch ' => ClassMetadataInfo:: FETCH_LAZY , 'targetEntity ' => UnknownDummy::class, 'joinColumns ' => [['nullable ' => false ]]],
524
561
];
525
562
$ emProphecy = $ this ->prophesize (EntityManager::class);
526
563
$ emProphecy ->getClassMetadata (Dummy::class)->shouldBeCalled ()->willReturn ($ classMetadataProphecy ->reveal ());
@@ -547,7 +584,7 @@ public function testResourceClassNotFoundExceptionPropertyNameCollection()
547
584
548
585
$ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
549
586
$ classMetadataProphecy ->associationMappings = [
550
- 'relation ' => ['fetch ' => 2 , 'targetEntity ' => UnknownDummy::class, 'joinColumns ' => [['nullable ' => false ]]],
587
+ 'relation ' => ['fetch ' => ClassMetadataInfo:: FETCH_LAZY , 'targetEntity ' => UnknownDummy::class, 'joinColumns ' => [['nullable ' => false ]]],
551
588
];
552
589
$ emProphecy = $ this ->prophesize (EntityManager::class);
553
590
$ emProphecy ->getClassMetadata (Dummy::class)->shouldBeCalled ()->willReturn ($ classMetadataProphecy ->reveal ());
@@ -589,7 +626,7 @@ public function testApplyToCollectionWithSerializerContextBuilder()
589
626
590
627
$ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
591
628
$ classMetadataProphecy ->associationMappings = [
592
- 'relatedDummy ' => ['fetch ' => 3 , 'joinColumns ' => [['nullable ' => true ]], 'targetEntity ' => RelatedDummy::class],
629
+ 'relatedDummy ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'joinColumns ' => [['nullable ' => true ]], 'targetEntity ' => RelatedDummy::class],
593
630
];
594
631
595
632
$ relatedClassMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
@@ -653,7 +690,7 @@ public function testAttributes()
653
690
654
691
$ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
655
692
$ classMetadataProphecy ->associationMappings = [
656
- 'relatedDummy ' => ['fetch ' => 3 , 'joinColumns ' => [['nullable ' => true ]], 'targetEntity ' => RelatedDummy::class],
693
+ 'relatedDummy ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'joinColumns ' => [['nullable ' => true ]], 'targetEntity ' => RelatedDummy::class],
657
694
];
658
695
659
696
$ relatedClassMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
@@ -707,8 +744,8 @@ public function testApplyToCollectionNoPartial()
707
744
708
745
$ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
709
746
$ classMetadataProphecy ->associationMappings = [
710
- 'relatedDummy ' => ['fetch ' => 3 , 'joinColumns ' => [['nullable ' => true ]], 'targetEntity ' => RelatedDummy::class],
711
- 'relatedDummy2 ' => ['fetch ' => 3 , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => RelatedDummy::class],
747
+ 'relatedDummy ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'joinColumns ' => [['nullable ' => true ]], 'targetEntity ' => RelatedDummy::class],
748
+ 'relatedDummy2 ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => RelatedDummy::class],
712
749
];
713
750
714
751
$ emProphecy = $ this ->prophesize (EntityManager::class);
@@ -750,8 +787,8 @@ public function testApplyToCollectionWithANonRedableButFetchEagerProperty()
750
787
751
788
$ classMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
752
789
$ classMetadataProphecy ->associationMappings = [
753
- 'relatedDummy ' => ['fetch ' => 3 , 'joinColumns ' => [['nullable ' => true ]], 'targetEntity ' => RelatedDummy::class],
754
- 'relatedDummy2 ' => ['fetch ' => 3 , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => RelatedDummy::class],
790
+ 'relatedDummy ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'joinColumns ' => [['nullable ' => true ]], 'targetEntity ' => RelatedDummy::class],
791
+ 'relatedDummy2 ' => ['fetch ' => ClassMetadataInfo:: FETCH_EAGER , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => RelatedDummy::class],
755
792
];
756
793
757
794
$ emProphecy = $ this ->prophesize (EntityManager::class);
0 commit comments