templateAction example


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();

        $controller->templateAction('mytemplate')->getContent();
        $controller('mytemplate')->getContent();
    }
$response->setPublic();
        }

        return $response;
    }

    /** * @param int $statusCode The HTTP status code (200 "OK" by default) */
    public function __invoke(string $template, int $maxAge = null, int $sharedAge = null, bool $private = null, array $context = [], int $statusCode = 200): Response
    {
        return $this->templateAction($template$maxAge$sharedAge$private$context$statusCode);
    }
}
Home | Imprint | This part of the site doesn't use cookies.