Skip to content

Commit 62921fd

Browse files
committed
minor #203 Added XML routing (phansys)
This PR was merged into the 3.x branch. Discussion ---------- |Q |A | |--- |---| |Branch |3.x| |Bug fix? |no | |New feature? |no | |BC breaks? |no | |Deprecations?|no | |Tests pass? |yes| |Fixed tickets|n/a| |License |MIT| |Doc PR |n/a| Commits ------- 1d7007e Added XML routing
2 parents 6270125 + 1d7007e commit 62921fd

File tree

8 files changed

+85
-2
lines changed

8 files changed

+85
-2
lines changed

Resources/config/routing.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<import resource="./routing/hackzilla_ticket.xml" type="xml" prefix="/ticket"/>
4+
</routes>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<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">
3+
<route id="hackzilla_ticket" path="/" controller="Hackzilla\Bundle\TicketBundle\Controller\TicketController::indexAction"/>
4+
<route id="hackzilla_ticket_show" path="/{ticketId}/show" controller="Hackzilla\Bundle\TicketBundle\Controller\TicketController::showAction"/>
5+
<route id="hackzilla_ticket_new" path="/new" controller="Hackzilla\Bundle\TicketBundle\Controller\TicketController::newAction"/>
6+
<route id="hackzilla_ticket_create" path="/create" controller="Hackzilla\Bundle\TicketBundle\Controller\TicketController::createAction" methods="POST"/>
7+
<route id="hackzilla_ticket_delete" path="/{ticketId}/delete" controller="Hackzilla\Bundle\TicketBundle\Controller\TicketController::deleteAction" methods="DELETE|POST"/>
8+
<route id="hackzilla_ticket_reply" path="/{ticketId}/reply" controller="Hackzilla\Bundle\TicketBundle\Controller\TicketController::replyAction"/>
9+
<route id="hackzilla_ticket_attachment" path="/attachment/{ticketMessageId}/download" controller="Hackzilla\Bundle\TicketBundle\Controller\TicketAttachmentController::downloadAction"/>
10+
</routes>

Resources/config/routing/ticket.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# NEXT_MAJOR: remove this file and add upgrade note.
12
hackzilla_ticket:
23
path: /
34
controller: 'Hackzilla\Bundle\TicketBundle\Controller\TicketController::indexAction'

Resources/doc/setup/install.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ public function registerBundles()
6969

7070
``` yml
7171
hackzilla_ticket:
72-
resource: "@HackzillaTicketBundle/Resources/config/routing.yml"
72+
resource: "@HackzillaTicketBundle/Resources/config/routing.xml"
7373
prefix: /
7474
```
7575

7676
or
7777

7878
``` yml
7979
hackzilla_ticket:
80-
resource: "@HackzillaTicketBundle/Resources/config/routing/ticket.yml"
80+
resource: "@HackzillaTicketBundle/Resources/config/routing/hackzilla_ticket.xml"
8181
prefix: /ticket
8282
```
8383

Tests/Functional/RoutingTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
/*
4+
* This file is part of HackzillaTicketBundle package.
5+
*
6+
* (c) Daniel Platt <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Hackzilla\Bundle\TicketBundle\Tests\Functional;
13+
14+
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
15+
16+
/**
17+
* @author Javier Spagnoletti <[email protected]>
18+
*/
19+
final class RoutingTest extends WebTestCase
20+
{
21+
/**
22+
* @dataProvider getRoutes
23+
*/
24+
public function testRoutes(string $name, string $path, array $methods): void
25+
{
26+
$client = static::createClient();
27+
$router = $client->getContainer()->get('router');
28+
29+
$route = $router->getRouteCollection()->get($name);
30+
31+
$this->assertNotNull($route);
32+
$this->assertSame($path, $route->getPath());
33+
$this->assertEmpty(array_diff($methods, $route->getMethods()));
34+
35+
$matcher = $router->getMatcher();
36+
$requestContext = $router->getContext();
37+
38+
foreach ($methods as $method) {
39+
$requestContext->setMethod($method);
40+
$match = $matcher->match($path);
41+
42+
$this->assertSame($name, $match['_route']);
43+
}
44+
}
45+
46+
public function getRoutes(): iterable
47+
{
48+
yield ['hackzilla_ticket', '/ticket/', []];
49+
yield ['hackzilla_ticket_show', '/ticket/{ticketId}/show', []];
50+
yield ['hackzilla_ticket_new', '/ticket/new', []];
51+
yield ['hackzilla_ticket_create', '/ticket/create', ['POST']];
52+
yield ['hackzilla_ticket_delete', '/ticket/{ticketId}/delete', ['DELETE', 'POST']];
53+
yield ['hackzilla_ticket_reply', '/ticket/{ticketId}/reply', []];
54+
yield ['hackzilla_ticket_attachment', '/ticket/attachment/{ticketMessageId}/download', []];
55+
}
56+
57+
protected static function getKernelClass(): string
58+
{
59+
return TestKernel::class;
60+
}
61+
}

Tests/Functional/TestKernel.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function getLogDir()
8484
*/
8585
protected function configureRoutes(RouteCollectionBuilder $routes)
8686
{
87+
$routes->import(__DIR__.'/routes.yaml', '/', 'yaml');
8788
}
8889

8990
/**
@@ -109,6 +110,7 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
109110
'validation' => [
110111
'enabled' => true,
111112
],
113+
'test' => true,
112114
]);
113115

114116
// SecurityBundle config

Tests/Functional/routes.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
hackzilla_ticket:
2+
resource: "@HackzillaTicketBundle/Resources/config/routing.xml"
3+
prefix: /

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
"ext-pdo_sqlite": "*",
5353
"friendsofphp/php-cs-fixer": "^2.0",
5454
"phpstan/phpstan": "^0.12.32",
55+
"symfony/browser-kit": "^4.4 || ^5.2",
56+
"symfony/http-client": "^4.4 || ^5.2",
5557
"symfony/phpunit-bridge": "^5.1.1",
5658
"symfony/security": "^4.4"
5759
},

0 commit comments

Comments
 (0)