Merge branch '3.2' into 3.3

* 3.2:
  Don't access private services from container aware commands (deprecated)
  Improve CircularReferenceException message
This commit is contained in:
Fabien Potencier 2017-07-04 08:29:22 +03:00
commit 8b1f4127c3
4 changed files with 48 additions and 30 deletions

View File

@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Command; namespace Symfony\Bundle\FrameworkBundle\Command;
use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper; use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@ -112,7 +113,7 @@ EOF
private function convertController(Route $route) private function convertController(Route $route)
{ {
if ($route->hasDefault('_controller')) { if ($route->hasDefault('_controller')) {
$nameParser = $this->getContainer()->get('controller_name_converter'); $nameParser = new ControllerNameParser($this->getApplication()->getKernel());
try { try {
$route->setDefault('_controller', $nameParser->build($route->getDefault('_controller'))); $route->setDefault('_controller', $nameParser->build($route->getDefault('_controller')));
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {

View File

@ -12,9 +12,10 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Command; namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application; use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand; use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Route; use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\RouteCollection;
@ -51,16 +52,15 @@ class RouterDebugCommandTest extends TestCase
*/ */
private function createCommandTester() private function createCommandTester()
{ {
$application = new Application(); $application = new Application($this->getKernel());
$command = new RouterDebugCommand(); $command = new RouterDebugCommand();
$command->setContainer($this->getContainer());
$application->add($command); $application->add($command);
return new CommandTester($application->find('debug:router')); return new CommandTester($application->find('debug:router'));
} }
private function getContainer() private function getKernel()
{ {
$routeCollection = new RouteCollection(); $routeCollection = new RouteCollection();
$routeCollection->add('foo', new Route('foo')); $routeCollection->add('foo', new Route('foo'));
@ -82,14 +82,25 @@ class RouterDebugCommandTest extends TestCase
->with('router') ->with('router')
->will($this->returnValue(true)) ->will($this->returnValue(true))
; ;
$container $container
->expects($this->any())
->method('get') ->method('get')
->will($this->returnValueMap(array( ->with('router')
array('router', 1, $router), ->willReturn($router)
array('controller_name_converter', 1, $loader), ;
)));
return $container; $kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
$kernel
->expects($this->any())
->method('getContainer')
->willReturn($container)
;
$kernel
->expects($this->once())
->method('getBundles')
->willReturn(array())
;
return $kernel;
} }
} }

View File

@ -12,10 +12,11 @@
namespace Symfony\Bundle\FrameworkBundle\Tests\Command; namespace Symfony\Bundle\FrameworkBundle\Tests\Command;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Application; use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\CommandTester; use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Bundle\FrameworkBundle\Command\RouterMatchCommand; use Symfony\Bundle\FrameworkBundle\Command\RouterMatchCommand;
use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand; use Symfony\Bundle\FrameworkBundle\Command\RouterDebugCommand;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Route; use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\RequestContext; use Symfony\Component\Routing\RequestContext;
@ -45,20 +46,14 @@ class RouterMatchCommandTest extends TestCase
*/ */
private function createCommandTester() private function createCommandTester()
{ {
$application = new Application(); $application = new Application($this->getKernel());
$application->add(new RouterMatchCommand());
$command = new RouterMatchCommand(); $application->add(new RouterDebugCommand());
$command->setContainer($this->getContainer());
$application->add($command);
$command = new RouterDebugCommand();
$command->setContainer($this->getContainer());
$application->add($command);
return new CommandTester($application->find('router:match')); return new CommandTester($application->find('router:match'));
} }
private function getContainer() private function getKernel()
{ {
$routeCollection = new RouteCollection(); $routeCollection = new RouteCollection();
$routeCollection->add('foo', new Route('foo')); $routeCollection->add('foo', new Route('foo'));
@ -81,16 +76,27 @@ class RouterMatchCommandTest extends TestCase
$container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
$container $container
->expects($this->once()) ->expects($this->atLeastOnce())
->method('has') ->method('has')
->with('router') ->with('router')
->will($this->returnValue(true)); ->will($this->returnValue(true));
$container->method('get') $container
->will($this->returnValueMap(array( ->expects($this->any())
array('router', 1, $router), ->method('get')
array('controller_name_converter', 1, $loader), ->willReturn($router);
)));
return $container; $kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
$kernel
->expects($this->any())
->method('getContainer')
->willReturn($container)
;
$kernel
->expects($this->once())
->method('getBundles')
->willReturn(array())
;
return $kernel;
} }
} }

View File

@ -192,7 +192,7 @@ abstract class AbstractNormalizer extends SerializerAwareNormalizer implements N
return call_user_func($this->circularReferenceHandler, $object); return call_user_func($this->circularReferenceHandler, $object);
} }
throw new CircularReferenceException(sprintf('A circular reference has been detected (configured limit: %d).', $this->circularReferenceLimit)); throw new CircularReferenceException(sprintf('A circular reference has been detected when serializing the object of class "%s" (configured limit: %d)', get_class($object), $this->circularReferenceLimit));
} }
/** /**