|
| 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\Tester\CommandTester; |
| 16 | + |
| 17 | +/** |
| 18 | + * @group functional |
| 19 | + */ |
| 20 | +class RouterDebugCommandTest extends WebTestCase |
| 21 | +{ |
| 22 | + private $application; |
| 23 | + |
| 24 | + protected function setUp() |
| 25 | + { |
| 26 | + $kernel = static::createKernel(array('test_case' => 'RouterDebug', 'root_config' => 'config.yml')); |
| 27 | + $this->application = new Application($kernel); |
| 28 | + } |
| 29 | + |
| 30 | + public function testDumpAllRoutes() |
| 31 | + { |
| 32 | + $tester = $this->createCommandTester(); |
| 33 | + $ret = $tester->execute(array()); |
| 34 | + $display = $tester->getDisplay(); |
| 35 | + |
| 36 | + $this->assertSame(0, $ret, 'Returns 0 in case of success'); |
| 37 | + $this->assertContains('routerdebug_test', $display); |
| 38 | + $this->assertContains('/test', $display); |
| 39 | + $this->assertContains('/session', $display); |
| 40 | + } |
| 41 | + |
| 42 | + public function testDumpOneRoute() |
| 43 | + { |
| 44 | + $tester = $this->createCommandTester(); |
| 45 | + $ret = $tester->execute(array('name' => 'routerdebug_session_welcome')); |
| 46 | + |
| 47 | + $this->assertSame(0, $ret, 'Returns 0 in case of success'); |
| 48 | + $this->assertContains('routerdebug_session_welcome', $tester->getDisplay()); |
| 49 | + $this->assertContains('/session', $tester->getDisplay()); |
| 50 | + } |
| 51 | + |
| 52 | + public function testSearchMultipleRoutes() |
| 53 | + { |
| 54 | + $tester = $this->createCommandTester(); |
| 55 | + $tester->setInputs(array(3)); |
| 56 | + $ret = $tester->execute(array('name' => 'routerdebug'), array('interactive' => true)); |
| 57 | + |
| 58 | + $this->assertSame(0, $ret, 'Returns 0 in case of success'); |
| 59 | + $this->assertContains('Select one of the matching routes:', $tester->getDisplay()); |
| 60 | + $this->assertContains('routerdebug_test', $tester->getDisplay()); |
| 61 | + $this->assertContains('/test', $tester->getDisplay()); |
| 62 | + } |
| 63 | + |
| 64 | + /** |
| 65 | + * @expectedException \InvalidArgumentException |
| 66 | + * @expectedExceptionMessage The route "gerard" does not exist. |
| 67 | + */ |
| 68 | + public function testSearchWithThrow() |
| 69 | + { |
| 70 | + $tester = $this->createCommandTester(); |
| 71 | + $tester->execute(array('name' => 'gerard'), array('interactive' => true)); |
| 72 | + } |
| 73 | + |
| 74 | + private function createCommandTester(): CommandTester |
| 75 | + { |
| 76 | + $command = $this->application->get('debug:router'); |
| 77 | + |
| 78 | + return new CommandTester($command); |
| 79 | + } |
| 80 | +} |
0 commit comments