ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
CallTest.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of Twig.
5  *
6  * (c) Fabien Potencier
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11 
12 class Twig_Tests_Node_Expression_CallTest extends \PHPUnit\Framework\TestCase
13 {
14  public function testGetArguments()
15  {
16  $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date'));
17  $this->assertEquals(array('U', null), $node->getArguments('date', array('format' => 'U', 'timestamp' => null)));
18  }
19 
25  {
26  $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date'));
27  $node->getArguments('date', array('timestamp' => 123456, 'Y-m-d'));
28  }
29 
35  {
36  $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date'));
37  $node->getArguments('date', array('Y-m-d', 'format' => 'U'));
38  }
39 
45  {
46  $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date'));
47  $node->getArguments('date', array('Y-m-d', 'timestamp' => null, 'unknown' => ''));
48  }
49 
55  {
56  $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'date'));
57  $node->getArguments('date', array('Y-m-d', 'timestamp' => null, 'unknown1' => '', 'unknown2' => ''));
58  }
59 
65  {
66  $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'substr_compare'));
67  $node->getArguments('substr_compare', array('abcd', 'bc', 'offset' => 1, 'case_sensitivity' => true));
68  }
69 
71  {
72  $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'custom_function'));
73 
74  $this->assertEquals(array('arg1'), $node->getArguments(array($this, 'customFunction'), array('arg1' => 'arg1')));
75  }
76 
78  {
79  $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'custom_static_function'));
80  $this->assertEquals(array('arg1'), $node->getArguments(__CLASS__.'::customStaticFunction', array('arg1' => 'arg1')));
81  }
82 
88  {
89  $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'foo', 'is_variadic' => true));
90  $node->getArguments(array($this, 'customFunctionWithArbitraryArguments'), array());
91  }
92 
93  public static function customStaticFunction($arg1, $arg2 = 'default', $arg3 = array())
94  {
95  }
96 
97  public function customFunction($arg1, $arg2 = 'default', $arg3 = array())
98  {
99  }
100 
102  {
103  }
104 
110  {
111  $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'foo', 'is_variadic' => true));
112  $node->getArguments('custom_Twig_Tests_Node_Expression_CallTest_function', array());
113  }
114 
120  {
121  $node = new Twig_Tests_Node_Expression_Call(array(), array('type' => 'function', 'name' => 'foo', 'is_variadic' => true));
122  $node->getArguments(new CallableTestClass(), array());
123  }
124 }
125 
127 {
128  public function getArguments($callable, $arguments)
129  {
130  return parent::getArguments($callable, $arguments);
131  }
132 }
133 
135 {
136  public function __invoke($required)
137  {
138  }
139 }
140 
142 {
143 }
custom_Twig_Tests_Node_Expression_CallTest_function($required)
Definition: CallTest.php:141
customFunction($arg1, $arg2='default', $arg3=array())
Definition: CallTest.php:97
static customStaticFunction($arg1, $arg2='default', $arg3=array())
Definition: CallTest.php:93
getArguments($callable, $arguments)
Definition: CallTest.php:128
testGetArgumentsWithWrongNamedArgumentNames()
Twig_Error_Syntax Unknown arguments "unknown1", "unknown2" for function "date(format, timestamp)".
Definition: CallTest.php:54
testGetArgumentsWhenArgumentIsDefinedTwice()
Twig_Error_Syntax Argument "format" is defined twice for function "date".
Definition: CallTest.php:34
testResolveArgumentsWithMissingParameterForArbitraryArguments()
LogicException The last parameter of "Twig_Tests_Node_Expression_CallTest::customFunctionWithArbitra...
Definition: CallTest.php:87
__invoke($required)
Definition: CallTest.php:136
testGetArgumentsWithWrongNamedArgumentName()
Twig_Error_Syntax Unknown argument "unknown" for function "date(format, timestamp)".
Definition: CallTest.php:44
testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnFunction()
LogicException #^The last parameter of "custom_Twig_Tests_Node_Expression_CallTest_function" for fun...
Definition: CallTest.php:109
testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnObject()
LogicException #^The last parameter of "CallableTestClass\:\:__invoke" for function "foo" must be an...
Definition: CallTest.php:119
testGetArgumentsWhenPositionalArgumentsAfterNamedArguments()
Twig_Error_Syntax Positional arguments cannot be used after named arguments for function "date"...
Definition: CallTest.php:24
testResolveArgumentsWithMissingValueForOptionalArgument()
Twig_Error_Syntax Argument "case_sensitivity" could not be assigned for function "substr_compare(mai...
Definition: CallTest.php:64