Skip to content
Advertisement

Twig Template Unit Testing

I began to think about Continuous Integration for the twig templates in Symfony.

  1. A template is independent logic.
  2. There are mistakes in the templates. But in the process of development I do not want to be distracted by visual inspection.

Are there any ready-made solutions for unit testing a twig file in symphony?

Advertisement

Answer

Inside a WebTestCase (extension of a phpunit TestCase since Symfony 2.0) / KernelTestCase (extension of phpunit TestCase since Symfony 2.5)

    $twig = self::$kernel->getContainer()->get('twig');
    $html = $twig->render('AppBundle::app/something.html.twig', ['content' => 'I am some variable value']);
    self::assertEquals($html, $response->getContent());

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement