Skip to content

Commit

Permalink
feat(PhpUnit) - add php 8.0 compatibility part 4
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 0c5b82b commit f2e23a2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/Generator/Helper/CodeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,6 @@ public function parseMethodsFromSource(string $sourceName): array
*/
protected function getMethodReturnType(ReflectionMethod $reflectionMethod): string
{
$returnType = null;
$className = $reflectionMethod->getDeclaringClass()->getName();

if (in_array($reflectionMethod->getName(), self::METHOD_NAMES_RETURN_SELF, true)) {
Expand All @@ -534,7 +533,7 @@ protected function getMethodReturnType(ReflectionMethod $reflectionMethod): stri

if (
class_exists('ReflectionUnionType') &&
$className instanceof \ReflectionUnionType
$returnType instanceof \ReflectionUnionType
) {
// use only first return type
// @TODO return all return types
Expand All @@ -546,7 +545,7 @@ class_exists('ReflectionUnionType') &&
}
}

if (!$returnType || $returnType === 'array') {
if (!$returnType || $returnType === DataTypeInterface::TYPE_ARRAY) {
$returnType = $this->getReturnFromReflectionMethodAnnotation($reflectionMethod, false, true);

if (null === $returnType) {
Expand Down
2 changes: 1 addition & 1 deletion src/Generator/Mock/Mockery.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function generateMockCode(

if (
class_exists('ReflectionUnionType') &&
$className instanceof \ReflectionUnionType
$returnType instanceof \ReflectionUnionType
) {
// use only first return type
// @TODO return all return types
Expand Down

0 comments on commit f2e23a2

Please sign in to comment.