From 6427189000b2af9a910ba3397f7e1812be2ffc8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Haso=C5=88?= Date: Thu, 16 Oct 2014 13:41:31 +0200 Subject: [PATCH] Improved an exception message for unknown arguments --- lib/Twig/Node/Expression/Call.php | 8 ++++++-- test/Twig/Tests/Node/Expression/CallTest.php | 4 ++-- test/Twig/Tests/Node/Expression/FilterTest.php | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/lib/Twig/Node/Expression/Call.php b/lib/Twig/Node/Expression/Call.php index 912b837a9..5703b61df 100644 --- a/lib/Twig/Node/Expression/Call.php +++ b/lib/Twig/Node/Expression/Call.php @@ -138,9 +138,10 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression } $arguments = array(); + $names = array(); $pos = 0; foreach ($definition as $param) { - $name = $this->normalizeName($param->name); + $names[] = $name = $this->normalizeName($param->name); if (array_key_exists($name, $parameters)) { if (array_key_exists($pos, $parameters)) { @@ -163,7 +164,10 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression } if (!empty($parameters)) { - throw new Twig_Error_Syntax(sprintf('Unknown argument%s "%s" for %s "%s".', count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $this->getAttribute('type'), $this->getAttribute('name'))); + throw new Twig_Error_Syntax(sprintf( + 'Unknown argument%s "%s" for %s "%s(%s)".', + count($parameters) > 1 ? 's' : '', implode('", "', array_keys($parameters)), $this->getAttribute('type'), $this->getAttribute('name'), implode(', ', $names) + )); } return $arguments; diff --git a/test/Twig/Tests/Node/Expression/CallTest.php b/test/Twig/Tests/Node/Expression/CallTest.php index c54ea1e02..94ad32eb6 100644 --- a/test/Twig/Tests/Node/Expression/CallTest.php +++ b/test/Twig/Tests/Node/Expression/CallTest.php @@ -39,7 +39,7 @@ class Twig_Tests_Node_Expression_CallTest extends PHPUnit_Framework_TestCase /** * @expectedException Twig_Error_Syntax - * @expectedExceptionMessage Unknown argument "unknown" for function "date". + * @expectedExceptionMessage Unknown argument "unknown" for function "date(format, timestamp)". */ public function testGetArgumentsWithWrongNamedArgumentName() { @@ -49,7 +49,7 @@ class Twig_Tests_Node_Expression_CallTest extends PHPUnit_Framework_TestCase /** * @expectedException Twig_Error_Syntax - * @expectedExceptionMessage Unknown arguments "unknown1", "unknown2" for function "date". + * @expectedExceptionMessage Unknown arguments "unknown1", "unknown2" for function "date(format, timestamp)". */ public function testGetArgumentsWithWrongNamedArgumentNames() { diff --git a/test/Twig/Tests/Node/Expression/FilterTest.php b/test/Twig/Tests/Node/Expression/FilterTest.php index 8089b9cb1..9caf9f5dc 100644 --- a/test/Twig/Tests/Node/Expression/FilterTest.php +++ b/test/Twig/Tests/Node/Expression/FilterTest.php @@ -86,7 +86,7 @@ class Twig_Tests_Node_Expression_FilterTest extends Twig_Test_NodeTestCase /** * @expectedException Twig_Error_Syntax - * @expectedExceptionMessage Unknown argument "foobar" for filter "date". + * @expectedExceptionMessage Unknown argument "foobar" for filter "date(format, timezone)". */ public function testCompileWithWrongNamedArgumentName() {