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
12class 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
An exception for terminatinating execution or to throw for unit testing.
__invoke($required)
Definition: CallTest.php:136
testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnFunction()
@expectedException LogicException @expectedExceptionMessageRegExp #^The last parameter of "custom_Twi...
Definition: CallTest.php:109
testResolveArgumentsWithMissingParameterForArbitraryArgumentsOnObject()
@expectedException LogicException @expectedExceptionMessageRegExp #^The last parameter of "CallableTe...
Definition: CallTest.php:119
testResolveArgumentsWithMissingValueForOptionalArgument()
@expectedException Twig_Error_Syntax @expectedExceptionMessage Argument "case_sensitivity" could not ...
Definition: CallTest.php:64
testResolveArgumentsWithMissingParameterForArbitraryArguments()
@expectedException LogicException @expectedExceptionMessage The last parameter of "Twig_Tests_Node_Ex...
Definition: CallTest.php:87
static customStaticFunction($arg1, $arg2='default', $arg3=array())
Definition: CallTest.php:93
testGetArgumentsWithWrongNamedArgumentNames()
@expectedException Twig_Error_Syntax @expectedExceptionMessage Unknown arguments "unknown1",...
Definition: CallTest.php:54
testGetArgumentsWhenPositionalArgumentsAfterNamedArguments()
@expectedException Twig_Error_Syntax @expectedExceptionMessage Positional arguments cannot be used af...
Definition: CallTest.php:24
customFunction($arg1, $arg2='default', $arg3=array())
Definition: CallTest.php:97
testGetArgumentsWhenArgumentIsDefinedTwice()
@expectedException Twig_Error_Syntax @expectedExceptionMessage Argument "format" is defined twice for...
Definition: CallTest.php:34
testGetArgumentsWithWrongNamedArgumentName()
@expectedException Twig_Error_Syntax @expectedExceptionMessage Unknown argument "unknown" for functio...
Definition: CallTest.php:44
getArguments($callable, $arguments)
Definition: CallTest.php:128