mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-12 02:16:41 +00:00
enhanced error reporting when the template file is an instance of SplFileInfo
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
* 1.7.0 (2012-XX-XX)
|
||||
|
||||
* enhanced error reporting when the template file is an instance of SplFileInfo
|
||||
* added Twig_Environment::mergeGlobals()
|
||||
* fixed a regression when a template only extends another one without defining any blocks
|
||||
* added compilation checks to avoid misuses of the sandbox tag
|
||||
|
||||
+6
-1
@@ -140,7 +140,12 @@ class Twig_Error extends Exception
|
||||
}
|
||||
|
||||
if (null !== $this->filename) {
|
||||
$this->message .= sprintf(' in %s', is_string($this->filename) ? '"'.$this->filename.'"' : json_encode($this->filename));
|
||||
if (is_string($this->filename) || (is_object($this->filename) && method_exists($this->filename, '__toString'))) {
|
||||
$filename = sprintf('"%s"', $this->filename);
|
||||
} else {
|
||||
$filename = json_encode($this->filename);
|
||||
}
|
||||
$this->message .= sprintf(' in %s', $filename);
|
||||
}
|
||||
|
||||
if ($this->lineno >= 0) {
|
||||
|
||||
@@ -11,6 +11,22 @@
|
||||
|
||||
class Twig_Tests_ErrorTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testErrorWithObjectFilename()
|
||||
{
|
||||
$error = new Twig_Error('foo');
|
||||
$error->setTemplateFile(new SplFileInfo(__FILE__));
|
||||
|
||||
$this->assertContains('test/Twig/Tests/ErrorTest.php', $error->getMessage());
|
||||
}
|
||||
|
||||
public function testErrorWithArrayFilename()
|
||||
{
|
||||
$error = new Twig_Error('foo');
|
||||
$error->setTemplateFile(array('foo' => 'bar'));
|
||||
|
||||
$this->assertEquals('foo in {"foo":"bar"}', $error->getMessage());
|
||||
}
|
||||
|
||||
public function testTwigExceptionAddsFileAndLineWhenMissing()
|
||||
{
|
||||
$loader = new Twig_Loader_Array(array('index' => "\n\n{{ foo.bar }}"));
|
||||
|
||||
Reference in New Issue
Block a user