0129f3a82a520f1e2134297074b8be593aa82031
[yaffs-website] / vendor / symfony / http-kernel / Tests / DependencyInjection / FragmentRendererPassTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
13
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;
18
19 class FragmentRendererPassTest extends TestCase
20 {
21     /**
22      * Tests that content rendering not implementing FragmentRendererInterface
23      * trigger an exception.
24      *
25      * @expectedException \InvalidArgumentException
26      */
27     public function testContentRendererWithoutInterface()
28     {
29         // one service, not implementing any interface
30         $services = array(
31             'my_content_renderer' => array(array('alias' => 'foo')),
32         );
33
34         $definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
35
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));
40
41         // We don't test kernel.fragment_renderer here
42         $builder->expects($this->atLeastOnce())
43             ->method('findTaggedServiceIds')
44             ->will($this->returnValue($services));
45
46         $builder->expects($this->atLeastOnce())
47             ->method('getDefinition')
48             ->will($this->returnValue($definition));
49
50         $pass = new FragmentRendererPass();
51         $pass->process($builder);
52     }
53
54     public function testValidContentRenderer()
55     {
56         $services = array(
57             'my_content_renderer' => array(array('alias' => 'foo')),
58         );
59
60         $renderer = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
61         $renderer
62             ->expects($this->once())
63             ->method('addMethodCall')
64             ->with('addRendererService', array('foo', 'my_content_renderer'))
65         ;
66
67         $definition = $this->getMockBuilder('Symfony\Component\DependencyInjection\Definition')->getMock();
68         $definition->expects($this->atLeastOnce())
69             ->method('getClass')
70             ->will($this->returnValue('Symfony\Component\HttpKernel\Tests\DependencyInjection\RendererService'));
71         $definition
72             ->expects($this->once())
73             ->method('isPublic')
74             ->will($this->returnValue(true))
75         ;
76
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));
81
82         // We don't test kernel.fragment_renderer here
83         $builder->expects($this->atLeastOnce())
84             ->method('findTaggedServiceIds')
85             ->will($this->returnValue($services));
86
87         $builder->expects($this->atLeastOnce())
88             ->method('getDefinition')
89             ->will($this->onConsecutiveCalls($renderer, $definition));
90
91         $pass = new FragmentRendererPass();
92         $pass->process($builder);
93     }
94 }
95
96 class RendererService implements FragmentRendererInterface
97 {
98     public function render($uri, Request $request = null, array $options = array())
99     {
100     }
101
102     public function getName()
103     {
104         return 'test';
105     }
106 }