* 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
}
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) {
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 }}"));