Skip to content

Commit

Permalink
feat(PhpUnit) - add php 8.0 compatibility part 2
Browse files Browse the repository at this point in the history
- Update CodeHelper add support ReflectionUnionType return type
- Update Mockery add support ReflectionUnionType return type
  • Loading branch information
temafey committed Apr 28, 2021
1 parent ceb2730 commit 2e68470
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Generator/Helper/CodeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,15 @@ protected function getMethodReturnType(ReflectionMethod $reflectionMethod): stri
} else {
$returnType = $reflectionMethod->getReturnType();

if (null !== $returnType) {
if (
class_exists('ReflectionUnionType') &&
$returnType instanceof \ReflectionUnionType
) {
// use only first return type
// @TODO return all return types
$returnType = array_shift($returnType->getTypes());
}
if ($returnType instanceof \ReflectionNamedType) {
$returnType = $returnType->getName();
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/Generator/Mock/Mockery.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,15 @@ public function generateMockCode(
} else {
$returnType = $refMethod->getReturnType();

if (null !== $returnType) {
if (
class_exists('ReflectionUnionType') &&
$returnType instanceof \ReflectionUnionType
) {
// use only first return type
// @TODO return all return types
$returnType = array_shift($returnType->getTypes());
}
if ($returnType instanceof \ReflectionNamedType) {
$returnType = $returnType->getName();
}
}
Expand Down

0 comments on commit 2e68470

Please sign in to comment.