4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\DependencyInjection\Reference;
16 use Symfony\Component\HttpFoundation\Request;
17 use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
18 use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;
20 class FragmentRendererPassTest extends TestCase
25 public function testLegacyFragmentRedererWithoutAlias()
29 'my_content_renderer' => array(array()),
32 $renderer = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
34 ->expects($this->once())
35 ->method('addMethodCall')
36 ->with('addRenderer', array(new Reference('my_content_renderer')))
39 $definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
40 $definition->expects($this->atLeastOnce())
42 ->will($this->returnValue('Symfony\Component\HttpKernel\Tests\DependencyInjection\RendererService'));
44 ->expects($this->once())
46 ->will($this->returnValue(true))
49 $builder = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock();
50 $builder->expects($this->any())
51 ->method('hasDefinition')
52 ->will($this->returnValue(true));
54 // We don't test kernel.fragment_renderer here
55 $builder->expects($this->atLeastOnce())
56 ->method('findTaggedServiceIds')
57 ->will($this->returnValue($services));
59 $builder->expects($this->atLeastOnce())
60 ->method('getDefinition')
61 ->will($this->onConsecutiveCalls($renderer, $definition));
63 $pass = new FragmentRendererPass();
64 $pass->process($builder);
68 * Tests that content rendering not implementing FragmentRendererInterface
69 * trigger an exception.
71 * @expectedException \InvalidArgumentException
73 public function testContentRendererWithoutInterface()
75 // one service, not implementing any interface
77 'my_content_renderer' => array(array('alias' => 'foo')),
80 $definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
82 $builder = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock();
83 $builder->expects($this->any())
84 ->method('hasDefinition')
85 ->will($this->returnValue(true));
87 // We don't test kernel.fragment_renderer here
88 $builder->expects($this->atLeastOnce())
89 ->method('findTaggedServiceIds')
90 ->will($this->returnValue($services));
92 $builder->expects($this->atLeastOnce())
93 ->method('getDefinition')
94 ->will($this->returnValue($definition));
96 $pass = new FragmentRendererPass();
97 $pass->process($builder);
100 public function testValidContentRenderer()
103 'my_content_renderer' => array(array('alias' => 'foo')),
106 $renderer = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
108 ->expects($this->once())
109 ->method('addMethodCall')
110 ->with('addRendererService', array('foo', 'my_content_renderer'))
113 $definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
114 $definition->expects($this->atLeastOnce())
116 ->will($this->returnValue('Symfony\Component\HttpKernel\Tests\DependencyInjection\RendererService'));
118 ->expects($this->once())
120 ->will($this->returnValue(true))
123 $builder = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock();
124 $builder->expects($this->any())
125 ->method('hasDefinition')
126 ->will($this->returnValue(true));
128 // We don't test kernel.fragment_renderer here
129 $builder->expects($this->atLeastOnce())
130 ->method('findTaggedServiceIds')
131 ->will($this->returnValue($services));
133 $builder->expects($this->atLeastOnce())
134 ->method('getDefinition')
135 ->will($this->onConsecutiveCalls($renderer, $definition));
137 $pass = new FragmentRendererPass();
138 $pass->process($builder);
142 class RendererService implements FragmentRendererInterface
144 public function render($uri, Request $request = null, array $options = array())
148 public function getName()