|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <fabien@symfony.com> |
| 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 Symfony\Bundle\FrameworkBundle\Tests\Functional; |
| 13 | + |
| 14 | +use Symfony\Bundle\FrameworkBundle\Console\Application; |
| 15 | +use Symfony\Component\Console\Input\ArrayInput; |
| 16 | +use Symfony\Component\Console\Output\NullOutput; |
| 17 | +use Symfony\Component\Console\Tester\CommandTester; |
| 18 | + |
| 19 | +/** |
| 20 | + * @group functional |
| 21 | + */ |
| 22 | +class RouterDebugCommandTest extends WebTestCase |
| 23 | +{ |
| 24 | + private $application; |
| 25 | + |
| 26 | + protected function setUp() |
| 27 | + { |
| 28 | + $kernel = static::createKernel(array('test_case' => 'RouterDebug', 'root_config' => 'config.yml')); |
| 29 | + $this->application = new Application($kernel); |
| 30 | + $this->application->doRun(new ArrayInput(array()), new NullOutput()); |
| 31 | + } |
| 32 | + |
| 33 | + public function testDumpAllRoutes() |
| 34 | + { |
| 35 | + $tester = $this->createCommandTester(); |
| 36 | + $ret = $tester->execute(array()); |
| 37 | + $display = $tester->getDisplay(); |
| 38 | + |
| 39 | + $this->assertSame(0, $ret, 'Returns 0 in case of success'); |
| 40 | + $this->assertContains('routerdebug_test', $display); |
| 41 | + $this->assertContains('/test', $display); |
| 42 | + $this->assertContains('/session', $display); |
| 43 | + } |
| 44 | + |
| 45 | + public function testDumpOneRoutes() |
| 46 | + { |
| 47 | + $tester = $this->createCommandTester(); |
| 48 | + $ret = $tester->execute(array('name' => 'routerdebug_session_welcome')); |
| 49 | + |
| 50 | + $this->assertSame(0, $ret, 'Returns 0 in case of success'); |
| 51 | + $this->assertContains('+--------------+---------------------------------------------------------------------------------------------------------------+ |
| 52 | +| Property | Value | |
| 53 | ++--------------+---------------------------------------------------------------------------------------------------------------+ |
| 54 | +| Route Name | routerdebug_session_welcome | |
| 55 | +| Path | /session | |
| 56 | +| Path Regex | #^/session$#sD | |
| 57 | +| Host | ANY | |
| 58 | +| Host Regex | | |
| 59 | +| Scheme | ANY | |
| 60 | +| Method | ANY | |
| 61 | +| Requirements | NO CUSTOM | |
| 62 | +| Class | Symfony\Component\Routing\Route | |
| 63 | +| Defaults | _controller: FrameworkBundle:Session:welcome | |
| 64 | +| Options | compiler_class: Symfony\Component\Routing\RouteCompiler | |
| 65 | +| Callable | Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\SessionController::welcomeAction | |
| 66 | ++--------------+---------------------------------------------------------------------------------------------------------------+ |
| 67 | +', $tester->getDisplay()); |
| 68 | + } |
| 69 | + |
| 70 | + public function testSearchMultipleRoutes() |
| 71 | + { |
| 72 | + $tester = $this->createCommandTester(); |
| 73 | + $tester->setInputs(array(3)); |
| 74 | + $ret = $tester->execute(array('name' => 'routerdebug'), array('interactive' => true)); |
| 75 | + |
| 76 | + $this->assertSame(0, $ret, 'Returns 0 in case of success'); |
| 77 | + $this->assertContains('Select one of the following routes to display its information:', $tester->getDisplay()); |
| 78 | + $this->assertContains('+--------------+---------------------------------------------------------------------------------------------------------------+ |
| 79 | +| Property | Value | |
| 80 | ++--------------+---------------------------------------------------------------------------------------------------------------+ |
| 81 | +| Route Name | routerdebug_test | |
| 82 | +| Path | /test | |
| 83 | +| Path Regex | #^/test$#sD | |
| 84 | +| Host | ANY | |
| 85 | +| Host Regex | | |
| 86 | +| Scheme | ANY | |
| 87 | +| Method | ANY | |
| 88 | +| Requirements | NO CUSTOM | |
| 89 | +| Class | Symfony\Component\Routing\Route | |
| 90 | +| Defaults | _controller: FrameworkBundle:Session:welcome | |
| 91 | +| Options | compiler_class: Symfony\Component\Routing\RouteCompiler | |
| 92 | +| Callable | Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\TestBundle\Controller\SessionController::welcomeAction | |
| 93 | ++--------------+---------------------------------------------------------------------------------------------------------------+ |
| 94 | +', $tester->getDisplay()); |
| 95 | + } |
| 96 | + |
| 97 | + /** |
| 98 | + * @return CommandTester |
| 99 | + */ |
| 100 | + private function createCommandTester() |
| 101 | + { |
| 102 | + $command = $this->application->find('debug:router'); |
| 103 | + |
| 104 | + return new CommandTester($command); |
| 105 | + } |
| 106 | +} |
0 commit comments