function InvocationHandler::invoke
Throws
\PHPUnit\Framework\MockObject\Exception
Exception
File
-
vendor/
phpunit/ phpunit/ src/ Framework/ MockObject/ Runtime/ InvocationHandler.php, line 100
Class
- InvocationHandler
- @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Namespace
PHPUnit\Framework\MockObjectCode
public function invoke(Invocation $invocation) : mixed {
$exception = null;
$hasReturnValue = false;
$returnValue = null;
foreach ($this->matchers as $match) {
try {
if ($match->matches($invocation)) {
$value = $match->invoked($invocation);
if (!$hasReturnValue) {
$returnValue = $value;
$hasReturnValue = true;
}
}
} catch (Exception $e) {
$exception = $e;
}
}
if ($exception !== null) {
throw $exception;
}
if ($hasReturnValue) {
return $returnValue;
}
if (!$this->returnValueGeneration) {
if (strtolower($invocation->methodName()) === '__tostring') {
return '';
}
throw new ReturnValueNotConfiguredException($invocation);
}
return $invocation->generateReturnValue();
}