You are here

public function LazyLoadingFragmentHandlerTest::test in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/symfony/http-kernel/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php \Symfony\Component\HttpKernel\Tests\DependencyInjection\LazyLoadingFragmentHandlerTest::test()

File

vendor/symfony/http-kernel/Tests/DependencyInjection/LazyLoadingFragmentHandlerTest.php, line 20

Class

LazyLoadingFragmentHandlerTest

Namespace

Symfony\Component\HttpKernel\Tests\DependencyInjection

Code

public function test() {
  $renderer = $this
    ->getMock('Symfony\\Component\\HttpKernel\\Fragment\\FragmentRendererInterface');
  $renderer
    ->expects($this
    ->once())
    ->method('getName')
    ->will($this
    ->returnValue('foo'));
  $renderer
    ->expects($this
    ->any())
    ->method('render')
    ->will($this
    ->returnValue(new Response()));
  $requestStack = $this
    ->getMock('Symfony\\Component\\HttpFoundation\\RequestStack');
  $requestStack
    ->expects($this
    ->any())
    ->method('getCurrentRequest')
    ->will($this
    ->returnValue(Request::create('/')));
  $container = $this
    ->getMock('Symfony\\Component\\DependencyInjection\\ContainerInterface');
  $container
    ->expects($this
    ->once())
    ->method('get')
    ->will($this
    ->returnValue($renderer));
  $handler = new LazyLoadingFragmentHandler($container, false, $requestStack);
  $handler
    ->addRendererService('foo', 'foo');
  $handler
    ->render('/foo', 'foo');

  // second call should not lazy-load anymore (see once() above on the get() method)
  $handler
    ->render('/foo', 'foo');
}