63090d050340c585215c5d1a8a5bd7c14adfb913
[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\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler;
16 use Symfony\Component\HttpFoundation\Request;
17 use Symfony\Component\HttpFoundation\Response;
18
19 class LazyLoadingFragmentHandlerTest extends TestCase
20 {
21     public function test()
22     {
23         $renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock();
24         $renderer->expects($this->once())->method('getName')->will($this->returnValue('foo'));
25         $renderer->expects($this->any())->method('render')->will($this->returnValue(new Response()));
26
27         $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
28         $requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue(Request::create('/')));
29
30         $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
31         $container->expects($this->once())->method('get')->will($this->returnValue($renderer));
32
33         $handler = new LazyLoadingFragmentHandler($container, $requestStack, false);
34         $handler->addRendererService('foo', 'foo');
35
36         $handler->render('/foo', 'foo');
37
38         // second call should not lazy-load anymore (see once() above on the get() method)
39         $handler->render('/foo', 'foo');
40     }
41 }