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\HttpFoundation\Request;
16 use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
17 use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;
19 class FragmentRendererPassTest extends TestCase
22 * Tests that content rendering not implementing FragmentRendererInterface
23 * trigger an exception.
25 * @expectedException \InvalidArgumentException
27 public function testContentRendererWithoutInterface()
29 // one service, not implementing any interface
31 'my_content_renderer' => array(array('alias' => 'foo')),
34 $definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
36 $builder = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock();
37 $builder->expects($this->any())
38 ->method('hasDefinition')
39 ->will($this->returnValue(true));
41 // We don't test kernel.fragment_renderer here
42 $builder->expects($this->atLeastOnce())
43 ->method('findTaggedServiceIds')
44 ->will($this->returnValue($services));
46 $builder->expects($this->atLeastOnce())
47 ->method('getDefinition')
48 ->will($this->returnValue($definition));
50 $pass = new FragmentRendererPass();
51 $pass->process($builder);
54 public function testValidContentRenderer()
57 'my_content_renderer' => array(array('alias' => 'foo')),
60 $renderer = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
62 ->expects($this->once())
63 ->method('addMethodCall')
64 ->with('addRendererService', array('foo', 'my_content_renderer'))
67 $definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
68 $definition->expects($this->atLeastOnce())
70 ->will($this->returnValue('Symfony\Component\HttpKernel\Tests\DependencyInjection\RendererService'));
72 ->expects($this->once())
74 ->will($this->returnValue(true))
77 $builder = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder')->setMethods(array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'))->getMock();
78 $builder->expects($this->any())
79 ->method('hasDefinition')
80 ->will($this->returnValue(true));
82 // We don't test kernel.fragment_renderer here
83 $builder->expects($this->atLeastOnce())
84 ->method('findTaggedServiceIds')
85 ->will($this->returnValue($services));
87 $builder->expects($this->atLeastOnce())
88 ->method('getDefinition')
89 ->will($this->onConsecutiveCalls($renderer, $definition));
91 $pass = new FragmentRendererPass();
92 $pass->process($builder);
96 class RendererService implements FragmentRendererInterface
98 public function render($uri, Request $request = null, array $options = array())
102 public function getName()