Skip to content

Commit 085ebf3

Browse files
committed
Refactor is_in_function_call() tests to cover all parameter combinations and to remove duplicate test cases
1 parent 1ea69cf commit 085ebf3

File tree

2 files changed

+427
-127
lines changed

2 files changed

+427
-127
lines changed
Lines changed: 74 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,89 @@
11
<?php
22

33
/*
4-
* Make sure that tokens inside a function call are correctly identified using the default values
5-
* for the optional parameters (`$global_function = true` and `$allow_nested = false`).
6-
*
7-
* The below should *NOT* be recognized as inside a function call to one of the valid functions.
4+
* The below should *NOT* be recognized as inside a function call to one of the valid functions regardless of the value
5+
* of the optional parameters (`$global_function` and `$allow_nested`).
86
*/
97

10-
$a = /* test return false 1 */ 'foo';
11-
another_function( /* test return false 2 */ $a );
12-
MyNamespace\my_function( /* test return false 3 */ $a );
13-
\MyNamespace\my_function( /* test return false 4 */ $a );
14-
namespace\MyNamespace\my_function( /* test return false 5 */ $a );
15-
my_function( another_function( /* test return false 6 */ $a ) );
8+
$a = /* testPlainAssignment */ 'foo';
9+
another_function( /* testDifferentFunction */ 123 );
1610
$anon_func = function() {
17-
/* test return false 7 */ $a = 'foo';
11+
/* testInsideClosure */ $a = 'foo';
1812
};
19-
$my_function( /* test return false 8 */ $a );
13+
$my_function( /* testVariableFunction */ $a );
14+
if ( /* testIfCondition */ true ) {}
2015

2116
/*
22-
* Make sure that tokens inside a function call are correctly identified using the default values
23-
* for the optional parameters (`$global_function = true` and `$allow_nested = false`).
24-
*
25-
* The below should be recognized as inside a function call to one of the valid functions.
17+
* The below should be recognized as inside a function call to one of the valid functions regardless of the value
18+
* of the optional parameters (`$global_function` and `$allow_nested`).
2619
*/
2720

28-
/* test function call 1 */ my_function( /* test inside function pointer 1 */ $a );
29-
/* test function call 2 */ MY_FUNCTION( /* test inside function pointer 2 */ $a );
30-
/* test function call 3 */ \my_function( /* test inside function pointer 3 */ $a );
21+
/* testLowercaseName */
22+
valid_function1( /* testLowercaseNameInsideCall */ );
23+
/* testUppercaseName */
24+
VALID_FUNCTION2( /* testUppercaseNameInsideCall */ 'string' );
25+
/* testFullyQualified */
26+
\valid_function2( /* testFullyQualifiedInsideCall */ 42 );
3127

3228
/*
33-
* Make sure that tokens inside a function call are correctly identified when `$global_function` is
34-
* set to false.
35-
*
36-
* The below should be recognized as inside a function call to one of the valid functions.
29+
* The below might be recognized as inside a function call to one of the valid functions or not depending on the values
30+
* passed to the optional parameters (`$global_function` and `$allow_nested`).
3731
*/
3832

39-
/* test function call 4 */ my_function( /* test inside function pointer 4 */ $a );
40-
/* test function call 5 */ MY_FUNCTION( /* test inside function pointer 5 */ $a );
41-
/* test function call 6 */ \my_function( /* test inside function pointer 6 */ $a );
42-
MyNamespace\/* test function call 7 */my_function( /* test inside function pointer 7 */ $a );
43-
\MyNamespace\/* test function call 8 */my_function( /* test inside function pointer 8 */ $a );
44-
namespace\MyNamespace\/* test function call 9 */my_function( /* test inside function pointer 9 */ $a );
45-
MyClass::/* test function call 10 */my_function( /* test inside function pointer 10 */ $a );
46-
/* test function call 11 */ $obj->my_function( /* test inside function pointer 11 */ $a );
47-
/* test function call 12 */ $obj?->my_function( /* test inside function pointer 12 */ $a );
48-
49-
/*
50-
* Make sure that tokens inside a function call are correctly identified when `$allow_nested` is
51-
* set to true.
52-
*
53-
* The below should be recognized as inside a function call to one of the valid functions.
54-
*/
55-
/* test function call 13 */ my_function( another_function( /* test inside function pointer 13 */ $a ) );
56-
another_function( /* test function call 14 */ my_function( /* test inside function pointer 14 */ $a ) );
57-
/* test function call 15 */ my_function( middle_function( inner_function( /* test inside function pointer 15 */ $a ) ) );
33+
MyNamespace\/* testNamespacedFunction */valid_function1( /* testNamespacedFunctionInsideCall */ false );
34+
\MyNamespace\/* testFullyQualifiedNamespacedFunction */valid_function1(
35+
/* testFullyQualifiedNamespacedFunctionInsideCall */ null
36+
);
37+
namespace\MyNamespace\/* testNamespaceRelativeFunction */valid_function2(
38+
/* testNamespaceRelativeFunctionInsideCall */ 3.14
39+
);
40+
MyClass::/* testStaticMethod */valid_function2(
41+
/* testStaticMethodInsideCall */ 'text'
42+
);
43+
/* testObjectMethod */
44+
$obj->valid_function1( /* testObjectMethodInsideCall */ array() );
45+
/* testNullsafeObjectMethod */
46+
$obj?->valid_function1( /* testNullsafeObjectMethodInsideCall */ [ 1, 2, 3 ] );
47+
/* testNestedOuter */
48+
valid_function1( another_function( /* testNestedOuterInsideCall */ 'param' ) );
49+
another_function( /* testNestedInner */ valid_function1( /* testNestedInnerInsideCall */ true ) );
50+
/* testNestedMultipleLevels */
51+
valid_function1( middle_function( inner_function( /* testNestedMultipleLevelsInsideCall */ 999 ) ) );
52+
other_function(
53+
MyNamespace\/* testNestedNamespacedMatching */ valid_function1(
54+
/* testNestedNamespacedMatchingInsideCall */ some_function()
55+
)
56+
);
57+
MyNamespace\other_function(
58+
MyNamespace\/* testNestedBothNamespacedInner */ valid_function1(
59+
/* testNestedBothNamespacedInnerInsideCall */ $obj->method()
60+
)
61+
);
62+
MyNamespace\/* testNestedBothNamespacedOuter */ valid_function1(
63+
MyNamespace\other_function(
64+
/* testNestedBothNamespacedOuterInsideCall */ 'value' . $var
65+
)
66+
);
67+
/* testComplexParametersAlwaysMatch */
68+
valid_function1(
69+
array( 'key1' => 'value1' ),
70+
other_function( 'nested' ),
71+
/* testComplexParametersAlwaysMatchInsideCall */ $var
72+
);
73+
/* testComplexParametersNestedOnly */
74+
valid_function1(
75+
function() { return 'closure value'; },
76+
$obj->method(),
77+
another_function( /* testComplexParametersNestedOnlyInsideCall */ $var )
78+
);
79+
/* testComplexParametersNonGlobal */
80+
$obj->valid_function1(
81+
array( 'key1' => get_value() ),
82+
MyClass::helper(),
83+
/* testComplexParametersNonGlobalInsideCall */ true
84+
);
85+
MyClass::/* testComplexParametersNonGlobalNested */ valid_function1(
86+
$obj->method(),
87+
'text',
88+
array( 'key' => MyNamespace\other_function( /* testComplexParametersNonGlobalNestedInsideCall */ 123 ) )
89+
);

0 commit comments

Comments
 (0)