LazyLoadingFragmentHandlerTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 Psr\Container\ContainerInterface;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\RequestStack;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\HttpKernel\DependencyInjection\LazyLoadingFragmentHandler;
  17. use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;
  18. class LazyLoadingFragmentHandlerTest extends TestCase
  19. {
  20. public function testRender()
  21. {
  22. $renderer = $this->createMock(FragmentRendererInterface::class);
  23. $renderer->expects($this->once())->method('getName')->willReturn('foo');
  24. $renderer->expects($this->any())->method('render')->willReturn(new Response());
  25. $requestStack = $this->createMock(RequestStack::class);
  26. $requestStack->expects($this->any())->method('getCurrentRequest')->willReturn(Request::create('/'));
  27. $container = $this->createMock(ContainerInterface::class);
  28. $container->expects($this->once())->method('has')->with('foo')->willReturn(true);
  29. $container->expects($this->once())->method('get')->willReturn($renderer);
  30. $handler = new LazyLoadingFragmentHandler($container, $requestStack, false);
  31. $handler->render('/foo', 'foo');
  32. // second call should not lazy-load anymore (see once() above on the get() method)
  33. $handler->render('/foo', 'foo');
  34. }
  35. }