|
| 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 | +} |
0 commit comments