Skip to content

Commit 46fd899

Browse files
fix(metadata): fix CreateProvider Behat tests (#5802)
1 parent c7dcd36 commit 46fd899

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/State/CreateProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
5757
->create($relationClass)
5858
->getOperation($operation->getExtraProperties()['parent_uri_template'] ?? null);
5959
try {
60-
$relation = $this->decorated->provide($parentOperation, $uriVariables);
60+
$relation = $this->decorated->provide($parentOperation, $uriVariables, $context);
6161
} catch (ProviderNotFoundException) {
6262
$relation = null;
6363
}

src/Symfony/Bundle/Resources/config/state.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
<service id="ApiPlatform\State\Pagination\PaginationOptions" alias="api_platform.pagination_options" />
8282

8383
<service id="api_platform.state_provider.create" class="ApiPlatform\State\CreateProvider">
84-
<argument type="service" id="api_platform.state_provider" />
84+
<argument type="service" id="api_platform.state_provider.locator" />
8585
<argument type="service" id="api_platform.metadata.resource.metadata_collection_factory" />
8686

8787
<tag name="api_platform.state_provider" key="ApiPlatform\State\CreateProvider" />

tests/State/CreateProviderTest.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function testProvide(): void
5454
new ApiResource(operations: [$parentOperation]),
5555
])
5656
);
57-
$decorated->provide($parentOperation, $uriVariables)->shouldBeCalled()->willReturn(new Company());
57+
$decorated->provide($parentOperation, $uriVariables, [])->shouldBeCalled()->willReturn(new Company());
5858

5959
$createProvider = new CreateProvider($decorated->reveal(), $resourceMetadataCollectionFactory->reveal());
6060
$createProvider->provide($operation, $uriVariables);
@@ -78,7 +78,7 @@ public function testProvideParentNotFound(): void
7878
new ApiResource(operations: [$parentOperation]),
7979
])
8080
);
81-
$decorated->provide($parentOperation, $uriVariables)->shouldBeCalled()->willReturn(null);
81+
$decorated->provide($parentOperation, $uriVariables, [])->shouldBeCalled()->willReturn(null);
8282

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

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

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

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

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

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

@@ -157,7 +157,7 @@ class: Employee::class,
157157
new ApiResource(),
158158
])
159159
);
160-
$decorated->provide($parentOperation, $uriVariables)->shouldNotBeCalled();
160+
$decorated->provide($parentOperation, $uriVariables, [])->shouldNotBeCalled();
161161

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

@@ -191,7 +191,7 @@ class: Employee::class,
191191
]),
192192
])
193193
);
194-
$decorated->provide($parentOperation, $uriVariables)->shouldBeCalled()->willReturn(new Company());
194+
$decorated->provide($parentOperation, $uriVariables, [])->shouldBeCalled()->willReturn(new Company());
195195

196196
$createProvider = new CreateProvider($decorated->reveal(), $resourceMetadataCollectionFactory->reveal());
197197
$createProvider->provide($operation, $uriVariables);
@@ -215,7 +215,7 @@ public function testProvideFailsProperlyOnComplexConstructor(): void
215215
new ApiResource(operations: [$parentOperation]),
216216
])
217217
);
218-
$decorated->provide($parentOperation, $uriVariables)->shouldBeCalled()->willReturn(new Company());
218+
$decorated->provide($parentOperation, $uriVariables, [])->shouldBeCalled()->willReturn(new Company());
219219

220220
$this->expectException(RuntimeException::class);
221221
$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.');

0 commit comments

Comments
 (0)