LazyLoadingFragmentHandlerTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\HttpFoundation\Response;
  14. use Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler;
  15. class LazyLoadingFragmentHandlerTest extends TestCase
  16. {
  17. public function testRender()
  18. {
  19. $renderer = $this->getMockBuilder('Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface')->getMock();
  20. $renderer->expects($this->once())->method('getName')->will($this->returnValue('foo'));
  21. $renderer->expects($this->any())->method('render')->will($this->returnValue(new Response()));
  22. $requestStack = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestStack')->getMock();
  23. $requestStack->expects($this->any())->method('getCurrentRequest')->will($this->returnValue(Request::create('/')));
  24. $container = $this->getMockBuilder('Psr\Container\ContainerInterface')->getMock();
  25. $container->expects($this->once())->method('has')->with('foo')->willReturn(true);
  26. $container->expects($this->once())->method('get')->will($this->returnValue($renderer));
  27. $handler = new LazyLoadingFragmentHandler($container, $requestStack, false);
  28. $handler->render('/foo', 'foo');
  29. // second call should not lazy-load anymore (see once() above on the get() method)
  30. $handler->render('/foo', 'foo');
  31. }
  32. }