mirror of
https://github.com/twigphp/Twig.git
synced 2026-09-15 03:46:39 +00:00
Improved an exception message for unknown arguments
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user