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\HttpFoundation\Response;
17 use Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler;
19 class LazyLoadingFragmentHandlerTest extends TestCase
23 * @expectedDeprecation The Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler::addRendererService() method is deprecated since Symfony 3.3 and will be removed in 4.0.
25 public function testRenderWithLegacyMapping()
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()));
31 $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
32 $requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue(Request::create('/')));
34 $container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
35 $container->expects($this->once())->method('get')->will($this->returnValue($renderer));
37 $handler = new LazyLoadingFragmentHandler($container, $requestStack, false);
38 $handler->addRendererService('foo', 'foo');
40 $handler->render('/foo', 'foo');
42 // second call should not lazy-load anymore (see once() above on the get() method)
43 $handler->render('/foo', 'foo');
46 public function testRender()
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()));
52 $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
53 $requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue(Request::create('/')));
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));
59 $handler = new LazyLoadingFragmentHandler($container, $requestStack, false);
61 $handler->render('/foo', 'foo');
63 // second call should not lazy-load anymore (see once() above on the get() method)
64 $handler->render('/foo', 'foo');