Skip to content

Commit c7425ff

Browse files
committed
File::getMethodParameters(): add extra test
Just safeguarding handling of closure use with parameters imported by reference.
1 parent b5cfed2 commit c7425ff

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

tests/Core/File/GetMethodParametersTest.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,9 @@ function() use() {};
312312
/* testClosureUse */
313313
function() use( $foo, $bar ) {};
314314

315+
/* testClosureUseWithReference */
316+
$cl = function() use (&$foo, &$bar) {};
317+
315318
/* testFunctionParamListWithTrailingComma */
316319
function trailingComma(
317320
?string $foo /*comment*/ ,

tests/Core/File/GetMethodParametersTest.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,6 +2937,51 @@ public function testClosureUse()
29372937
}//end testClosureUse()
29382938

29392939

2940+
/**
2941+
* Verify handling of a closure T_USE token with variables imported by reference.
2942+
*
2943+
* @return void
2944+
*/
2945+
public function testClosureUseWithReference()
2946+
{
2947+
// Offsets are relative to the T_USE token.
2948+
$expected = [];
2949+
$expected[0] = [
2950+
'token' => 4,
2951+
'name' => '$foo',
2952+
'content' => '&$foo',
2953+
'has_attributes' => false,
2954+
'pass_by_reference' => true,
2955+
'reference_token' => 3,
2956+
'variable_length' => false,
2957+
'variadic_token' => false,
2958+
'type_hint' => '',
2959+
'type_hint_token' => false,
2960+
'type_hint_end_token' => false,
2961+
'nullable_type' => false,
2962+
'comma_token' => 5,
2963+
];
2964+
$expected[1] = [
2965+
'token' => 8,
2966+
'name' => '$bar',
2967+
'content' => '&$bar',
2968+
'has_attributes' => false,
2969+
'pass_by_reference' => true,
2970+
'reference_token' => 7,
2971+
'variable_length' => false,
2972+
'variadic_token' => false,
2973+
'type_hint' => '',
2974+
'type_hint_token' => false,
2975+
'type_hint_end_token' => false,
2976+
'nullable_type' => false,
2977+
'comma_token' => false,
2978+
];
2979+
2980+
$this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected, [T_USE]);
2981+
2982+
}//end testClosureUseWithReference()
2983+
2984+
29402985
/**
29412986
* Verify function declarations with trailing commas are handled correctly.
29422987
*

0 commit comments

Comments
 (0)