Fix exception message for static method and object without req. params.

This commit is contained in:
SpacePossum
2016-06-03 13:27:11 +02:00
parent a2400a8dd1
commit 8f6fd57a7e
2 changed files with 37 additions and 6 deletions
+6 -6
View File
@@ -239,12 +239,12 @@ abstract class Twig_Node_Expression_Call extends Twig_Node_Expression
if ($argument && $argument->isArray() && $argument->isDefaultValueAvailable() && array() === $argument->getDefaultValue()) {
array_pop($parameters);
} else {
$callableName = $r->name;
if ($r->getDeclaringClass()) {
$callableName = $r->getDeclaringClass()->name.'::'.$callableName;
}
throw new LogicException(sprintf('The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = array()".', $callableName, $this->getAttribute('type'), $this->getAttribute('name')));
throw new LogicException(sprintf(
'The last parameter of "%s" for %s "%s" must be an array with default value, eg. "array $arg = array()".',
$r instanceof ReflectionMethod ? $r->getDeclaringClass()->name.'::'.$r->name : $r->name,
$this->getAttribute('type'),
$this->getAttribute('name')
));
}
}
@@ -105,6 +105,26 @@ class Twig_Tests_Node_Expression_CallTest extends PHPUnit_Framework_TestCase
public function customFunctionWithArbitraryArguments()
{
}
/**
* @expectedException LogicException
* @expectedExceptionMessageRegExp #^The last parameter of "custom_Twig_Tests_Node_Expression_CallTest_function" for function "foo" must be an array with default value, eg\. "array \$arg \= array\(\)"\.$#
*/
public function testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnFunction()
{
$node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'foo', 'is_variadic' => true));
$node->getArguments('custom_Twig_Tests_Node_Expression_CallTest_function', array());
}
/**
* @expectedException LogicException
* @expectedExceptionMessageRegExp #^The last parameter of "CallableTestClass\:\:__invoke" for function "foo" must be an array with default value, eg\. "array \$arg \= array\(\)"\.$#
*/
public function testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnObject()
{
$node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'foo', 'is_variadic' => true));
$node->getArguments(new CallableTestClass(), array());
}
}
class Twig_Tests_Node_Expression_Call extends Twig_Node_Expression_Call
@@ -114,3 +134,14 @@ class Twig_Tests_Node_Expression_Call extends Twig_Node_Expression_Call
return parent::getArguments($callable, $arguments);
}
}
class CallableTestClass
{
public function __invoke($required)
{
}
}
function custom_Twig_Tests_Node_Expression_CallTest_function($required)
{
}