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\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler;
16 use Symfony\Component\HttpFoundation\Request;
17 use Symfony\Component\HttpFoundation\Response;
19 class LazyLoadingFragmentHandlerTest extends TestCase
21 public function test()
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()));
27 $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
28 $requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue(Request::create('/')));
30 $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
31 $container->expects($this->once())->method('get')->will($this->returnValue($renderer));
33 $handler = new LazyLoadingFragmentHandler($container, $requestStack, false);
34 $handler->addRendererService('foo', 'foo');
36 $handler->render('/foo', 'foo');
38 // second call should not lazy-load anymore (see once() above on the get() method)
39 $handler->render('/foo', 'foo');