From a6205c55f32519faa039efca5717b442d36d3e34 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Martin=20Haso=C5=88?= Date: Wed, 8 May 2013 21:49:15 +0200 Subject: [PATCH] Fixed exception message in Call --- lib/Twig/Node/Expression/Call.php | 6 +++--- test/Twig/Tests/Node/Expression/CallTest.php | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/Twig/Node/Expression/Call.php b/lib/Twig/Node/Expression/Call.php index 87b62de..dba9b0e 100644 --- a/lib/Twig/Node/Expression/Call.php +++ b/lib/Twig/Node/Expression/Call.php @@ -146,7 +146,7 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression if (array_key_exists($name, $parameters)) { if (array_key_exists($pos, $parameters)) { - throw new Twig_Error_Syntax(sprintf('Arguments "%s" is defined twice for %s "%s".', $name, $this->getAttribute('type'), $this->getAttribute('name'))); + throw new Twig_Error_Syntax(sprintf('Argument "%s" is defined twice for %s "%s".', $name, $this->getAttribute('type'), $this->getAttribute('name'))); } $arguments[] = $parameters[$name]; @@ -164,8 +164,8 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression } } - foreach (array_keys($parameters) as $name) { - throw new Twig_Error_Syntax(sprintf('Unknown argument "%s" for %s "%s".', $name, $this->getAttribute('type'), $this->getAttribute('name'))); + 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'))); } return $arguments; diff --git a/test/Twig/Tests/Node/Expression/CallTest.php b/test/Twig/Tests/Node/Expression/CallTest.php index b465549..53b5e6e 100644 --- a/test/Twig/Tests/Node/Expression/CallTest.php +++ b/test/Twig/Tests/Node/Expression/CallTest.php @@ -29,13 +29,33 @@ class Twig_Tests_Node_Expression_CallTest extends PHPUnit_Framework_TestCase /** * @expectedException Twig_Error_Syntax - * @expectedExceptionMessage Arguments "format" is defined twice for function "date". + * @expectedExceptionMessage Argument "format" is defined twice for function "date". */ public function testGetArgumentsWhenArgumentIsDefinedTwice() { $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date')); $node->getArguments('date', array('Y-m-d', 'format' => 'U')); } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage Unknown argument "unknown" for function "date". + */ + public function testGetArgumentsWithWrongNamedArgumentName() + { + $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date')); + $node->getArguments('date', array('Y-m-d', 'unknown' => '')); + } + + /** + * @expectedException Twig_Error_Syntax + * @expectedExceptionMessage Unknown arguments "unknown1", "unknown2" for function "date". + */ + public function testGetArgumentsWithWrongNamedArgumentNames() + { + $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date')); + $node->getArguments('date', array('Y-m-d', 'unknown1' => '', 'unknown2' => '')); + } } class Twig_Tests_Node_Expression_Call extends Twig_Node_Expression_Call -- 1.7.2.5