Skip to content

Instantly share code, notes, and snippets.

@fabpot
Created July 30, 2014 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabpot/cc2e79d138badf7c3a94 to your computer and use it in GitHub Desktop.
Save fabpot/cc2e79d138badf7c3a94 to your computer and use it in GitHub Desktop.
commit e1f188b522c05f2c0e1695603c8034cf751f8550
Author: Fabien Potencier <fabien.potencier@gmail.com>
Date: Wed Sep 26 00:54:25 2012 +0200
modified Twig_Error_* exceptions to override exception filename and line with the original template filename and line
diff --git a/CHANGELOG b/CHANGELOG
index 93109d0..51a6def 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,8 @@
* 2.0.0 (2012-XX-XX)
+ * [BC BREAK] modified Twig_Error_* exceptions to override exception filename
+ and line with the original template filename and line
+
* removed PEAR support
* added support for positional arguments for filters, tests, and functions
diff --git a/lib/Twig/Compiler.php b/lib/Twig/Compiler.php
index 786a75f..59ce1b3 100644
--- a/lib/Twig/Compiler.php
+++ b/lib/Twig/Compiler.php
@@ -228,6 +228,8 @@ class Twig_Compiler implements Twig_CompilerInterface
public function getDebugInfo()
{
+ ksort($this->debugInfo);
+
return $this->debugInfo;
}
diff --git a/lib/Twig/Error.php b/lib/Twig/Error.php
index 138151b..f303bce 100644
--- a/lib/Twig/Error.php
+++ b/lib/Twig/Error.php
@@ -34,10 +34,8 @@
*/
class Twig_Error extends Exception
{
- protected $lineno;
- protected $filename;
- protected $rawMessage;
- protected $previous;
+ protected $originalFile;
+ protected $originalLine;
/**
* Constructor.
@@ -52,155 +50,79 @@ class Twig_Error extends Exception
* By default, automatic guessing is enabled.
*
* @param string $message The error message
- * @param integer $lineno The template line where the error occurred
- * @param string $filename The template file name where the error occurred
+ * @param integer $line The template line where the error occurred
+ * @param string $file The template file name where the error occurred
* @param Exception $previous The previous exception
*/
- public function __construct($message, $lineno = -1, $filename = null, Exception $previous = null)
+ public function __construct($message, $line = -1, $file = null, Exception $previous = null)
{
- if (version_compare(PHP_VERSION, '5.3.0', '<')) {
- $this->previous = $previous;
- parent::__construct('');
- } else {
- parent::__construct('', 0, $previous);
- }
-
- $this->lineno = $lineno;
- $this->filename = $filename;
+ parent::__construct($message, 0, $previous);
- if (-1 === $this->lineno || null === $this->filename) {
- $this->guessTemplateInfo();
- }
+ $this->originalLine = $this->getLine();
+ $this->originalFile = $this->getFile();
- $this->rawMessage = $message;
+ $this->setTemplateFile($file);
+ $this->line = $line;
- $this->updateRepr();
+ if (-1 === $this->line || null === $this->file) {
+ $this->guess();
+ }
}
- /**
- * Gets the raw message.
- *
- * @return string The raw message
- */
- public function getRawMessage()
+ public function getOriginalFile()
{
- return $this->rawMessage;
+ return $this->originalFile;
}
- /**
- * Gets the filename where the error occurred.
- *
- * @return string The filename
- */
- public function getTemplateFile()
+ public function getOriginalLine()
{
- return $this->filename;
+ return $this->originalLine;
}
/**
* Sets the filename where the error occurred.
*
- * @param string $filename The filename
- */
- public function setTemplateFile($filename)
- {
- $this->filename = $filename;
-
- $this->updateRepr();
- }
-
- /**
- * Gets the template line where the error occurred.
- *
- * @return integer The template line
+ * @param string $file The file
*/
- public function getTemplateLine()
+ public function setTemplateFile($file)
{
- return $this->lineno;
+ if (null === $file || false === $file) {
+ $this->file = $file;
+ } elseif (is_string($file) || (is_object($file) && method_exists($file, '__toString'))) {
+ $this->file = (string) $file;
+ } else {
+ $this->file = json_encode($file);
+ }
}
/**
* Sets the template line where the error occurred.
*
- * @param integer $lineno The template line
+ * @param integer $line The template line
*/
- public function setTemplateLine($lineno)
+ public function setTemplateLine($line)
{
- $this->lineno = $lineno;
-
- $this->updateRepr();
+ $this->line = $line;
}
public function guess()
{
- $this->guessTemplateInfo();
- $this->updateRepr();
- }
-
- /**
- * For PHP < 5.3.0, provides access to the getPrevious() method.
- *
- * @param string $method The method name
- * @param array $arguments The parameters to be passed to the method
- *
- * @return Exception The previous exception or null
- *
- * @throws BadMethodCallException
- */
- public function __call($method, $arguments)
- {
- if ('getprevious' == strtolower($method)) {
- return $this->previous;
- }
-
- throw new BadMethodCallException(sprintf('Method "Twig_Error::%s()" does not exist.', $method));
- }
-
- protected function updateRepr()
- {
- $this->message = $this->rawMessage;
-
- $dot = false;
- if ('.' === substr($this->message, -1)) {
- $this->message = substr($this->message, 0, -1);
- $dot = true;
- }
-
- if ($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 && $this->lineno >= 0) {
- $this->message .= sprintf(' at line %d', $this->lineno);
- }
-
- if ($dot) {
- $this->message .= '.';
- }
- }
-
- protected function guessTemplateInfo()
- {
$template = null;
foreach (debug_backtrace() as $trace) {
if (isset($trace['object']) && $trace['object'] instanceof Twig_Template && 'Twig_Template' !== get_class($trace['object'])) {
- if (null === $this->filename || $this->filename == $trace['object']->getTemplateName()) {
+ if (!$this->file || $this->file == $trace['object']->getTemplateName()) {
$template = $trace['object'];
}
}
}
- // update template filename
- if (null !== $template && null === $this->filename) {
- $this->filename = $template->getTemplateName();
+ // update template file
+ if (null !== $template && !$this->file) {
+ $this->setTemplateFile($template->getTemplateName());
+ $this->line = -1;
}
- if (null === $template || $this->lineno > -1) {
+ if (null === $template || $this->line > 0) {
return;
}
@@ -208,7 +130,7 @@ class Twig_Error extends Exception
$file = $r->getFileName();
$exceptions = array($e = $this);
- while (($e instanceof self || method_exists($e, 'getPrevious')) && $e = $e->getPrevious()) {
+ while ($e = $e->getPrevious()) {
$exceptions[] = $e;
}
@@ -222,12 +144,15 @@ class Twig_Error extends Exception
foreach ($template->getDebugInfo() as $codeLine => $templateLine) {
if ($codeLine <= $trace['line']) {
// update template line
- $this->lineno = $templateLine;
+ $this->line = $templateLine;
return;
}
}
}
}
+
+ // unable to find the correct line (should never happen)
+ $this->line = -1;
}
}
diff --git a/lib/Twig/Node/Embed.php b/lib/Twig/Node/Embed.php
index 5edb953..309e090 100644
--- a/lib/Twig/Node/Embed.php
+++ b/lib/Twig/Node/Embed.php
@@ -29,9 +29,13 @@ class Twig_Node_Embed extends Twig_Node_Include
protected function addGetTemplate(Twig_Compiler $compiler)
{
$compiler
- ->write("\$this->env->loadTemplate(")
+ ->write("\$this->loadTemplate(")
->string($this->getAttribute('filename'))
->raw(', ')
+ ->repr($compiler->getFilename())
+ ->raw(', ')
+ ->repr($this->getLine())
+ ->raw(', ')
->string($this->getAttribute('index'))
->raw(")")
;
diff --git a/lib/Twig/Node/Import.php b/lib/Twig/Node/Import.php
index a327411..5048264 100644
--- a/lib/Twig/Node/Import.php
+++ b/lib/Twig/Node/Import.php
@@ -40,8 +40,12 @@ class Twig_Node_Import extends Twig_Node
$compiler->raw("\$this");
} else {
$compiler
- ->raw('$this->env->loadTemplate(')
+ ->raw('$this->loadTemplate(')
->subcompile($this->getNode('expr'))
+ ->raw(', ')
+ ->repr($compiler->getFilename())
+ ->raw(', ')
+ ->repr($this->getLine())
->raw(")")
;
}
diff --git a/lib/Twig/Node/Include.php b/lib/Twig/Node/Include.php
index 5b6be7a..9b784ab 100644
--- a/lib/Twig/Node/Include.php
+++ b/lib/Twig/Node/Include.php
@@ -61,20 +61,15 @@ class Twig_Node_Include extends Twig_Node implements Twig_NodeOutputInterface
protected function addGetTemplate(Twig_Compiler $compiler)
{
- if ($this->getNode('expr') instanceof Twig_Node_Expression_Constant) {
- $compiler
- ->write("\$this->env->loadTemplate(")
- ->subcompile($this->getNode('expr'))
- ->raw(")")
- ;
- } else {
- $compiler
- ->write("\$template = \$this->env->resolveTemplate(")
- ->subcompile($this->getNode('expr'))
- ->raw(");\n")
- ->write('$template')
- ;
- }
+ $compiler
+ ->write("\$this->loadTemplate(")
+ ->subcompile($this->getNode('expr'))
+ ->raw(', ')
+ ->repr($compiler->getFilename())
+ ->raw(', ')
+ ->repr($this->getLine())
+ ->raw(")")
+ ;
}
protected function addTemplateArguments(Twig_Compiler $compiler)
diff --git a/lib/Twig/Node/Module.php b/lib/Twig/Node/Module.php
index 497696a..a3975aa 100644
--- a/lib/Twig/Node/Module.php
+++ b/lib/Twig/Node/Module.php
@@ -90,8 +90,12 @@ class Twig_Node_Module extends Twig_Node
$compiler->subcompile($this->getNode('parent'));
} else {
$compiler
- ->raw("\$this->env->resolveTemplate(")
+ ->raw("\$this->loadTemplate(")
->subcompile($this->getNode('parent'))
+ ->raw(', ')
+ ->repr($compiler->getFilename())
+ ->raw(', ')
+ ->repr($this->getLine())
->raw(")")
;
}
@@ -138,8 +142,12 @@ class Twig_Node_Module extends Twig_Node
$compiler->write("\$this->parent = false;\n\n");
} elseif ($this->getNode('parent') instanceof Twig_Node_Expression_Constant) {
$compiler
- ->write("\$this->parent = \$this->env->loadTemplate(")
+ ->write("\$this->parent = \$this->loadTemplate(")
->subcompile($this->getNode('parent'))
+ ->raw(', ')
+ ->repr($compiler->getFilename())
+ ->raw(', ')
+ ->repr($this->getLine())
->raw(");\n\n")
;
}
@@ -346,8 +354,12 @@ class Twig_Node_Module extends Twig_Node
{
if ($node instanceof Twig_Node_Expression_Constant) {
$compiler
- ->write(sprintf("%s = \$this->env->loadTemplate(", $var))
+ ->write(sprintf("%s = \$this->loadTemplate(", $var))
->subcompile($node)
+ ->raw(', ')
+ ->repr($compiler->getFilename())
+ ->raw(', ')
+ ->repr($this->getLine())
->raw(");\n")
;
} else {
@@ -358,7 +370,12 @@ class Twig_Node_Module extends Twig_Node
->write(sprintf("if (!%s", $var))
->raw(" instanceof Twig_Template) {\n")
->indent()
- ->write(sprintf("%s = \$this->env->loadTemplate(%s);\n", $var, $var))
+ ->write(sprintf("%s = \$this->loadTemplate(%s")
+ ->raw(', ')
+ ->repr($compiler->getFilename())
+ ->raw(', ')
+ ->repr($this->getLine())
+ ->raw(");\n", $var, $var))
->outdent()
->write("}\n")
;
diff --git a/lib/Twig/Parser.php b/lib/Twig/Parser.php
index 1179913..3259162 100644
--- a/lib/Twig/Parser.php
+++ b/lib/Twig/Parser.php
@@ -105,11 +105,11 @@ class Twig_Parser implements Twig_ParserInterface
}
}
} catch (Twig_Error_Syntax $e) {
- if (!$e->getTemplateFile()) {
+ if (!$e->getFile()) {
$e->setTemplateFile($this->getFilename());
}
- if (!$e->getTemplateLine()) {
+ if (!$e->getLine()) {
$e->setTemplateLine($this->stream->getCurrent()->getLine());
}
diff --git a/lib/Twig/Template.php b/lib/Twig/Template.php
index e6fdd9e..95f1353 100644
--- a/lib/Twig/Template.php
+++ b/lib/Twig/Template.php
@@ -58,7 +58,7 @@ abstract class Twig_Template
$this->parents[$name] = $parent;
$parent = $name;
} elseif (!isset($this->parents[$parent])) {
- $this->parents[$parent] = $this->env->loadTemplate($parent);
+ $this->parents[$parent] = $this->loadTemplate($parent);
}
return $this->parents[$parent];
@@ -157,6 +157,28 @@ abstract class Twig_Template
return ob_get_clean();
}
+ protected function loadTemplate($template, $templateName = null, $line = null, $index = null)
+ {
+ try {
+ if (is_array($template)) {
+ return $this->env->resolveTemplate($template);
+ } elseif ($template instanceof Twig_Template) {
+ return $template;
+ } else {
+ return $this->env->loadTemplate($template, $index);
+ }
+ } catch (Twig_Error $e) {
+ $e->setTemplateFile($templateName ? $templateName : $this->getTemplateName());
+ if (!$line) {
+ $e->guess();
+ } else {
+ $e->setTemplateLine($line);
+ }
+
+ throw $e;
+ }
+ }
+
protected function getBlocks($context)
{
$blocks = array();
@@ -190,17 +212,6 @@ abstract class Twig_Template
$blocks = $this->getBlocks($context);
call_user_func($blocks['_root'][0], $context, $blocks);
} catch (Twig_Error $e) {
- if (!$e->getTemplateFile()) {
- $e->setTemplateFile($this->getTemplateName());
- }
-
- // this is mostly useful for Twig_Error_Loader exceptions
- // see Twig_Error_Loader
- if (false === $e->getTemplateLine()) {
- $e->setTemplateLine(-1);
- $e->guess();
- }
-
throw $e;
} catch (Exception $e) {
throw new Twig_Error_Runtime(sprintf('An exception has been thrown during the rendering of a template ("%s").', $e->getMessage()), -1, null, $e);
diff --git a/lib/Twig/Test/IntegrationTestCase.php b/lib/Twig/Test/IntegrationTestCase.php
index 3fcf4eb..dd0626c 100644
--- a/lib/Twig/Test/IntegrationTestCase.php
+++ b/lib/Twig/Test/IntegrationTestCase.php
@@ -90,7 +90,7 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
$template = $twig->loadTemplate('index.twig');
} catch (Exception $e) {
if (false !== $exception) {
- $this->assertEquals(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage())));
+ $this->assertEquals(trim($exception), trim(sprintf('%s: %s in "%s" at line %d', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine())));
return;
}
@@ -108,7 +108,7 @@ abstract class Twig_Test_IntegrationTestCase extends PHPUnit_Framework_TestCase
$output = trim($template->render(eval($match[1].';')), "\n ");
} catch (Exception $e) {
if (false !== $exception) {
- $this->assertEquals(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage())));
+ $this->assertEquals(trim($exception), trim(sprintf('%s: %s in "%s" at line %d', get_class($e), $e->getMessage(), $e->getFile(), $e->getLine())));
return;
}
diff --git a/test/Twig/Tests/ErrorTest.php b/test/Twig/Tests/ErrorTest.php
index 9b28697..1331457 100644
--- a/test/Twig/Tests/ErrorTest.php
+++ b/test/Twig/Tests/ErrorTest.php
@@ -16,7 +16,7 @@ class Twig_Tests_ErrorTest extends PHPUnit_Framework_TestCase
$error = new Twig_Error('foo');
$error->setTemplateFile(new SplFileInfo(__FILE__));
- $this->assertContains('test'.DIRECTORY_SEPARATOR.'Twig'.DIRECTORY_SEPARATOR.'Tests'.DIRECTORY_SEPARATOR.'ErrorTest.php', $error->getMessage());
+ $this->assertContains('test'.DIRECTORY_SEPARATOR.'Twig'.DIRECTORY_SEPARATOR.'Tests'.DIRECTORY_SEPARATOR.'ErrorTest.php', $error->getFile());
}
public function testErrorWithArrayFilename()
@@ -24,7 +24,8 @@ class Twig_Tests_ErrorTest extends PHPUnit_Framework_TestCase
$error = new Twig_Error('foo');
$error->setTemplateFile(array('foo' => 'bar'));
- $this->assertEquals('foo in {"foo":"bar"}', $error->getMessage());
+ $this->assertEquals('foo', $error->getMessage());
+ $this->assertEquals('{"foo":"bar"}', $error->getFile());
}
public function testTwigExceptionAddsFileAndLineWhenMissing()
@@ -39,9 +40,9 @@ class Twig_Tests_ErrorTest extends PHPUnit_Framework_TestCase
$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());
+ $this->assertEquals('Variable "foo" does not exist', $e->getMessage());
+ $this->assertEquals(3, $e->getLine());
+ $this->assertEquals('index', $e->getFile());
}
}
@@ -57,9 +58,9 @@ class Twig_Tests_ErrorTest extends PHPUnit_Framework_TestCase
$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 4.', $e->getMessage());
- $this->assertEquals(4, $e->getTemplateLine());
- $this->assertEquals('index', $e->getTemplateFile());
+ $this->assertEquals('An exception has been thrown during the rendering of a template ("Runtime error...").', $e->getMessage());
+ $this->assertEquals(4, $e->getLine());
+ $this->assertEquals('index', $e->getFile());
}
}
@@ -83,9 +84,9 @@ class Twig_Tests_ErrorTest extends PHPUnit_Framework_TestCase
$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());
+ $this->assertEquals('Variable "foo" does not exist', $e->getMessage());
+ $this->assertEquals(3, $e->getLine());
+ $this->assertEquals('index', $e->getFile());
}
try {
@@ -93,9 +94,9 @@ class Twig_Tests_ErrorTest extends PHPUnit_Framework_TestCase
$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());
+ $this->assertEquals('An exception has been thrown during the rendering of a template ("Runtime error...").', $e->getMessage());
+ $this->assertEquals(3, $e->getLine());
+ $this->assertEquals('index', $e->getFile());
}
}
@@ -116,9 +117,9 @@ class Twig_Tests_ErrorTest extends PHPUnit_Framework_TestCase
$this->fail();
} catch (Twig_Error_Runtime $e) {
- $this->assertEquals('Variable "foo" does not exist in "base" at line 1', $e->getMessage());
- $this->assertEquals(1, $e->getTemplateLine());
- $this->assertEquals('base', $e->getTemplateFile());
+ $this->assertEquals('Variable "foo" does not exist', $e->getMessage());
+ $this->assertEquals(1, $e->getLine());
+ $this->assertEquals('base', $e->getFile());
}
}
@@ -133,9 +134,9 @@ class Twig_Tests_ErrorTest extends PHPUnit_Framework_TestCase
$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());
+ $this->assertEquals('Variable "foo" does not exist', $e->getMessage());
+ $this->assertEquals(3, $e->getLine());
+ $this->assertEquals('index.html', $e->getFile());
}
try {
@@ -143,9 +144,9 @@ class Twig_Tests_ErrorTest extends PHPUnit_Framework_TestCase
$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());
+ $this->assertEquals('An exception has been thrown during the rendering of a template ("Runtime error...").', $e->getMessage());
+ $this->assertEquals(3, $e->getLine());
+ $this->assertEquals('index.html', $e->getFile());
}
}
}
diff --git a/test/Twig/Tests/ExpressionParserTest.php b/test/Twig/Tests/ExpressionParserTest.php
index e7d7e02..c592319 100644
--- a/test/Twig/Tests/ExpressionParserTest.php
+++ b/test/Twig/Tests/ExpressionParserTest.php
@@ -215,27 +215,31 @@ class Twig_Tests_ExpressionParserTest extends PHPUnit_Framework_TestCase
);
}
- /**
- * @expectedException Twig_Error_Syntax
- * @expectedExceptionMessage The filter "lowe" does not exist. Did you mean "lower" in "index" at line 1
- */
public function testUnkownFilter()
{
$env = new Twig_Environment(new Twig_Loader_String(), array('cache' => false, 'autoescape' => false));
$parser = new Twig_Parser($env);
- $parser->parse($env->tokenize('{{ 1|lowe }}', 'index'));
+ try {
+ $parser->parse($env->tokenize('{{ 1|lowe }}', 'index'));
+ } catch (Twig_Error_Syntax $e) {
+ $this->assertEquals('The filter "lowe" does not exist. Did you mean "lower"', $e->getMessage());
+ $this->assertEquals(1, $e->getLine());
+ $this->assertEquals('index', $e->getFile());
+ }
}
- /**
- * @expectedException Twig_Error_Syntax
- * @expectedExceptionMessage The function "cycl" does not exist. Did you mean "cycle" in "index" at line 1
- */
public function testUnknownFunction()
{
$env = new Twig_Environment(new Twig_Loader_String(), array('cache' => false, 'autoescape' => false));
$parser = new Twig_Parser($env);
- $parser->parse($env->tokenize('{{ cycl() }}', 'index'));
+ try {
+ $parser->parse($env->tokenize('{{ cycl() }}', 'index'));
+ } catch (Twig_Error_Syntax $e) {
+ $this->assertEquals('The function "cycl" does not exist. Did you mean "cycle"', $e->getMessage());
+ $this->assertEquals(1, $e->getLine());
+ $this->assertEquals('index', $e->getFile());
+ }
}
}
diff --git a/test/Twig/Tests/Extension/SandboxTest.php b/test/Twig/Tests/Extension/SandboxTest.php
index b16f9c9..9e65a5c 100644
--- a/test/Twig/Tests/Extension/SandboxTest.php
+++ b/test/Twig/Tests/Extension/SandboxTest.php
@@ -38,7 +38,7 @@ class Twig_Tests_Extension_SandboxTest extends PHPUnit_Framework_TestCase
/**
* @expectedException Twig_Sandbox_SecurityError
- * @expectedExceptionMessage Filter "json_encode" is not allowed in "1_child".
+ * @expectedExceptionMessage Filter "json_encode" is not allowed.
*/
public function testSandboxWithInheritance()
{
diff --git a/test/Twig/Tests/Fixtures/tags/include/missing.test b/test/Twig/Tests/Fixtures/tags/include/missing.test
index f25e871..df657a9 100644
--- a/test/Twig/Tests/Fixtures/tags/include/missing.test
+++ b/test/Twig/Tests/Fixtures/tags/include/missing.test
@@ -5,4 +5,4 @@
--DATA--
return array();
--EXCEPTION--
-Twig_Error_Loader: Template "foo.twig" is not defined in "index.twig" at line 2.
+Twig_Error_Loader: Template "foo.twig" is not defined. in "index.twig" at line 2
diff --git a/test/Twig/Tests/Fixtures/tags/include/missing_nested.test b/test/Twig/Tests/Fixtures/tags/include/missing_nested.test
index 86c1864..9ad5c00 100644
--- a/test/Twig/Tests/Fixtures/tags/include/missing_nested.test
+++ b/test/Twig/Tests/Fixtures/tags/include/missing_nested.test
@@ -13,4 +13,4 @@
--DATA--
return array();
--EXCEPTION--
-Twig_Error_Loader: Template "foo.twig" is not defined in "base.twig" at line 3.
+Twig_Error_Loader: Template "foo.twig" is not defined. in "base.twig" at line 3
diff --git a/test/Twig/Tests/Fixtures/tags/macro/inheritance.test_NR b/test/Twig/Tests/Fixtures/tags/macro/inheritance.test_NR
new file mode 100644
index 0000000..171ca97
--- /dev/null
+++ b/test/Twig/Tests/Fixtures/tags/macro/inheritance.test_NR
@@ -0,0 +1,18 @@
+--TEST--
+"macro" tag - inheritance
+--TEMPLATE--
+{% import 'forms.twig' as forms %}
+
+{{ forms.foo('foo') }}
+{{ forms.bar('foo') }}
+--TEMPLATE(forms.twig)--
+{% extends 'formsparent.twig' %}
+{% macro foo(name) %}foo{{ name }} (overwritten){% endmacro %}
+--TEMPLATE(formsparent.twig)--
+{% macro foo(name) %}foo{{ name }}{% endmacro %}
+{% macro bar(name) %}bar{{ name }}{% endmacro %}
+--DATA--
+return array()
+--EXPECT--
+foofoo (overwritten)
+barfoo
diff --git a/test/Twig/Tests/Fixtures/tags/macro/inheritance_from.test_NR b/test/Twig/Tests/Fixtures/tags/macro/inheritance_from.test_NR
new file mode 100644
index 0000000..5c74db2
--- /dev/null
+++ b/test/Twig/Tests/Fixtures/tags/macro/inheritance_from.test_NR
@@ -0,0 +1,18 @@
+--TEST--
+"macro" tag - inheritance
+--TEMPLATE--
+{% from 'forms.twig' import foo, bar as barfoo %}
+
+{{ foo('foo') }}
+{{ barfoo('foo') }}
+--TEMPLATE(forms.twig)--
+{% extends 'formsparent.twig' %}
+{% macro foo(name) %}foo{{ name }} (overwritten){% endmacro %}
+--TEMPLATE(formsparent.twig)--
+{% macro foo(name) %}foo{{ name }}{% endmacro %}
+{% macro bar(name) %}bar{{ name }}{% endmacro %}
+--DATA--
+return array()
+--EXPECT--
+foofoo (overwritten)
+barfoo
diff --git a/test/Twig/Tests/Node/ImportTest.php b/test/Twig/Tests/Node/ImportTest.php
index 99ddeda..146fa37 100644
--- a/test/Twig/Tests/Node/ImportTest.php
+++ b/test/Twig/Tests/Node/ImportTest.php
@@ -44,7 +44,7 @@ class Twig_Tests_Node_ImportTest extends Twig_Test_NodeTestCase
$tests[] = array($node, <<<EOF
// line 1
-\$context["macro"] = \$this->env->loadTemplate("foo.twig");
+\$context["macro"] = \$this->loadTemplate("foo.twig", null, 1);
EOF
);
diff --git a/test/Twig/Tests/Node/IncludeTest.php b/test/Twig/Tests/Node/IncludeTest.php
index e6c2bfa..3a07c23 100644
--- a/test/Twig/Tests/Node/IncludeTest.php
+++ b/test/Twig/Tests/Node/IncludeTest.php
@@ -47,7 +47,7 @@ class Twig_Tests_Node_IncludeTest extends Twig_Test_NodeTestCase
$node = new Twig_Node_Include($expr, null, false, false, 1);
$tests[] = array($node, <<<EOF
// line 1
-\$this->env->loadTemplate("foo.twig")->display(\$context);
+\$this->loadTemplate("foo.twig", null, 1)->display(\$context);
EOF
);
@@ -60,8 +60,7 @@ EOF
$node = new Twig_Node_Include($expr, null, false, false, 1);
$tests[] = array($node, <<<EOF
// line 1
-\$template = \$this->env->resolveTemplate(((true) ? ("foo") : ("foo")));
-\$template->display(\$context);
+\$this->loadTemplate(((true) ? ("foo") : ("foo")), null, 1)->display(\$context);
EOF
);
@@ -70,14 +69,14 @@ EOF
$node = new Twig_Node_Include($expr, $vars, false, false, 1);
$tests[] = array($node, <<<EOF
// line 1
-\$this->env->loadTemplate("foo.twig")->display(array_merge(\$context, array("foo" => true)));
+\$this->loadTemplate("foo.twig", null, 1)->display(array_merge(\$context, array("foo" => true)));
EOF
);
$node = new Twig_Node_Include($expr, $vars, true, false, 1);
$tests[] = array($node, <<<EOF
// line 1
-\$this->env->loadTemplate("foo.twig")->display(array("foo" => true));
+\$this->loadTemplate("foo.twig", null, 1)->display(array("foo" => true));
EOF
);
@@ -85,7 +84,7 @@ EOF
$tests[] = array($node, <<<EOF
// line 1
try {
- \$this->env->loadTemplate("foo.twig")->display(array("foo" => true));
+ \$this->loadTemplate("foo.twig", null, 1)->display(array("foo" => true));
} catch (Twig_Error_Loader \$e) {
// ignore missing template
}
diff --git a/test/Twig/Tests/Node/ModuleTest.php b/test/Twig/Tests/Node/ModuleTest.php
index 26609e5..b6715f1 100644
--- a/test/Twig/Tests/Node/ModuleTest.php
+++ b/test/Twig/Tests/Node/ModuleTest.php
@@ -117,7 +117,7 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
{
\$this->env = \$env;
- \$this->parent = \$this->env->loadTemplate("layout.twig");
+ \$this->parent = \$this->loadTemplate("layout.twig", "foo.twig", 1);
\$this->traits = array();
@@ -135,7 +135,7 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
public function root(array \$context, array \$blocks, \$level = 0)
{
// line 1
- \$context["macro"] = \$this->env->loadTemplate("foo.twig");
+ \$context["macro"] = \$this->loadTemplate("foo.twig", "foo.twig", 1);
call_user_func(\$blocks['_root'][\$level + 1], \$context, \$blocks, \$level + 1);
}
@@ -186,7 +186,7 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
protected function doGetParent(array \$context)
{
- return \$this->env->resolveTemplate(((true) ? ("foo") : ("foo")));
+ return \$this->loadTemplate(((true) ? ("foo") : ("foo")), "foo.twig", 1);
}
public function root(array \$context, array \$blocks, \$level = 0)
diff --git a/test/Twig/Tests/Node/SandboxedModuleTest.php b/test/Twig/Tests/Node/SandboxedModuleTest.php
index 75ec2a6..65086bc 100644
--- a/test/Twig/Tests/Node/SandboxedModuleTest.php
+++ b/test/Twig/Tests/Node/SandboxedModuleTest.php
@@ -128,7 +128,7 @@ class __TwigTemplate_be925a7b06dda0dfdbd18a1509f7eb34 extends Twig_Template
{
\$this->env = \$env;
- \$this->parent = \$this->env->loadTemplate("layout.twig");
+ \$this->parent = \$this->loadTemplate("layout.twig", "foo.twig", 1);
\$this->traits = array();
diff --git a/test/Twig/Tests/ParserTest.php b/test/Twig/Tests/ParserTest.php
index 9c757ee..c0d7995 100644
--- a/test/Twig/Tests/ParserTest.php
+++ b/test/Twig/Tests/ParserTest.php
@@ -21,7 +21,7 @@ class Twig_Tests_ParserTest extends PHPUnit_Framework_TestCase
/**
* @expectedException Twig_Error_Syntax
- * @expectedExceptionMessage Unknown tag name "foo". Did you mean "for" at line 1
+ * @expectedExceptionMessage Unknown tag name "foo". Did you mean "for"
*/
public function testUnkownTag()
{
@@ -84,7 +84,7 @@ class Twig_Tests_ParserTest extends PHPUnit_Framework_TestCase
/**
* @expectedException Twig_Error_Syntax
- * @expectedExceptionMessage A template that extends another one cannot have a body but a byte order mark (BOM) has been detected; it must be removed at line 1.
+ * @expectedExceptionMessage A template that extends another one cannot have a body but a byte order mark (BOM) has been detected; it must be removed.
*/
public function testFilterBodyNodesWithBOM()
{
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment