Skip to content

Commit b206d39

Browse files
committed
mongodb
1 parent 3194ff8 commit b206d39

File tree

6 files changed

+95
-161
lines changed

6 files changed

+95
-161
lines changed

src/Doctrine/Odm/State/CollectionProvider.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,19 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
6060

6161
$aggregationBuilder = $repository->createAggregationBuilder();
6262

63-
$this->handleLinks($aggregationBuilder, $uriVariables, $context, $resourceClass, $operationName);
63+
$this->handleLinks($aggregationBuilder, $uriVariables, $context, $resourceClass, $operation);
6464

6565
foreach ($this->collectionExtensions as $extension) {
66-
$extension->applyToCollection($aggregationBuilder, $resourceClass, $operationName, $context);
66+
$extension->applyToCollection($aggregationBuilder, $resourceClass, $operation->getName(), $context);
6767

68-
if ($extension instanceof AggregationResultCollectionExtensionInterface && $extension->supportsResult($resourceClass, $operationName, $context)) {
69-
return $extension->getResult($aggregationBuilder, $resourceClass, $operationName, $context);
68+
if ($extension instanceof AggregationResultCollectionExtensionInterface && $extension->supportsResult($resourceClass, $operation->getName(), $context)) {
69+
return $extension->getResult($aggregationBuilder, $resourceClass, $operation->getName(), $context);
7070
}
7171
}
7272

7373
$resourceMetadata = $this->resourceMetadataCollectionFactory->create($resourceClass);
7474
try {
75-
$operation = $context['operation'] ?? $resourceMetadata->getOperation($operationName);
75+
$operation = $context['operation'] ?? $resourceMetadata->getOperation($operation->getName());
7676
$attribute = $operation->getExtraProperties()['doctrine_mongodb'] ?? [];
7777
} catch (OperationNotFoundException $e) {
7878
$attribute = $resourceMetadata->getOperation(null, true)->getExtraProperties()['doctrine_mongodb'] ?? [];

src/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ private function registerMetadataConfiguration(ContainerBuilder $container, arra
340340
$loader->load('metadata/links.xml');
341341
$loader->load('metadata/property.xml');
342342
$loader->load('metadata/resource.xml');
343+
$loader->load('v3/metadata.xml');
343344

344345
$container->getDefinition('api_platform.metadata.resource_extractor.xml')->replaceArgument(0, $xmlResources);
345346
$container->getDefinition('api_platform.metadata.property_extractor.xml')->replaceArgument(0, $xmlResources);

src/Symfony/Bundle/Resources/config/v3/metadata.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,5 @@
99
<argument>%api_platform.resource_class_directories%</argument>
1010
<argument type="service" id="api_platform.metadata.resource.name_collection_factory.attributes.inner" />
1111
</service>
12-
13-
1412
</services>
1513
</container>

tests/Doctrine/Odm/State/CollectionProviderTest.php

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
use ApiPlatform\Doctrine\Odm\State\CollectionProvider;
2020
use ApiPlatform\Exception\RuntimeException;
2121
use ApiPlatform\Metadata\ApiResource;
22-
use ApiPlatform\Metadata\Get;
2322
use ApiPlatform\Metadata\GetCollection;
2423
use ApiPlatform\Metadata\Operations;
2524
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
2625
use ApiPlatform\Metadata\Resource\ResourceMetadataCollection;
27-
use ApiPlatform\Tests\Fixtures\TestBundle\Document\Dummy;
2826
use ApiPlatform\Tests\Fixtures\TestBundle\Document\ProviderEntity;
2927
use Doctrine\ODM\MongoDB\Aggregation\Builder;
3028
use Doctrine\ODM\MongoDB\DocumentManager;
@@ -71,14 +69,14 @@ public function testGetCollection()
7169
$managerProphecy->getRepository(ProviderEntity::class)->willReturn($repositoryProphecy->reveal())->shouldBeCalled();
7270

7371
$this->managerRegistryProphecy->getManagerForClass(ProviderEntity::class)->willReturn($managerProphecy->reveal())->shouldBeCalled();
74-
75-
$this->resourceMetadataFactoryProphecy->create(ProviderEntity::class)->willReturn(new ResourceMetadataCollection(ProviderEntity::class, [(new ApiResource())->withOperations(new Operations(['foo' => new GetCollection()]))]));
72+
$operation = (new GetCollection())->withName('foo')->withClass(ProviderEntity::class);
73+
$this->resourceMetadataFactoryProphecy->create(ProviderEntity::class)->willReturn(new ResourceMetadataCollection(ProviderEntity::class, [(new ApiResource())->withOperations(new Operations(['foo' => $operation]))]));
7674

7775
$extensionProphecy = $this->prophesize(AggregationCollectionExtensionInterface::class);
7876
$extensionProphecy->applyToCollection($aggregationBuilder, ProviderEntity::class, 'foo', [])->shouldBeCalled();
7977

8078
$dataProvider = new CollectionProvider($this->resourceMetadataFactoryProphecy->reveal(), $this->managerRegistryProphecy->reveal(), [$extensionProphecy->reveal()]);
81-
$this->assertEquals($iterator, $dataProvider->provide(ProviderEntity::class, [], 'foo'));
79+
$this->assertEquals($iterator, $dataProvider->provide($operation, []));
8280
}
8381

8482
public function testGetCollectionWithExecuteOptions()
@@ -98,13 +96,17 @@ public function testGetCollectionWithExecuteOptions()
9896

9997
$this->managerRegistryProphecy->getManagerForClass(ProviderEntity::class)->willReturn($managerProphecy->reveal())->shouldBeCalled();
10098

101-
$this->resourceMetadataFactoryProphecy->create(ProviderEntity::class)->willReturn(new ResourceMetadataCollection(ProviderEntity::class, [(new ApiResource())->withOperations(new Operations(['foo' => (new GetCollection())->withExtraProperties(['doctrine_mongodb' => ['execute_options' => ['allowDiskUse' => true]]])]))]));
99+
$operation = (new GetCollection())->withExtraProperties(['doctrine_mongodb' => ['execute_options' => ['allowDiskUse' => true]]])->withName('foo')->withClass(ProviderEntity::class);
100+
$this->resourceMetadataFactoryProphecy->create(ProviderEntity::class)
101+
->willReturn(new ResourceMetadataCollection(ProviderEntity::class, [
102+
(new ApiResource())->withOperations(new Operations(['foo' => $operation])),
103+
]));
102104

103105
$extensionProphecy = $this->prophesize(AggregationCollectionExtensionInterface::class);
104106
$extensionProphecy->applyToCollection($aggregationBuilder, ProviderEntity::class, 'foo', [])->shouldBeCalled();
105107

106108
$dataProvider = new CollectionProvider($this->resourceMetadataFactoryProphecy->reveal(), $this->managerRegistryProphecy->reveal(), [$extensionProphecy->reveal()]);
107-
$this->assertEquals($iterator, $dataProvider->provide(ProviderEntity::class, [], 'foo'));
109+
$this->assertEquals($iterator, $dataProvider->provide($operation, []));
108110
}
109111

110112
public function testAggregationResultExtension()
@@ -119,14 +121,15 @@ public function testAggregationResultExtension()
119121
$managerProphecy->getRepository(ProviderEntity::class)->willReturn($repositoryProphecy->reveal())->shouldBeCalled();
120122

121123
$this->managerRegistryProphecy->getManagerForClass(ProviderEntity::class)->willReturn($managerProphecy->reveal())->shouldBeCalled();
124+
$operation = (new GetCollection())->withName('foo')->withClass(ProviderEntity::class);
122125

123126
$extensionProphecy = $this->prophesize(AggregationResultCollectionExtensionInterface::class);
124127
$extensionProphecy->applyToCollection($aggregationBuilder, ProviderEntity::class, 'foo', [])->shouldBeCalled();
125128
$extensionProphecy->supportsResult(ProviderEntity::class, 'foo', [])->willReturn(true)->shouldBeCalled();
126129
$extensionProphecy->getResult($aggregationBuilder, ProviderEntity::class, 'foo', [])->willReturn([])->shouldBeCalled();
127130

128131
$dataProvider = new CollectionProvider($this->resourceMetadataFactoryProphecy->reveal(), $this->managerRegistryProphecy->reveal(), [$extensionProphecy->reveal()]);
129-
$this->assertEquals([], $dataProvider->provide(ProviderEntity::class, [], 'foo'));
132+
$this->assertEquals([], $dataProvider->provide($operation, []));
130133
}
131134

132135
public function testCannotCreateAggregationBuilder()
@@ -142,43 +145,8 @@ public function testCannotCreateAggregationBuilder()
142145
$this->managerRegistryProphecy->getManagerForClass(ProviderEntity::class)->willReturn($managerProphecy->reveal())->shouldBeCalled();
143146

144147
$dataProvider = new CollectionProvider($this->resourceMetadataFactoryProphecy->reveal(), $this->managerRegistryProphecy->reveal());
145-
$this->assertEquals([], $dataProvider->provide(ProviderEntity::class, [], 'foo'));
146-
}
147-
148-
public function testSupportedClass()
149-
{
150-
$documentManagerProphecy = $this->prophesize(DocumentManager::class);
151-
152-
$this->resourceMetadataFactoryProphecy->create(ProviderEntity::class)->willReturn(new ResourceMetadataCollection(ProviderEntity::class, [(new ApiResource())->withOperations(new Operations(['foo' => new GetCollection()]))]));
153-
$this->managerRegistryProphecy->getManagerForClass(ProviderEntity::class)->willReturn($documentManagerProphecy->reveal())->shouldBeCalled();
154-
155-
$extensionProphecy = $this->prophesize(AggregationResultCollectionExtensionInterface::class);
156-
157-
$dataProvider = new CollectionProvider($this->resourceMetadataFactoryProphecy->reveal(), $this->managerRegistryProphecy->reveal(), [$extensionProphecy->reveal()]);
158-
$this->assertTrue($dataProvider->supports(ProviderEntity::class, [], 'foo'));
159-
}
160-
161-
public function testUnsupportedClass()
162-
{
163-
$this->managerRegistryProphecy->getManagerForClass(Dummy::class)->willReturn(null)->shouldBeCalled();
164-
165-
$extensionProphecy = $this->prophesize(AggregationResultCollectionExtensionInterface::class);
166-
167-
$dataProvider = new CollectionProvider($this->resourceMetadataFactoryProphecy->reveal(), $this->managerRegistryProphecy->reveal(), [$extensionProphecy->reveal()]);
168-
$this->assertFalse($dataProvider->supports(Dummy::class, [], 'foo'));
169-
}
170-
171-
public function testNotCollectionOperation()
172-
{
173-
$documentManagerProphecy = $this->prophesize(DocumentManager::class);
174-
175-
$this->resourceMetadataFactoryProphecy->create(ProviderEntity::class)->willReturn(new ResourceMetadataCollection(ProviderEntity::class, [(new ApiResource())->withOperations(new Operations(['foo' => new Get()]))]));
176-
$this->managerRegistryProphecy->getManagerForClass(ProviderEntity::class)->willReturn($documentManagerProphecy->reveal())->shouldBeCalled();
177-
178-
$extensionProphecy = $this->prophesize(AggregationResultCollectionExtensionInterface::class);
179-
180-
$dataProvider = new CollectionProvider($this->resourceMetadataFactoryProphecy->reveal(), $this->managerRegistryProphecy->reveal(), [$extensionProphecy->reveal()]);
181-
$this->assertFalse($dataProvider->supports(ProviderEntity::class, [], 'foo'));
148+
$operation = (new GetCollection())->withName('foo')->withClass(ProviderEntity::class);
149+
$this->assertEquals([], $dataProvider->provide($operation, []));
182150
}
183151

184152
public function testOperationNotFound()
@@ -204,6 +172,6 @@ public function testOperationNotFound()
204172
$extensionProphecy->applyToCollection($aggregationBuilder, ProviderEntity::class, 'bar', [])->shouldBeCalled();
205173

206174
$dataProvider = new CollectionProvider($this->resourceMetadataFactoryProphecy->reveal(), $this->managerRegistryProphecy->reveal(), [$extensionProphecy->reveal()]);
207-
$this->assertEquals($iterator, $dataProvider->provide(ProviderEntity::class, [], 'bar'));
175+
$this->assertEquals($iterator, $dataProvider->provide((new GetCollection())->withName('bar')->withClass(ProviderEntity::class), []));
208176
}
209177
}

0 commit comments

Comments
 (0)