You are here

public function Twig_Tests_ErrorTest::testTwigExceptionAddsFileAndLine in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/twig/twig/test/Twig/Tests/ErrorTest.php \Twig_Tests_ErrorTest::testTwigExceptionAddsFileAndLine()

@dataProvider getErroredTemplates

File

vendor/twig/twig/test/Twig/Tests/ErrorTest.php, line 60

Class

Twig_Tests_ErrorTest

Code

public function testTwigExceptionAddsFileAndLine($templates, $name, $line) {
  $loader = new Twig_Loader_Array($templates);
  $twig = new Twig_Environment($loader, array(
    'strict_variables' => true,
    'debug' => true,
    'cache' => false,
  ));
  $template = $twig
    ->loadTemplate('index');
  try {
    $template
      ->render(array());
    $this
      ->fail();
  } catch (Twig_Error_Runtime $e) {
    $this
      ->assertEquals(sprintf('Variable "foo" does not exist in "%s" at line %d', $name, $line), $e
      ->getMessage());
    $this
      ->assertEquals($line, $e
      ->getTemplateLine());
    $this
      ->assertEquals($name, $e
      ->getTemplateFile());
  }
  try {
    $template
      ->render(array(
      'foo' => new Twig_Tests_ErrorTest_Foo(),
    ));
    $this
      ->fail();
  } catch (Twig_Error_Runtime $e) {
    $this
      ->assertEquals(sprintf('An exception has been thrown during the rendering of a template ("Runtime error...") in "%s" at line %d.', $name, $line), $e
      ->getMessage());
    $this
      ->assertEquals($line, $e
      ->getTemplateLine());
    $this
      ->assertEquals($name, $e
      ->getTemplateFile());
  }
}