diff --git a/src/Resources/skeleton/crud/controller/Controller.tpl.php b/src/Resources/skeleton/crud/controller/Controller.tpl.php index 135d0c10a..0a4a84d55 100644 --- a/src/Resources/skeleton/crud/controller/Controller.tpl.php +++ b/src/Resources/skeleton/crud/controller/Controller.tpl.php @@ -7,7 +7,7 @@ #[Route('')] getClassDeclaration() ?> { -generateRouteForControllerMethod('/', sprintf('%s_index', $route_name), ['GET']) ?> +generateRouteForControllerMethod('', sprintf('%s_index', $route_name), ['GET']) ?> public function index( $): Response { diff --git a/src/Resources/skeleton/crud/test/Test.EntityManager.tpl.php b/src/Resources/skeleton/crud/test/Test.EntityManager.tpl.php index 825737383..36003d7e4 100644 --- a/src/Resources/skeleton/crud/test/Test.EntityManager.tpl.php +++ b/src/Resources/skeleton/crud/test/Test.EntityManager.tpl.php @@ -27,6 +27,7 @@ protected function setUp(): void public function testIndex(): void { + $this->client->followRedirects(); $crawler = $this->client->request('GET', $this->path); self::assertResponseStatusCodeSame(200); diff --git a/src/Util/TemplateComponentGenerator.php b/src/Util/TemplateComponentGenerator.php index 24271fc35..de8fc163c 100644 --- a/src/Util/TemplateComponentGenerator.php +++ b/src/Util/TemplateComponentGenerator.php @@ -27,9 +27,16 @@ public function __construct( ) { } - public function generateRouteForControllerMethod(string $routePath, string $routeName, array $methods = [], bool $indent = true, bool $trailingNewLine = true): string + /** + * @param string|null $routePath passing an empty string/null will create a route attribute without the "path" argument + */ + public function generateRouteForControllerMethod(?string $routePath, string $routeName, array $methods = [], bool $indent = true, bool $trailingNewLine = true): string { - $attribute = \sprintf('%s#[Route(\'%s\', name: \'%s\'', $indent ? ' ' : null, $routePath, $routeName); + if (!empty($routePath)) { + $path = \sprintf('\'%s\', ', $routePath); + } + + $attribute = \sprintf('%s#[Route(%sname: \'%s\'', $indent ? ' ' : null, $path ?? null, $routeName); if (!empty($methods)) { $attribute .= ', methods: ['; diff --git a/tests/fixtures/make-crud/expected/WithCustomRepository.php b/tests/fixtures/make-crud/expected/WithCustomRepository.php index b1c77ffd5..b5fa2da83 100644 --- a/tests/fixtures/make-crud/expected/WithCustomRepository.php +++ b/tests/fixtures/make-crud/expected/WithCustomRepository.php @@ -14,7 +14,7 @@ #[Route('/sweet/food')] final class SweetFoodController extends AbstractController { - #[Route('/', name: 'app_sweet_food_index', methods: ['GET'])] + #[Route(name: 'app_sweet_food_index', methods: ['GET'])] public function index(SweetFoodRepository $sweetFoodRepository): Response { return $this->render('sweet_food/index.html.twig', [ diff --git a/tests/fixtures/make-crud/tests/it_generates_basic_crud.php b/tests/fixtures/make-crud/tests/it_generates_basic_crud.php index 576eb328b..69307fb0d 100644 --- a/tests/fixtures/make-crud/tests/it_generates_basic_crud.php +++ b/tests/fixtures/make-crud/tests/it_generates_basic_crud.php @@ -9,7 +9,7 @@ class GeneratedCrudControllerTest extends WebTestCase public function testIndexAction() { $client = self::createClient(); - $crawler = $client->request('GET', '/sweet/food/'); + $crawler = $client->request('GET', '/sweet/food'); $this->assertTrue($client->getResponse()->isSuccessful()); $this->assertStringContainsString('', $client->getResponse()->getContent()); $this->assertStringContainsString('SweetFood index', $client->getResponse()->getContent()); diff --git a/tests/fixtures/make-crud/tests/it_generates_crud_with_custom_controller.php b/tests/fixtures/make-crud/tests/it_generates_crud_with_custom_controller.php index d6eaca822..aefdae80a 100644 --- a/tests/fixtures/make-crud/tests/it_generates_crud_with_custom_controller.php +++ b/tests/fixtures/make-crud/tests/it_generates_crud_with_custom_controller.php @@ -9,7 +9,7 @@ class GeneratedCrudControllerTest extends WebTestCase public function testIndexAction() { $client = self::createClient(); - $crawler = $client->request('GET', '/sweet/food/admin/'); + $crawler = $client->request('GET', '/sweet/food/admin'); $this->assertTrue($client->getResponse()->isSuccessful()); $this->assertStringContainsString('', $client->getResponse()->getContent()); $this->assertStringContainsString('SweetFood index', $client->getResponse()->getContent()); diff --git a/tests/fixtures/make-crud/tests/it_generates_crud_with_custom_root_namespace.php b/tests/fixtures/make-crud/tests/it_generates_crud_with_custom_root_namespace.php index 576eb328b..69307fb0d 100644 --- a/tests/fixtures/make-crud/tests/it_generates_crud_with_custom_root_namespace.php +++ b/tests/fixtures/make-crud/tests/it_generates_crud_with_custom_root_namespace.php @@ -9,7 +9,7 @@ class GeneratedCrudControllerTest extends WebTestCase public function testIndexAction() { $client = self::createClient(); - $crawler = $client->request('GET', '/sweet/food/'); + $crawler = $client->request('GET', '/sweet/food'); $this->assertTrue($client->getResponse()->isSuccessful()); $this->assertStringContainsString('', $client->getResponse()->getContent()); $this->assertStringContainsString('SweetFood index', $client->getResponse()->getContent());