merged branch hason/patch1 (PR #1080)

This PR was merged into the master branch.

Discussion
----------

Small fixes

Commits
-------

a6205c5 Fixed exception message in Call
b5928de Fixed PSR-0 in tests
This commit is contained in:
Fabien Potencier
2013-06-27 08:24:31 +02:00
3 changed files with 24 additions and 4 deletions
+3 -3
View File
@@ -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;
+21 -1
View File
@@ -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