29
29
use ApiPlatform \Tests \Fixtures \TestBundle \Entity \Dummy ;
30
30
use ApiPlatform \Tests \Fixtures \TestBundle \Entity \EmbeddableDummy ;
31
31
use ApiPlatform \Tests \Fixtures \TestBundle \Entity \RelatedDummy ;
32
+ use ApiPlatform \Tests \Fixtures \TestBundle \Entity \ThirdLevel ;
32
33
use ApiPlatform \Tests \Fixtures \TestBundle \Entity \UnknownDummy ;
33
34
use Doctrine \ORM \EntityManager ;
34
35
use Doctrine \ORM \Mapping \ClassMetadata ;
@@ -140,6 +141,7 @@ public function testApplyToItem(): void
140
141
$ propertyNameCollectionFactoryProphecy ->create (RelatedDummy::class)->willReturn ($ relatedNameCollection )->shouldBeCalled ();
141
142
$ propertyNameCollectionFactoryProphecy ->create (EmbeddableDummy::class)->willReturn ($ relatedEmbedableCollection )->shouldBeCalled ();
142
143
$ propertyNameCollectionFactoryProphecy ->create (UnknownDummy::class)->willReturn (new PropertyNameCollection (['id ' ]))->shouldBeCalled ();
144
+ $ propertyNameCollectionFactoryProphecy ->create (ThirdLevel::class)->willReturn (new PropertyNameCollection (['id ' ]))->shouldBeCalled ();
143
145
144
146
$ propertyMetadataFactoryProphecy = $ this ->prophesize (PropertyMetadataFactoryInterface::class);
145
147
$ relationPropertyMetadata = new ApiProperty ();
@@ -151,6 +153,7 @@ public function testApplyToItem(): void
151
153
$ propertyMetadataFactoryProphecy ->create (Dummy::class, 'relatedDummy4 ' , $ callContext )->willReturn ($ relationPropertyMetadata )->shouldBeCalled ();
152
154
$ propertyMetadataFactoryProphecy ->create (Dummy::class, 'relatedDummy5 ' , $ callContext )->willReturn ($ relationPropertyMetadata )->shouldBeCalled ();
153
155
$ propertyMetadataFactoryProphecy ->create (Dummy::class, 'singleInheritanceRelation ' , $ callContext )->willReturn ($ relationPropertyMetadata )->shouldBeCalled ();
156
+ $ propertyMetadataFactoryProphecy ->create (Dummy::class, 'relatedDummies ' , $ callContext )->willReturn ($ relationPropertyMetadata )->shouldBeCalled ();
154
157
155
158
$ idPropertyMetadata = new ApiProperty ();
156
159
$ idPropertyMetadata = $ idPropertyMetadata ->withIdentifier (true );
@@ -169,7 +172,9 @@ public function testApplyToItem(): void
169
172
$ propertyMetadataFactoryProphecy ->create (RelatedDummy::class, 'notindatabase ' , $ callContext )->willReturn ($ notInDatabasePropertyMetadata )->shouldBeCalled ();
170
173
$ propertyMetadataFactoryProphecy ->create (RelatedDummy::class, 'notreadable ' , $ callContext )->willReturn ($ notReadablePropertyMetadata )->shouldBeCalled ();
171
174
$ propertyMetadataFactoryProphecy ->create (RelatedDummy::class, 'relation ' , $ callContext )->willReturn ($ relationPropertyMetadata )->shouldBeCalled ();
175
+ $ propertyMetadataFactoryProphecy ->create (RelatedDummy::class, 'thirdLevel ' , $ callContext )->willReturn ($ relationPropertyMetadata )->shouldBeCalled ();
172
176
$ propertyMetadataFactoryProphecy ->create (UnknownDummy::class, 'id ' , $ callContext )->willReturn ($ idPropertyMetadata )->shouldBeCalled ();
177
+ $ propertyMetadataFactoryProphecy ->create (ThirdLevel::class, 'id ' , $ callContext )->willReturn ($ idPropertyMetadata )->shouldBeCalled ();
173
178
174
179
$ queryBuilderProphecy = $ this ->prophesize (QueryBuilder::class);
175
180
@@ -181,6 +186,7 @@ public function testApplyToItem(): void
181
186
'relatedDummy4 ' => ['fetch ' => ClassMetadataInfo::FETCH_EAGER , 'targetEntity ' => UnknownDummy::class],
182
187
'relatedDummy5 ' => ['fetch ' => ClassMetadataInfo::FETCH_LAZY , 'targetEntity ' => UnknownDummy::class],
183
188
'singleInheritanceRelation ' => ['fetch ' => ClassMetadataInfo::FETCH_EAGER , 'targetEntity ' => AbstractDummy::class],
189
+ 'relatedDummies ' => ['fetch ' => ClassMetadataInfo::FETCH_EAGER , 'targetEntity ' => RelatedDummy::class],
184
190
];
185
191
186
192
$ relatedClassMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
@@ -194,6 +200,7 @@ public function testApplyToItem(): void
194
200
195
201
$ relatedClassMetadataProphecy ->associationMappings = [
196
202
'relation ' => ['fetch ' => ClassMetadataInfo::FETCH_EAGER , 'joinColumns ' => [['nullable ' => false ]], 'targetEntity ' => UnknownDummy::class],
203
+ 'thirdLevel ' => ['fetch ' => ClassMetadataInfo::FETCH_EAGER , 'targetEntity ' => ThirdLevel::class, 'sourceEntity ' => RelatedDummy::class, 'inversedBy ' => 'relatedDummies ' , 'type ' => ClassMetadata::TO_ONE ],
197
204
];
198
205
199
206
$ relatedClassMetadataProphecy ->embeddedClasses = ['embeddedDummy ' => ['class ' => EmbeddableDummy::class]];
@@ -204,26 +211,38 @@ public function testApplyToItem(): void
204
211
$ unknownClassMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
205
212
$ unknownClassMetadataProphecy ->associationMappings = [];
206
213
214
+ $ thirdLevelMetadataProphecy = $ this ->prophesize (ClassMetadata::class);
215
+ $ thirdLevelMetadataProphecy ->associationMappings = [];
216
+
207
217
$ emProphecy = $ this ->prophesize (EntityManager::class);
208
218
$ emProphecy ->getClassMetadata (Dummy::class)->shouldBeCalled ()->willReturn ($ classMetadataProphecy ->reveal ());
209
219
$ emProphecy ->getClassMetadata (RelatedDummy::class)->shouldBeCalled ()->willReturn ($ relatedClassMetadataProphecy ->reveal ());
210
220
$ emProphecy ->getClassMetadata (AbstractDummy::class)->shouldBeCalled ()->willReturn ($ singleInheritanceClassMetadataProphecy ->reveal ());
211
221
$ emProphecy ->getClassMetadata (UnknownDummy::class)->shouldBeCalled ()->willReturn ($ unknownClassMetadataProphecy ->reveal ());
222
+ $ emProphecy ->getClassMetadata (ThirdLevel::class)->shouldBeCalled ()->willReturn ($ thirdLevelMetadataProphecy ->reveal ());
212
223
213
224
$ queryBuilderProphecy ->getRootAliases ()->willReturn (['o ' ]);
214
225
$ queryBuilderProphecy ->getEntityManager ()->willReturn ($ emProphecy );
215
226
$ queryBuilderProphecy ->leftJoin ('o.relatedDummy ' , 'relatedDummy_a1 ' )->shouldBeCalledTimes (1 );
216
227
$ queryBuilderProphecy ->leftJoin ('relatedDummy_a1.relation ' , 'relation_a2 ' )->shouldBeCalledTimes (1 );
217
- $ queryBuilderProphecy ->innerJoin ('o.relatedDummy2 ' , 'relatedDummy2_a3 ' )->shouldBeCalledTimes (1 );
218
- $ queryBuilderProphecy ->leftJoin ('o.relatedDummy3 ' , 'relatedDummy3_a4 ' )->shouldBeCalledTimes (1 );
219
- $ queryBuilderProphecy ->leftJoin ('o.relatedDummy4 ' , 'relatedDummy4_a5 ' )->shouldBeCalledTimes (1 );
220
- $ queryBuilderProphecy ->leftJoin ('o.singleInheritanceRelation ' , 'singleInheritanceRelation_a6 ' )->shouldBeCalledTimes (1 );
228
+ $ queryBuilderProphecy ->leftJoin ('relatedDummy_a1.thirdLevel ' , 'thirdLevel_a3 ' )->shouldBeCalledTimes (1 );
229
+ $ queryBuilderProphecy ->innerJoin ('o.relatedDummy2 ' , 'relatedDummy2_a4 ' )->shouldBeCalledTimes (1 );
230
+ $ queryBuilderProphecy ->leftJoin ('o.relatedDummy3 ' , 'relatedDummy3_a5 ' )->shouldBeCalledTimes (1 );
231
+ $ queryBuilderProphecy ->leftJoin ('o.relatedDummy4 ' , 'relatedDummy4_a6 ' )->shouldBeCalledTimes (1 );
232
+ $ queryBuilderProphecy ->leftJoin ('o.singleInheritanceRelation ' , 'singleInheritanceRelation_a7 ' )->shouldBeCalledTimes (1 );
233
+ $ queryBuilderProphecy ->leftJoin ('o.relatedDummies ' , 'relatedDummies_a8 ' )->shouldBeCalledTimes (1 );
234
+ $ queryBuilderProphecy ->leftJoin ('relatedDummies_a8.relation ' , 'relation_a9 ' )->shouldBeCalledTimes (1 );
235
+ $ queryBuilderProphecy ->leftJoin ('relatedDummies_a8.thirdLevel ' , 'thirdLevel_a10 ' )->shouldBeCalledTimes (1 );
221
236
$ queryBuilderProphecy ->addSelect ('partial relatedDummy_a1.{id,name,embeddedDummy.name} ' )->shouldBeCalledTimes (1 );
237
+ $ queryBuilderProphecy ->addSelect ('partial thirdLevel_a3.{id} ' )->shouldBeCalledTimes (1 );
222
238
$ queryBuilderProphecy ->addSelect ('partial relation_a2.{id} ' )->shouldBeCalledTimes (1 );
223
- $ queryBuilderProphecy ->addSelect ('partial relatedDummy2_a3.{id} ' )->shouldBeCalledTimes (1 );
224
- $ queryBuilderProphecy ->addSelect ('partial relatedDummy3_a4.{id} ' )->shouldBeCalledTimes (1 );
225
- $ queryBuilderProphecy ->addSelect ('partial relatedDummy4_a5.{id} ' )->shouldBeCalledTimes (1 );
226
- $ queryBuilderProphecy ->addSelect ('singleInheritanceRelation_a6 ' )->shouldBeCalledTimes (1 );
239
+ $ queryBuilderProphecy ->addSelect ('partial relatedDummy2_a4.{id} ' )->shouldBeCalledTimes (1 );
240
+ $ queryBuilderProphecy ->addSelect ('partial relatedDummy3_a5.{id} ' )->shouldBeCalledTimes (1 );
241
+ $ queryBuilderProphecy ->addSelect ('partial relatedDummy4_a6.{id} ' )->shouldBeCalledTimes (1 );
242
+ $ queryBuilderProphecy ->addSelect ('singleInheritanceRelation_a7 ' )->shouldBeCalledTimes (1 );
243
+ $ queryBuilderProphecy ->addSelect ('partial relatedDummies_a8.{id,name,embeddedDummy.name} ' )->shouldBeCalledTimes (1 );
244
+ $ queryBuilderProphecy ->addSelect ('partial relation_a9.{id} ' )->shouldBeCalledTimes (1 );
245
+ $ queryBuilderProphecy ->addSelect ('partial thirdLevel_a10.{id} ' )->shouldBeCalledTimes (1 );
227
246
$ queryBuilderProphecy ->getDQLPart ('join ' )->willReturn ([]);
228
247
$ queryBuilderProphecy ->getDQLPart ('select ' )->willReturn ([]);
229
248
0 commit comments