mirror of
https://github.com/twigphp/Twig.git
synced 2026-08-31 20:47:28 +00:00
fixed exception trace when an error occurs when rendering a child template
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
* 1.9.0 (2012-XX-XX)
|
||||
|
||||
* fixed exception trace when an error occurs when rendering a child template
|
||||
* added escaping strategies for CSS, URL, and HTML attributes
|
||||
* fixed nested embed tag calls
|
||||
* added the date_modify filter
|
||||
|
||||
+5
-7
@@ -156,16 +156,14 @@ class Twig_Error extends Exception
|
||||
foreach (debug_backtrace() as $trace) {
|
||||
if (isset($trace['object']) && $trace['object'] instanceof Twig_Template && 'Twig_Template' !== get_class($trace['object'])) {
|
||||
$template = $trace['object'];
|
||||
|
||||
// update template filename
|
||||
if (null === $this->filename) {
|
||||
$this->filename = $template->getTemplateName();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// update template filename
|
||||
if (null !== $template && null === $this->filename) {
|
||||
$this->filename = $template->getTemplateName();
|
||||
}
|
||||
|
||||
if (null === $template || $this->lineno > -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,6 @@ class Twig_Tests_ErrorTest extends PHPUnit_Framework_TestCase
|
||||
$twig = new Twig_Environment($loader, array('strict_variables' => true, 'debug' => true, 'cache' => false));
|
||||
|
||||
$template = $twig->loadTemplate('index');
|
||||
|
||||
try {
|
||||
$template->render(array());
|
||||
|
||||
@@ -88,6 +87,43 @@ class Twig_Tests_ErrorTest extends PHPUnit_Framework_TestCase
|
||||
$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());
|
||||
}
|
||||
}
|
||||
|
||||
public function testTwigExceptionAddsFileAndLineWhenMissingWithInheritanceOnDisk()
|
||||
{
|
||||
$loader = new Twig_Loader_Filesystem(__DIR__.'/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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
{% block content %}{% endblock %}
|
||||
@@ -0,0 +1,7 @@
|
||||
{% extends 'base.html' %}
|
||||
{% block content %}
|
||||
{{ foo.bar }}
|
||||
{% endblock %}
|
||||
{% block foo %}
|
||||
{{ foo.bar }}
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user