Skip to content

Commit b32fbbe

Browse files
abluchetsoyuka
authored andcommitted
Forward operation name in the iri converter
1 parent cc34af9 commit b32fbbe

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/Bridge/Symfony/Routing/IriConverter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function getItemFromIri(string $iri, array $context = [])
7373
throw new InvalidArgumentException(sprintf('No resource associated to "%s".', $iri));
7474
}
7575

76-
if ($item = $this->itemDataProvider->getItem($parameters['_api_resource_class'], $parameters['id'], null, $context)) {
76+
if ($item = $this->itemDataProvider->getItem($parameters['_api_resource_class'], $parameters['id'], $parameters['_api_item_operation_name'] ?? null, $context)) {
7777
return $item;
7878
}
7979

tests/Bridge/Symfony/Routing/IriConverterTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,41 @@ public function testGetItemFromIri()
168168
$converter->getItemFromIri('/users/3', ['fetch_data' => true]);
169169
}
170170

171+
public function testGetItemFromIriWithOperationName()
172+
{
173+
$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);
174+
175+
$propertyMetadataFactoryProphecy = $this->prophesize(PropertyMetadataFactoryInterface::class);
176+
177+
$itemDataProviderProphecy = $this->prophesize(ItemDataProviderInterface::class);
178+
$itemDataProviderProphecy->getItem('AppBundle\Entity\User', '3', 'operation_name', ['fetch_data' => true])
179+
->willReturn('foo')
180+
->shouldBeCalledTimes(1);
181+
182+
$routeNameResolverProphecy = $this->prophesize(RouteNameResolverInterface::class);
183+
184+
$routerProphecy = $this->prophesize(RouterInterface::class);
185+
$routerProphecy->match('/users/3')->willReturn([
186+
'_api_resource_class' => 'AppBundle\Entity\User',
187+
'_api_item_operation_name' => 'operation_name',
188+
'id' => 3,
189+
])->shouldBeCalledTimes(1);
190+
191+
$propertyNameCollectionFactory = $propertyNameCollectionFactoryProphecy->reveal();
192+
$propertyMetadataFactory = $propertyMetadataFactoryProphecy->reveal();
193+
194+
$converter = new IriConverter(
195+
$propertyNameCollectionFactory,
196+
$propertyMetadataFactory,
197+
$itemDataProviderProphecy->reveal(),
198+
$routeNameResolverProphecy->reveal(),
199+
$routerProphecy->reveal(),
200+
null,
201+
new IdentifiersExtractor($propertyNameCollectionFactory, $propertyMetadataFactory, null, $this->getResourceClassResolver())
202+
);
203+
$converter->getItemFromIri('/users/3', ['fetch_data' => true]);
204+
}
205+
171206
public function testGetIriFromResourceClass()
172207
{
173208
$propertyNameCollectionFactoryProphecy = $this->prophesize(PropertyNameCollectionFactoryInterface::class);

0 commit comments

Comments
 (0)