Skip to content

Commit 80f031b

Browse files
committed
File::getMethodParameters(): add tests with PHP 8 "mixed" type
No changes needed to the actual method, the parameter type is already handled correctly.
1 parent 5b0b6ab commit 80f031b

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

tests/Core/File/GetMethodParametersTest.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,10 @@ function myFunction($a = 10 & 20) {}
3131

3232
/* testArrowFunction */
3333
fn(int $a, ...$b) => $b;
34+
35+
/* testPHP8MixedTypeHint */
36+
function mixedTypeHint(mixed &...$var1) {}
37+
38+
/* testPHP8MixedTypeHintNullable */
39+
// Intentional fatal error - nullability is not allowed with mixed, but that's not the concern of the method.
40+
function mixedTypeHintNullable(?Mixed $var1) {}

tests/Core/File/GetMethodParametersTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,50 @@ public function testArrowFunction()
274274
}//end testArrowFunction()
275275

276276

277+
/**
278+
* Verify recognition of PHP8 mixed type declaration.
279+
*
280+
* @return void
281+
*/
282+
public function testPHP8MixedTypeHint()
283+
{
284+
$expected = [];
285+
$expected[0] = [
286+
'name' => '$var1',
287+
'content' => 'mixed &...$var1',
288+
'pass_by_reference' => true,
289+
'variable_length' => true,
290+
'type_hint' => 'mixed',
291+
'nullable_type' => false,
292+
];
293+
294+
$this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected);
295+
296+
}//end testPHP8MixedTypeHint()
297+
298+
299+
/**
300+
* Verify recognition of PHP8 mixed type declaration with nullability.
301+
*
302+
* @return void
303+
*/
304+
public function testPHP8MixedTypeHintNullable()
305+
{
306+
$expected = [];
307+
$expected[0] = [
308+
'name' => '$var1',
309+
'content' => '?Mixed $var1',
310+
'pass_by_reference' => false,
311+
'variable_length' => false,
312+
'type_hint' => '?Mixed',
313+
'nullable_type' => true,
314+
];
315+
316+
$this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected);
317+
318+
}//end testPHP8MixedTypeHintNullable()
319+
320+
277321
/**
278322
* Test helper.
279323
*

0 commit comments

Comments
 (0)