Navigation Menu

Skip to content

Commit

Permalink
bug #23366 [FrameworkBundle] Don't get() private services from debug:…
Browse files Browse the repository at this point in the history
…router (chalasr)

This PR was merged into the 3.2 branch.

Discussion
----------

[FrameworkBundle] Don't get() private services from debug:router

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

Fixes
> php.INFO: User Deprecated: Requesting the "controller_name_converter" private service is deprecated since Symfony 3.2 and won't be supported anymore in Symfony 4.0. {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\ContextErrorException(code: 0): User Deprecated: Requesting the \"controller_name_converter\" private service is deprecated since Symfony 3.2 and won't be supported anymore in Symfony 4.0. at /tmp/name_parser/vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php:260)"}

Commits
-------

08a6178 Don't access private services from container aware commands (deprecated)
  • Loading branch information
fabpot committed Jul 4, 2017
2 parents 5d797b2 + 08a6178 commit d01e2d1
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 29 deletions.
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Command;

use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -109,7 +110,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

private function convertController(Route $route)
{
$nameParser = $this->getContainer()->get('controller_name_converter');
$nameParser = new ControllerNameParser($this->getApplication()->getKernel());
if ($route->hasDefault('_controller')) {
try {
$route->setDefault('_controller', $nameParser->build($route->getDefault('_controller')));
Expand Down
Expand Up @@ -12,9 +12,10 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;

Expand Down Expand Up @@ -51,16 +52,15 @@ public function testDebugInvalidRoute()
*/
private function createCommandTester()
{
$application = new Application();
$application = new Application($this->getKernel());

$command = new RouterDebugCommand();
$command->setContainer($this->getContainer());
$application->add($command);

return new CommandTester($application->find('debug:router'));
}

private function getContainer()
private function getKernel()
{
$routeCollection = new RouteCollection();
$routeCollection->add('foo', new Route('foo'));
Expand All @@ -82,14 +82,25 @@ private function getContainer()
->with('router')
->will($this->returnValue(true))
;

$container
->expects($this->any())
->method('get')
->will($this->returnValueMap(array(
array('router', 1, $router),
array('controller_name_converter', 1, $loader),
)));
->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())
;

return $container;
return $kernel;
}
}
Expand Up @@ -12,10 +12,11 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Command;

use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Bundle\FrameworkBundle\Command\RouterMatchCommand;
use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RequestContext;
Expand Down Expand Up @@ -45,20 +46,14 @@ public function testWithNotMatchPath()
*/
private function createCommandTester()
{
$application = new Application();

$command = new RouterMatchCommand();
$command->setContainer($this->getContainer());
$application->add($command);

$command = new RouterDebugCommand();
$command->setContainer($this->getContainer());
$application->add($command);
$application = new Application($this->getKernel());
$application->add(new RouterMatchCommand());
$application->add(new RouterDebugCommand());

return new CommandTester($application->find('router:match'));
}

private function getContainer()
private function getKernel()
{
$routeCollection = new RouteCollection();
$routeCollection->add('foo', new Route('foo'));
Expand All @@ -81,16 +76,27 @@ private function getContainer()

$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container
->expects($this->once())
->expects($this->atLeastOnce())
->method('has')
->with('router')
->will($this->returnValue(true));
$container->method('get')
->will($this->returnValueMap(array(
array('router', 1, $router),
array('controller_name_converter', 1, $loader),
)));
$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())
;

return $container;
return $kernel;
}
}

0 comments on commit d01e2d1

Please sign in to comment.