Skip to content

Commit

Permalink
File::getMethodParameters(): add tests with PHP 8 "mixed" type
Browse files Browse the repository at this point in the history
No changes needed to the actual method, the parameter type is already handled correctly.
  • Loading branch information
jrfnl committed Jul 15, 2020
1 parent 5b0b6ab commit 80f031b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/Core/File/GetMethodParametersTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,10 @@ function myFunction($a = 10 & 20) {}

/* testArrowFunction */
fn(int $a, ...$b) => $b;

/* testPHP8MixedTypeHint */
function mixedTypeHint(mixed &...$var1) {}

/* testPHP8MixedTypeHintNullable */
// Intentional fatal error - nullability is not allowed with mixed, but that's not the concern of the method.
function mixedTypeHintNullable(?Mixed $var1) {}
44 changes: 44 additions & 0 deletions tests/Core/File/GetMethodParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,50 @@ public function testArrowFunction()
}//end testArrowFunction()


/**
* Verify recognition of PHP8 mixed type declaration.
*
* @return void
*/
public function testPHP8MixedTypeHint()
{
$expected = [];
$expected[0] = [
'name' => '$var1',
'content' => 'mixed &...$var1',
'pass_by_reference' => true,
'variable_length' => true,
'type_hint' => 'mixed',
'nullable_type' => false,
];

$this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected);

}//end testPHP8MixedTypeHint()


/**
* Verify recognition of PHP8 mixed type declaration with nullability.
*
* @return void
*/
public function testPHP8MixedTypeHintNullable()
{
$expected = [];
$expected[0] = [
'name' => '$var1',
'content' => '?Mixed $var1',
'pass_by_reference' => false,
'variable_length' => false,
'type_hint' => '?Mixed',
'nullable_type' => true,
];

$this->getMethodParametersTestHelper('/* '.__FUNCTION__.' */', $expected);

}//end testPHP8MixedTypeHintNullable()


/**
* Test helper.
*
Expand Down

0 comments on commit 80f031b

Please sign in to comment.