Improved an exception message for unknown arguments

This commit is contained in:
Martin Hasoň
2014-10-16 13:41:31 +02:00
parent e443766fc5
commit 6427189000
3 changed files with 9 additions and 5 deletions
+6 -2
View File
@@ -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;
+2 -2
View File
@@ -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()
{
@@ -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()
{