TemplateController example

/** * @author Kévin Dunglas <dunglas@gmail.com> */
class TemplateControllerTest extends TestCase
{
    public function testTwig()
    {
        $twig = $this->createMock(Environment::class);
        $twig->expects($this->exactly(2))->method('render')->willReturn('bar');

        $controller = new TemplateController($twig);

        $this->assertEquals('bar', $controller->templateAction('mytemplate')->getContent());
        $this->assertEquals('bar', $controller('mytemplate')->getContent());
    }

    public function testNoTwig()
    {
        $this->expectException(\LogicException::class);
        $this->expectExceptionMessage('You cannot use the TemplateController if the Twig Bundle is not available. Try running "composer require symfony/twig-bundle".');
        $controller = new TemplateController();

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