public function testTwigExceptionAddsFileAndLineWhenMissingWithInheritance() {
$loader = new Twig_Loader_Array(array(
'index' => "{% extends 'base' %}\n {% block content %}\n {{ foo.bar }}\n {% endblock %}\n {% block foo %}\n {{ foo.bar }}\n {% endblock %}",
'base' => '{% block content %}{% endblock %}',
));
$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('Variable "foo" does not exist in "index" at line 3', $e
->getMessage());
$this
->assertEquals(3, $e
->getTemplateLine());
$this
->assertEquals('index', $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" at line 3.', $e
->getMessage());
$this
->assertEquals(3, $e
->getTemplateLine());
$this
->assertEquals('index', $e
->getTemplateFile());
}
}