95baaa54c133cd5fdb6a7e90af739c8ebdae0726
[yaffs-website] / vendor / symfony / http-kernel / Tests / DependencyInjection / LazyLoadingFragmentHandlerTest.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\HttpFoundation\Response;
17 use Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler;
18
19 class LazyLoadingFragmentHandlerTest extends TestCase
20 {
21     /**
22      * @group legacy
23      * @expectedDeprecation The Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler::addRendererService() method is deprecated since Symfony 3.3 and will be removed in 4.0.
24      */
25     public function testRenderWithLegacyMapping()
26     {
27         $renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock();
28         $renderer->expects($this->once())->method('getName')->will($this->returnValue('foo'));
29         $renderer->expects($this->any())->method('render')->will($this->returnValue(new Response()));
30
31         $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
32         $requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue(Request::create('/')));
33
34         $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
35         $container->expects($this->once())->method('get')->will($this->returnValue($renderer));
36
37         $handler = new LazyLoadingFragmentHandler($container, $requestStack, false);
38         $handler->addRendererService('foo', 'foo');
39
40         $handler->render('/foo', 'foo');
41
42         // second call should not lazy-load anymore (see once() above on the get() method)
43         $handler->render('/foo', 'foo');
44     }
45
46     public function testRender()
47     {
48         $renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock();
49         $renderer->expects($this->once())->method('getName')->will($this->returnValue('foo'));
50         $renderer->expects($this->any())->method('render')->will($this->returnValue(new Response()));
51
52         $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
53         $requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue(Request::create('/')));
54
55         $container = $this->getMockBuilder('Psr\Container\ContainerInterface')->getMock();
56         $container->expects($this->once())->method('has')->with('foo')->willReturn(true);
57         $container->expects($this->once())->method('get')->will($this->returnValue($renderer));
58
59         $handler = new LazyLoadingFragmentHandler($container, $requestStack, false);
60
61         $handler->render('/foo', 'foo');
62
63         // second call should not lazy-load anymore (see once() above on the get() method)
64         $handler->render('/foo', 'foo');
65     }
66 }