Skip to content

Commit d25ca5e

Browse files
author
abluchet
committed
Forward operation name in the iri converter
1 parent 2e0c647 commit d25ca5e

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/Bridge/Symfony/Routing/IriConverter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function getItemFromIri(string $iri, array $context = [])
8787
$context[ChainIdentifierDenormalizer::HAS_IDENTIFIER_DENORMALIZER] = true;
8888
}
8989

90-
if ($item = $this->itemDataProvider->getItem($parameters['_api_resource_class'], $identifiers, null, $context)) {
90+
if ($item = $this->itemDataProvider->getItem($parameters['_api_resource_class'], $identifiers, $parameters['_api_item_operation_name'] ?? null, $context)) {
9191
return $item;
9292
}
9393

tests/Bridge/Symfony/Routing/IriConverterTest.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,44 @@ public function testGetItemFromIriWithIdentifierNormalizer()
217217
$converter->getItemFromIri('/users/3', ['fetch_data' => true]);
218218
}
219219

220+
public function testGetItemFromIriWithIdentifierNormalizerAndOperationName()
221+
{
222+
$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
223+
224+
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
225+
226+
$itemDataProviderProphecy = $this->prophesize(ItemDataProviderInterface::class);
227+
$itemDataProviderProphecy->getItem('AppBundle\Entity\User', ['id' => 3], 'operation_name', ['fetch_data' => true, ChainIdentifierDenormalizer::HAS_IDENTIFIER_DENORMALIZER => true])
228+
->willReturn('foo')
229+
->shouldBeCalledTimes(1);
230+
231+
$routeNameResolverProphecy = $this->prophesize(RouteNameResolverInterface::class);
232+
233+
$routerProphecy = $this->prophesize(RouterInterface::class);
234+
$routerProphecy->match('/users/3')->willReturn([
235+
'_api_resource_class' => 'AppBundle\Entity\User',
236+
'_api_item_operation_name' => 'operation_name',
237+
'id' => 3,
238+
])->shouldBeCalledTimes(1);
239+
240+
$propertyNameCollectionFactory = $propertyNameCollectionFactoryProphecy->reveal();
241+
$propertyMetadataFactory = $propertyMetadataFactoryProphecy->reveal();
242+
$identifierDenormalizer = $this->prophesize(ChainIdentifierDenormalizer::class);
243+
$identifierDenormalizer->denormalize('3', 'AppBundle\Entity\User')->shouldBeCalled()->willReturn(['id' => 3]);
244+
245+
$converter = new IriConverter(
246+
$propertyNameCollectionFactory,
247+
$propertyMetadataFactory,
248+
$itemDataProviderProphecy->reveal(),
249+
$routeNameResolverProphecy->reveal(),
250+
$routerProphecy->reveal(),
251+
null,
252+
new IdentifiersExtractor($propertyNameCollectionFactory, $propertyMetadataFactory, null, $this->getResourceClassResolver()),
253+
$identifierDenormalizer->reveal()
254+
);
255+
$converter->getItemFromIri('/users/3', ['fetch_data' => true]);
256+
}
257+
220258
public function testGetIriFromResourceClass()
221259
{
222260
$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);

0 commit comments

Comments
 (0)