Backported from PHPUnit 7 for PHPUnit 5 https://github.com/sebastianbergmann/phpunit/commit/e11397fed729bfef7a9c76f7b193c27ad5710f6b diff -up ./src/Framework/MockObject/Generator.php.php74 ./src/Framework/MockObject/Generator.php --- ./src/Framework/MockObject/Generator.php.php74 2019-08-21 10:15:13.489571552 +0200 +++ ./src/Framework/MockObject/Generator.php 2019-08-21 10:19:40.211435595 +0200 @@ -1007,7 +1007,11 @@ class PHPUnit_Framework_MockObject_Gener } if ($this->hasReturnType($method)) { - $returnType = (string) $method->getReturnType(); + if (PHP_VERSION_ID >= 70100) { + $returnType = $method->getReturnType()->getName(); + } else { + $returnType = (string) $method->getReturnType(); + } } else { $returnType = ''; } @@ -1190,12 +1194,19 @@ class PHPUnit_Framework_MockObject_Gener $typeDeclaration = ''; if (!$forCall) { - if ($this->hasType($parameter) && (string) $parameter->getType() !== 'self') { + if ($this->hasType($parameter)) { + if (PHP_VERSION_ID >= 70100) { + $typename = $parameter->getType()->getName(); + } else { + $typename = (string) $parameter->getType(); + } + } + if ($this->hasType($parameter) && $typename !== 'self') { if (version_compare(PHP_VERSION, '7.1', '>=') && $parameter->allowsNull() && !$parameter->isVariadic()) { $nullable = '?'; } - $typeDeclaration = (string) $parameter->getType() . ' '; + $typeDeclaration = $typename . ' '; } elseif ($parameter->isArray()) { $typeDeclaration = 'array '; } elseif ($parameter->isCallable()) {