diff --git a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php index a08c1a352197f..4f73da2cc7614 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php +++ b/src/Symfony/Bundle/FrameworkBundle/Command/RouterDebugCommand.php @@ -29,6 +29,15 @@ */ class RouterDebugCommand extends ContainerAwareCommand { + private $controllerNameParser; + + public function __construct(ControllerNameParser $controllerNameParser = null) + { + parent::__construct(); + + $this->controllerNameParser = $controllerNameParser; + } + /** * {@inheritdoc} */ @@ -110,10 +119,12 @@ protected function execute(InputInterface $input, OutputInterface $output) private function convertController(Route $route) { - $nameParser = new ControllerNameParser($this->getApplication()->getKernel()); if ($route->hasDefault('_controller')) { + if (null === $this->controllerNameParser) { + $this->controllerNameParser = new ControllerNameParser($this->getApplication()->getKernel()); + } try { - $route->setDefault('_controller', $nameParser->build($route->getDefault('_controller'))); + $route->setDefault('_controller', $this->controllerNameParser->build($route->getDefault('_controller'))); } catch (\InvalidArgumentException $e) { } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml index 6050686d6c3c5..613eb68539c0c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml @@ -98,5 +98,11 @@ + + + + + + diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php index 597082485a0b6..27871ed1d0a67 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterDebugCommandTest.php @@ -12,7 +12,8 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Command; use PHPUnit\Framework\TestCase; -use Symfony\Bundle\FrameworkBundle\Console\Application; +use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser; +use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand; use Symfony\Component\HttpKernel\KernelInterface; @@ -52,15 +53,16 @@ public function testDebugInvalidRoute() */ private function createCommandTester() { - $application = new Application($this->getKernel()); + $application = new Application(); - $command = new RouterDebugCommand(); + $command = new RouterDebugCommand(new ControllerNameParser($this->getMockBuilder(KernelInterface::class)->getMock())); + $command->setContainer($this->getContainer()); $application->add($command); return new CommandTester($application->find('debug:router')); } - private function getKernel() + private function getContainer() { $routeCollection = new RouteCollection(); $routeCollection->add('foo', new Route('foo')); @@ -82,25 +84,14 @@ private function getKernel() ->with('router') ->will($this->returnValue(true)) ; + $container - ->expects($this->any()) ->method('get') - ->with('router') - ->willReturn($router) - ; - - $kernel = $this->getMockBuilder(KernelInterface::class)->getMock(); - $kernel - ->expects($this->any()) - ->method('getContainer') - ->willReturn($container) - ; - $kernel - ->expects($this->once()) - ->method('getBundles') - ->willReturn(array()) - ; + ->will($this->returnValueMap(array( + array('router', 1, $router), + array('controller_name_converter', 1, $loader), + ))); - return $kernel; + return $container; } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php index 384bd7ca53079..4a8b571a383e3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Command/RouterMatchCommandTest.php @@ -12,7 +12,8 @@ namespace Symfony\Bundle\FrameworkBundle\Tests\Command; use PHPUnit\Framework\TestCase; -use Symfony\Bundle\FrameworkBundle\Console\Application; +use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser; +use Symfony\Component\Console\Application; use Symfony\Component\Console\Tester\CommandTester; use Symfony\Bundle\FrameworkBundle\Command\RouterMatchCommand; use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand; @@ -46,14 +47,20 @@ public function testWithNotMatchPath() */ private function createCommandTester() { - $application = new Application($this->getKernel()); - $application->add(new RouterMatchCommand()); - $application->add(new RouterDebugCommand()); + $application = new Application(); + + $command = new RouterMatchCommand(); + $command->setContainer($this->getContainer()); + $application->add($command); + + $command = new RouterDebugCommand(new ControllerNameParser($this->getMockBuilder(KernelInterface::class)->getMock())); + $command->setContainer($this->getContainer()); + $application->add($command); return new CommandTester($application->find('router:match')); } - private function getKernel() + private function getContainer() { $routeCollection = new RouteCollection(); $routeCollection->add('foo', new Route('foo')); @@ -76,27 +83,16 @@ private function getKernel() $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $container - ->expects($this->atLeastOnce()) + ->expects($this->once()) ->method('has') ->with('router') ->will($this->returnValue(true)); - $container - ->expects($this->any()) - ->method('get') - ->willReturn($router); - - $kernel = $this->getMockBuilder(KernelInterface::class)->getMock(); - $kernel - ->expects($this->any()) - ->method('getContainer') - ->willReturn($container) - ; - $kernel - ->expects($this->once()) - ->method('getBundles') - ->willReturn(array()) - ; + $container->method('get') + ->will($this->returnValueMap(array( + array('router', 1, $router), + array('controller_name_converter', 1, $loader), + ))); - return $kernel; + return $container; } }