Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/State/CreateProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
->create($relationClass)
->getOperation($operation->getExtraProperties()['parent_uri_template'] ?? null);
try {
$relation = $this->decorated->provide($parentOperation, $uriVariables);
$relation = $this->decorated->provide($parentOperation, $uriVariables, $context);
} catch (ProviderNotFoundException) {
$relation = null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/Resources/config/state.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
<service id="ApiPlatform\State\Pagination\PaginationOptions" alias="api_platform.pagination_options" />

<service id="api_platform.state_provider.create" class="ApiPlatform\State\CreateProvider">
<argument type="service" id="api_platform.state_provider" />
<argument type="service" id="api_platform.state_provider.locator" />
<argument type="service" id="api_platform.metadata.resource.metadata_collection_factory" />

<tag name="api_platform.state_provider" key="ApiPlatform\State\CreateProvider" />
Expand Down
14 changes: 7 additions & 7 deletions tests/State/CreateProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function testProvide(): void
new ApiResource(operations: [$parentOperation]),
])
);
$decorated->provide($parentOperation, $uriVariables)->shouldBeCalled()->willReturn(new Company());
$decorated->provide($parentOperation, $uriVariables, [])->shouldBeCalled()->willReturn(new Company());

$createProvider = new CreateProvider($decorated->reveal(), $resourceMetadataCollectionFactory->reveal());
$createProvider->provide($operation, $uriVariables);
Expand All @@ -78,7 +78,7 @@ public function testProvideParentNotFound(): void
new ApiResource(operations: [$parentOperation]),
])
);
$decorated->provide($parentOperation, $uriVariables)->shouldBeCalled()->willReturn(null);
$decorated->provide($parentOperation, $uriVariables, [])->shouldBeCalled()->willReturn(null);

$this->expectException(NotFoundHttpException::class);

Expand All @@ -104,7 +104,7 @@ public function testProvideParentProviderNotFound(): void
new ApiResource(operations: [$parentOperation]),
])
);
$decorated->provide($parentOperation, $uriVariables)->shouldBeCalled()->willThrow(ProviderNotFoundException::class);
$decorated->provide($parentOperation, $uriVariables, [])->shouldBeCalled()->willThrow(ProviderNotFoundException::class);

$this->expectException(NotFoundHttpException::class);

Expand All @@ -127,7 +127,7 @@ class: Employee::class,
$parentOperation = new Get(uriVariables: ['id' => $link], class: Company::class);

$resourceMetadataCollectionFactory->create(Company::class)->shouldBeCalledOnce()->willThrow(ResourceClassNotFoundException::class);
$decorated->provide($parentOperation, $uriVariables)->shouldNotBeCalled();
$decorated->provide($parentOperation, $uriVariables, [])->shouldNotBeCalled();

$this->expectException(ResourceClassNotFoundException::class);

Expand Down Expand Up @@ -157,7 +157,7 @@ class: Employee::class,
new ApiResource(),
])
);
$decorated->provide($parentOperation, $uriVariables)->shouldNotBeCalled();
$decorated->provide($parentOperation, $uriVariables, [])->shouldNotBeCalled();

$this->expectException(OperationNotFoundException::class);

Expand Down Expand Up @@ -191,7 +191,7 @@ class: Employee::class,
]),
])
);
$decorated->provide($parentOperation, $uriVariables)->shouldBeCalled()->willReturn(new Company());
$decorated->provide($parentOperation, $uriVariables, [])->shouldBeCalled()->willReturn(new Company());

$createProvider = new CreateProvider($decorated->reveal(), $resourceMetadataCollectionFactory->reveal());
$createProvider->provide($operation, $uriVariables);
Expand All @@ -215,7 +215,7 @@ public function testProvideFailsProperlyOnComplexConstructor(): void
new ApiResource(operations: [$parentOperation]),
])
);
$decorated->provide($parentOperation, $uriVariables)->shouldBeCalled()->willReturn(new Company());
$decorated->provide($parentOperation, $uriVariables, [])->shouldBeCalled()->willReturn(new Company());

$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('An error occurred while trying to create an instance of the "ApiPlatform\Tests\Fixtures\TestBundle\Entity\DummyResourceWithComplexConstructor" resource. Consider writing your own "ApiPlatform\State\ProviderInterface" implementation and setting it as `provider` on your operation instead.');
Expand Down