Skip to content

Commit 75038dc

Browse files
committed
Fix - Use operation name by default for the route name
1 parent 8061967 commit 75038dc

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/Component/spec/Symfony/Routing/Factory/RouteName/OperationRouteNameFactorySpec.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,38 @@ function it_is_initializable(): void
2525
$this->shouldHaveType(OperationRouteNameFactory::class);
2626
}
2727

28-
function it_create_a_route_name(): void
28+
function it_creates_a_route_name(): void
2929
{
3030
$resource = new ResourceMetadata(alias: 'app.book', name: 'book', applicationName: 'app');
3131
$operation = (new Create())->withResource($resource);
3232

3333
$this->createRouteName($operation)->shouldReturn('app_book_create');
3434
}
3535

36-
function it_create_a_route_name_with_a_section(): void
36+
function it_uses_the_operation_name_when_specified(): void
37+
{
38+
$resource = new ResourceMetadata(alias: 'app.book', name: 'book', applicationName: 'app');
39+
$operation = (new Create(name: 'app_book_new'))->withResource($resource);
40+
41+
$this->createRouteName($operation)->shouldReturn('app_book_new');
42+
}
43+
44+
function it_creates_a_route_name_with_a_section(): void
3745
{
3846
$resource = new ResourceMetadata(alias: 'app.book', section: 'admin', name: 'book', applicationName: 'app');
3947
$operation = (new Create())->withResource($resource);
4048

4149
$this->createRouteName($operation)->shouldReturn('app_admin_book_create');
4250
}
4351

52+
function it_creates_a_route_name_from_another_operation(): void
53+
{
54+
$resource = new ResourceMetadata(alias: 'app.book', name: 'book', applicationName: 'app');
55+
$operation = (new Create())->withResource($resource);
56+
57+
$this->createRouteName($operation, 'index')->shouldReturn('app_book_index');
58+
}
59+
4460
function it_throws_an_exception_when_operation_has_no_resource(): void
4561
{
4662
$operation = new Create();

src/Component/src/Symfony/Routing/Factory/RouteName/OperationRouteNameFactory.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ public function createRouteName(Operation $operation, ?string $shortName = null)
2828
throw new \RuntimeException(sprintf('No resource was found on the operation "%s"', $operation->getShortName() ?? ''));
2929
}
3030

31+
$operationName = $operation->getName();
32+
33+
if (null === $shortName && null !== $operationName) {
34+
return $operationName;
35+
}
36+
3137
$section = $resource->getSection();
3238
$sectionPrefix = $section ? $section . '_' : '';
3339

0 commit comments

Comments
 (0)