|
13 | 13 |
|
14 | 14 | use ApiPlatform\Core\Bridge\Doctrine\Orm\Extension\EagerLoadingExtension;
|
15 | 15 | use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGenerator;
|
| 16 | +use ApiPlatform\Core\Exception\PropertyNotFoundException; |
| 17 | +use ApiPlatform\Core\Exception\ResourceClassNotFoundException; |
16 | 18 | use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
|
17 | 19 | use ApiPlatform\Core\Metadata\Property\PropertyMetadata;
|
18 | 20 | use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
|
@@ -284,4 +286,51 @@ public function testForceEager()
|
284 | 286 | $orderExtensionTest = new EagerLoadingExtension($propertyMetadataFactoryProphecy->reveal(), $resourceMetadataFactoryProphecy->reveal(), 30, true);
|
285 | 287 | $orderExtensionTest->applyToItem($queryBuilderProphecy->reveal(), new QueryNameGenerator(), Dummy::class, []);
|
286 | 288 | }
|
| 289 | + |
| 290 | + public function testResourceClassNotFoundException() |
| 291 | + { |
| 292 | + $resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class); |
| 293 | + $resourceMetadataFactoryProphecy->create(Dummy::class)->willReturn(new ResourceMetadata()); |
| 294 | + |
| 295 | + $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class); |
| 296 | + $propertyMetadataFactoryProphecy->create(Dummy::class, 'relation', [])->willThrow(new ResourceClassNotFoundException()); |
| 297 | + |
| 298 | + $classMetadataProphecy = $this->prophesize(ClassMetadata::class); |
| 299 | + $classMetadataProphecy->associationMappings = [ |
| 300 | + 'relation' => ['fetch' => 2, 'targetEntity' => UnknownDummy::class, 'joinColumns' => [['nullable' => false]]], |
| 301 | + ]; |
| 302 | + $emProphecy = $this->prophesize(EntityManager::class); |
| 303 | + $emProphecy->getClassMetadata(Dummy::class)->shouldBeCalled()->willReturn($classMetadataProphecy->reveal()); |
| 304 | + $queryBuilderProphecy = $this->prophesize(QueryBuilder::class); |
| 305 | + $queryBuilderProphecy->getRootAliases()->willReturn(['o']); |
| 306 | + $queryBuilderProphecy->getEntityManager()->willReturn($emProphecy); |
| 307 | + |
| 308 | + $orderExtensionTest = new EagerLoadingExtension($propertyMetadataFactoryProphecy->reveal(), $resourceMetadataFactoryProphecy->reveal(), 30, true); |
| 309 | + $orderExtensionTest->applyToItem($queryBuilderProphecy->reveal(), new QueryNameGenerator(), Dummy::class, []); |
| 310 | + } |
| 311 | + |
| 312 | + public function testPropertyNotFoundException() |
| 313 | + { |
| 314 | + $resourceMetadataFactoryProphecy = $this->prophesize(ResourceMetadataFactoryInterface::class); |
| 315 | + $resourceMetadataFactoryProphecy->create(Dummy::class)->willReturn(new ResourceMetadata()); |
| 316 | + |
| 317 | + $propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class); |
| 318 | + $propertyMetadataFactoryProphecy->create(Dummy::class, 'relation', [])->willThrow(new PropertyNotFoundException()); |
| 319 | + |
| 320 | + $classMetadataProphecy = $this->prophesize(ClassMetadata::class); |
| 321 | + $classMetadataProphecy->associationMappings = [ |
| 322 | + 'relation' => ['fetch' => 2, 'targetEntity' => UnknownDummy::class, 'joinColumns' => [['nullable' => false]]], |
| 323 | + ]; |
| 324 | + $emProphecy = $this->prophesize(EntityManager::class); |
| 325 | + $emProphecy->getClassMetadata(Dummy::class)->shouldBeCalled()->willReturn($classMetadataProphecy->reveal()); |
| 326 | + $queryBuilderProphecy = $this->prophesize(QueryBuilder::class); |
| 327 | + $queryBuilderProphecy->getRootAliases()->willReturn(['o']); |
| 328 | + $queryBuilderProphecy->getEntityManager()->willReturn($emProphecy); |
| 329 | + $queryBuilderProphecy = $this->prophesize(QueryBuilder::class); |
| 330 | + $queryBuilderProphecy->getRootAliases()->willReturn(['o']); |
| 331 | + $queryBuilderProphecy->getEntityManager()->willReturn($emProphecy); |
| 332 | + |
| 333 | + $orderExtensionTest = new EagerLoadingExtension($propertyMetadataFactoryProphecy->reveal(), $resourceMetadataFactoryProphecy->reveal(), 30, true); |
| 334 | + $orderExtensionTest->applyToItem($queryBuilderProphecy->reveal(), new QueryNameGenerator(), Dummy::class, []); |
| 335 | + } |
287 | 336 | }
|
0 commit comments