From 969c5d92b30988e01f91bf16397400ed0dca5b0c Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 13 Jan 2015 18:40:19 +0100 Subject: [PATCH] [HttpKernel] fixed missing use cases --- .../FragmentRendererPass.php | 6 +-- .../FragmentRendererPassTest.php | 50 ++++++++++++++++++- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/DependencyInjection/FragmentRendererPass.php b/src/Symfony/Component/HttpKernel/DependencyInjection/FragmentRendererPass.php index 5a2f1e85b5..c0cd8d4d5d 100644 --- a/src/Symfony/Component/HttpKernel/DependencyInjection/FragmentRendererPass.php +++ b/src/Symfony/Component/HttpKernel/DependencyInjection/FragmentRendererPass.php @@ -60,13 +60,13 @@ class FragmentRendererPass implements CompilerPassInterface foreach ($tags as $tag) { if (!isset($tag['alias'])) { - trigger_error(sprintf('Service "%s" will have to define the "alias" attribute on the "%s" tag as of Symfony 3.0.', $id, $this->fragmentTag), E_USER_DEPRECATED); + trigger_error(sprintf('Service "%s" will have to define the "alias" attribute on the "%s" tag as of Symfony 3.0.', $id, $this->rendererTag), E_USER_DEPRECATED); // register the handler as a non-lazy-loaded one $definition->addMethodCall('addRenderer', array(new Reference($id))); + } else { + $definition->addMethodCall('addRendererService', array($tag['alias'], $id)); } - - $definition->addMethodCall('addRendererService', array($tag['alias'], $id)); } } } diff --git a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/FragmentRendererPassTest.php b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/FragmentRendererPassTest.php index dd18f1585c..f87bbc2c1c 100644 --- a/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/FragmentRendererPassTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/DependencyInjection/FragmentRendererPassTest.php @@ -11,12 +11,60 @@ namespace Symfony\Component\HttpKernel\Tests\DependencyInjection; +use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass; use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface; class FragmentRendererPassTest extends \PHPUnit_Framework_TestCase { + public function testLegacyFragmentRedererWithoutAlias() + { + $this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED); + + // no alias + $services = array( + 'my_content_renderer' => array(array()), + ); + + $renderer = $this->getMock('Symfony\Component\DependencyInjection\Definition'); + $renderer + ->expects($this->once()) + ->method('addMethodCall') + ->with('addRenderer', array(new Reference('my_content_renderer'))) + ; + + $definition = $this->getMock('Symfony\Component\DependencyInjection\Definition'); + $definition->expects($this->atLeastOnce()) + ->method('getClass') + ->will($this->returnValue('Symfony\Component\HttpKernel\Tests\DependencyInjection\RendererService')); + $definition + ->expects($this->once()) + ->method('isPublic') + ->will($this->returnValue(true)) + ; + + $builder = $this->getMock( + 'Symfony\Component\DependencyInjection\ContainerBuilder', + array('hasDefinition', 'findTaggedServiceIds', 'getDefinition') + ); + $builder->expects($this->any()) + ->method('hasDefinition') + ->will($this->returnValue(true)); + + // We don't test kernel.fragment_renderer here + $builder->expects($this->atLeastOnce()) + ->method('findTaggedServiceIds') + ->will($this->returnValue($services)); + + $builder->expects($this->atLeastOnce()) + ->method('getDefinition') + ->will($this->onConsecutiveCalls($renderer, $definition)); + + $pass = new FragmentRendererPass(); + $pass->process($builder); + } + /** * Tests that content rendering not implementing FragmentRendererInterface * trigger an exception. @@ -27,7 +75,7 @@ class FragmentRendererPassTest extends \PHPUnit_Framework_TestCase { // one service, not implementing any interface $services = array( - 'my_content_renderer' => array('alias' => 'foo'), + 'my_content_renderer' => array(array('alias' => 'foo')), ); $definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');