Skip to content

Added XML routing #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Resources/config/routing.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<routes xmlns="http://symfony.com/schema/routing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<import resource="./routing/hackzilla_ticket.xml" type="xml" prefix="/ticket"/>
</routes>
10 changes: 10 additions & 0 deletions Resources/config/routing/hackzilla_ticket.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<routes xmlns="http://symfony.com/schema/routing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
<route id="hackzilla_ticket" path="/" controller="Hackzilla\Bundle\TicketBundle\Controller\TicketController::indexAction"/>
<route id="hackzilla_ticket_show" path="/{ticketId}/show" controller="Hackzilla\Bundle\TicketBundle\Controller\TicketController::showAction"/>
<route id="hackzilla_ticket_new" path="/new" controller="Hackzilla\Bundle\TicketBundle\Controller\TicketController::newAction"/>
<route id="hackzilla_ticket_create" path="/create" controller="Hackzilla\Bundle\TicketBundle\Controller\TicketController::createAction" methods="POST"/>
<route id="hackzilla_ticket_delete" path="/{ticketId}/delete" controller="Hackzilla\Bundle\TicketBundle\Controller\TicketController::deleteAction" methods="DELETE|POST"/>
<route id="hackzilla_ticket_reply" path="/{ticketId}/reply" controller="Hackzilla\Bundle\TicketBundle\Controller\TicketController::replyAction"/>
<route id="hackzilla_ticket_attachment" path="/attachment/{ticketMessageId}/download" controller="Hackzilla\Bundle\TicketBundle\Controller\TicketAttachmentController::downloadAction"/>
</routes>
1 change: 1 addition & 0 deletions Resources/config/routing/ticket.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# NEXT_MAJOR: remove this file and add upgrade note.
hackzilla_ticket:
path: /
controller: 'Hackzilla\Bundle\TicketBundle\Controller\TicketController::indexAction'
Expand Down
4 changes: 2 additions & 2 deletions Resources/doc/setup/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ public function registerBundles()

``` yml
hackzilla_ticket:
resource: "@HackzillaTicketBundle/Resources/config/routing.yml"
resource: "@HackzillaTicketBundle/Resources/config/routing.xml"
prefix: /
```

or

``` yml
hackzilla_ticket:
resource: "@HackzillaTicketBundle/Resources/config/routing/ticket.yml"
resource: "@HackzillaTicketBundle/Resources/config/routing/hackzilla_ticket.xml"
prefix: /ticket
```

Expand Down
61 changes: 61 additions & 0 deletions Tests/Functional/RoutingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

/*
* This file is part of HackzillaTicketBundle package.
*
* (c) Daniel Platt <github@ofdan.co.uk>
*
* 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 <phansys@gmail.com>
*/
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;
}
}
2 changes: 2 additions & 0 deletions Tests/Functional/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public function getLogDir()
*/
protected function configureRoutes(RouteCollectionBuilder $routes)
{
$routes->import(__DIR__.'/routes.yaml', '/', 'yaml');
}

/**
Expand All @@ -109,6 +110,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
'validation' => [
'enabled' => true,
],
'test' => true,
]);

// SecurityBundle config
Expand Down
3 changes: 3 additions & 0 deletions Tests/Functional/routes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hackzilla_ticket:
resource: "@HackzillaTicketBundle/Resources/config/routing.xml"
prefix: /
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down