Skip to content

Commit 17b2c66

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

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

tests/Core/File/GetMethodPropertiesTest.inc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,10 @@ class ReturnMe {
7373
return $this;
7474
}
7575
}
76+
77+
/* testPHP8MixedTypeHint */
78+
function mixedTypeHint() :mixed {}
79+
80+
/* testPHP8MixedTypeHintNullable */
81+
// Intentional fatal error - nullability is not allowed with mixed, but that's not the concern of the method.
82+
function mixedTypeHintNullable(): ?mixed {}

tests/Core/File/GetMethodPropertiesTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,52 @@ public function testReturnTypeStatic()
406406
}//end testReturnTypeStatic()
407407

408408

409+
/**
410+
* Test a function with return type "mixed".
411+
*
412+
* @return void
413+
*/
414+
public function testPHP8MixedTypeHint()
415+
{
416+
$expected = [
417+
'scope' => 'public',
418+
'scope_specified' => false,
419+
'return_type' => 'mixed',
420+
'nullable_return_type' => false,
421+
'is_abstract' => false,
422+
'is_final' => false,
423+
'is_static' => false,
424+
'has_body' => true,
425+
];
426+
427+
$this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected);
428+
429+
}//end testPHP8MixedTypeHint()
430+
431+
432+
/**
433+
* Test a function with return type "mixed" and nullability.
434+
*
435+
* @return void
436+
*/
437+
public function testPHP8MixedTypeHintNullable()
438+
{
439+
$expected = [
440+
'scope' => 'public',
441+
'scope_specified' => false,
442+
'return_type' => '?mixed',
443+
'nullable_return_type' => true,
444+
'is_abstract' => false,
445+
'is_final' => false,
446+
'is_static' => false,
447+
'has_body' => true,
448+
];
449+
450+
$this->getMethodPropertiesTestHelper('/* '.__FUNCTION__.' */', $expected);
451+
452+
}//end testPHP8MixedTypeHintNullable()
453+
454+
409455
/**
410456
* Test helper.
411457
*

0 commit comments

Comments
 (0)