You are here

public function Twig_Tests_ErrorTest::testTwigExceptionAddsFileAndLineWhenMissingWithInheritanceOnDisk 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::testTwigExceptionAddsFileAndLineWhenMissingWithInheritanceOnDisk()

File

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

Class

Twig_Tests_ErrorTest

Code

public function testTwigExceptionAddsFileAndLineWhenMissingWithInheritanceOnDisk() {
  $loader = new Twig_Loader_Filesystem(dirname(__FILE__) . '/Fixtures/errors');
  $twig = new Twig_Environment($loader, array(
    'strict_variables' => true,
    'debug' => true,
    'cache' => false,
  ));
  $template = $twig
    ->loadTemplate('index.html');
  try {
    $template
      ->render(array());
    $this
      ->fail();
  } catch (Twig_Error_Runtime $e) {
    $this
      ->assertEquals('Variable "foo" does not exist in "index.html" at line 3', $e
      ->getMessage());
    $this
      ->assertEquals(3, $e
      ->getTemplateLine());
    $this
      ->assertEquals('index.html', $e
      ->getTemplateFile());
  }
  try {
    $template
      ->render(array(
      'foo' => new Twig_Tests_ErrorTest_Foo(),
    ));
    $this
      ->fail();
  } catch (Twig_Error_Runtime $e) {
    $this
      ->assertEquals('An exception has been thrown during the rendering of a template ("Runtime error...") in "index.html" at line 3.', $e
      ->getMessage());
    $this
      ->assertEquals(3, $e
      ->getTemplateLine());
    $this
      ->assertEquals('index.html', $e
      ->getTemplateFile());
  }
}