Skip to content

Commit b5c80d3

Browse files
authored
Merge pull request #914 from PHPCSStandards/feature/file-getmethodparameters-add-extra-test
File::getMethodParameters(): add extra test
2 parents 0dd320f + 198e954 commit b5c80d3

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
@@ -2935,6 +2935,51 @@ public function testClosureUse()
29352935
}//end testClosureUse()
29362936

29372937

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

0 commit comments

Comments
 (0)