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];
}
}
- 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;
/**
* @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