FragmentHandler example


        $renderer = $this->getFragmentHandler($this->returnValue(new Response('html')));

        $response = $this->renderTemplate($renderer);

        $this->assertEquals('html', $response);
    }

    public function testUnknownFragmentRenderer()
    {
        $context = $this->createMock(RequestStack::class);
        $renderer = new FragmentHandler($context);

        $this->expectException(\InvalidArgumentException::class);
        $this->expectExceptionMessage('The "inline" renderer does not exist.');

        $renderer->render('/foo');
    }

    public function testGenerateFragmentUri()
    {
        $requestStack = new RequestStack();
        $requestStack->push(Request::create('/'));

        
$this->requestStack = $this->createMock(RequestStack::class);
        $this->requestStack
            ->expects($this->any())
            ->method('getCurrentRequest')
            ->willReturn(Request::create('/'))
        ;
    }

    public function testRenderWhenRendererDoesNotExist()
    {
        $this->expectException(\InvalidArgumentException::class);
        $handler = new FragmentHandler($this->requestStack);
        $handler->render('/', 'foo');
    }

    public function testRenderWithUnknownRenderer()
    {
        $this->expectException(\InvalidArgumentException::class);
        $handler = $this->getHandler($this->returnValue(new Response('foo')));

        $handler->render('/', 'bar');
    }

    
Home | Imprint | This part of the site doesn't use cookies.