From 1d7007e47657490691299cd96cb893889b81f9e9 Mon Sep 17 00:00:00 2001 From: Javier Spagnoletti Date: Thu, 25 Feb 2021 12:06:51 -0300 Subject: [PATCH] Added XML routing --- Resources/config/routing.xml | 4 ++ Resources/config/routing/hackzilla_ticket.xml | 10 +++ Resources/config/routing/ticket.yml | 1 + Resources/doc/setup/install.md | 4 +- Tests/Functional/RoutingTest.php | 61 +++++++++++++++++++ Tests/Functional/TestKernel.php | 2 + Tests/Functional/routes.yaml | 3 + composer.json | 2 + 8 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 Resources/config/routing.xml create mode 100644 Resources/config/routing/hackzilla_ticket.xml create mode 100644 Tests/Functional/RoutingTest.php create mode 100644 Tests/Functional/routes.yaml diff --git a/Resources/config/routing.xml b/Resources/config/routing.xml new file mode 100644 index 00000000..dae6292b --- /dev/null +++ b/Resources/config/routing.xml @@ -0,0 +1,4 @@ + + + + diff --git a/Resources/config/routing/hackzilla_ticket.xml b/Resources/config/routing/hackzilla_ticket.xml new file mode 100644 index 00000000..632b5bbe --- /dev/null +++ b/Resources/config/routing/hackzilla_ticket.xml @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/Resources/config/routing/ticket.yml b/Resources/config/routing/ticket.yml index 780e72e7..631b4808 100644 --- a/Resources/config/routing/ticket.yml +++ b/Resources/config/routing/ticket.yml @@ -1,3 +1,4 @@ +# NEXT_MAJOR: remove this file and add upgrade note. hackzilla_ticket: path: / controller: 'Hackzilla\Bundle\TicketBundle\Controller\TicketController::indexAction' diff --git a/Resources/doc/setup/install.md b/Resources/doc/setup/install.md index 4a475a09..2eb6f07c 100644 --- a/Resources/doc/setup/install.md +++ b/Resources/doc/setup/install.md @@ -69,7 +69,7 @@ public function registerBundles() ``` yml hackzilla_ticket: - resource: "@HackzillaTicketBundle/Resources/config/routing.yml" + resource: "@HackzillaTicketBundle/Resources/config/routing.xml" prefix: / ``` @@ -77,7 +77,7 @@ or ``` yml hackzilla_ticket: - resource: "@HackzillaTicketBundle/Resources/config/routing/ticket.yml" + resource: "@HackzillaTicketBundle/Resources/config/routing/hackzilla_ticket.xml" prefix: /ticket ``` diff --git a/Tests/Functional/RoutingTest.php b/Tests/Functional/RoutingTest.php new file mode 100644 index 00000000..d48f31be --- /dev/null +++ b/Tests/Functional/RoutingTest.php @@ -0,0 +1,61 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Hackzilla\Bundle\TicketBundle\Tests\Functional; + +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; + +/** + * @author Javier Spagnoletti + */ +final class RoutingTest extends WebTestCase +{ + /** + * @dataProvider getRoutes + */ + public function testRoutes(string $name, string $path, array $methods): void + { + $client = static::createClient(); + $router = $client->getContainer()->get('router'); + + $route = $router->getRouteCollection()->get($name); + + $this->assertNotNull($route); + $this->assertSame($path, $route->getPath()); + $this->assertEmpty(array_diff($methods, $route->getMethods())); + + $matcher = $router->getMatcher(); + $requestContext = $router->getContext(); + + foreach ($methods as $method) { + $requestContext->setMethod($method); + $match = $matcher->match($path); + + $this->assertSame($name, $match['_route']); + } + } + + public function getRoutes(): iterable + { + yield ['hackzilla_ticket', '/ticket/', []]; + yield ['hackzilla_ticket_show', '/ticket/{ticketId}/show', []]; + yield ['hackzilla_ticket_new', '/ticket/new', []]; + yield ['hackzilla_ticket_create', '/ticket/create', ['POST']]; + yield ['hackzilla_ticket_delete', '/ticket/{ticketId}/delete', ['DELETE', 'POST']]; + yield ['hackzilla_ticket_reply', '/ticket/{ticketId}/reply', []]; + yield ['hackzilla_ticket_attachment', '/ticket/attachment/{ticketMessageId}/download', []]; + } + + protected static function getKernelClass(): string + { + return TestKernel::class; + } +} diff --git a/Tests/Functional/TestKernel.php b/Tests/Functional/TestKernel.php index 17ae15b6..dc1879dd 100644 --- a/Tests/Functional/TestKernel.php +++ b/Tests/Functional/TestKernel.php @@ -84,6 +84,7 @@ public function getLogDir() */ protected function configureRoutes(RouteCollectionBuilder $routes) { + $routes->import(__DIR__.'/routes.yaml', '/', 'yaml'); } /** @@ -109,6 +110,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load 'validation' => [ 'enabled' => true, ], + 'test' => true, ]); // SecurityBundle config diff --git a/Tests/Functional/routes.yaml b/Tests/Functional/routes.yaml new file mode 100644 index 00000000..2952b2e6 --- /dev/null +++ b/Tests/Functional/routes.yaml @@ -0,0 +1,3 @@ +hackzilla_ticket: + resource: "@HackzillaTicketBundle/Resources/config/routing.xml" + prefix: / diff --git a/composer.json b/composer.json index 23b1c80e..a04b5849 100644 --- a/composer.json +++ b/composer.json @@ -52,6 +52,8 @@ "ext-pdo_sqlite": "*", "friendsofphp/php-cs-fixer": "^2.0", "phpstan/phpstan": "^0.12.32", + "symfony/browser-kit": "^4.4 || ^5.2", + "symfony/http-client": "^4.4 || ^5.2", "symfony/phpunit-bridge": "^5.1.1", "symfony/security": "^4.4" },