function MockMethod::generateCode
Throws
File
-
vendor/
phpunit/ phpunit/ src/ Framework/ MockObject/ Generator/ MockMethod.php, line 178
Class
- MockMethod
- @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
Namespace
PHPUnit\Framework\MockObject\GeneratorCode
public function generateCode() : string {
if ($this->static) {
$templateFile = 'doubled_static_method.tpl';
}
else {
$templateFile = sprintf('%s_method.tpl', $this->callOriginalMethod ? 'proxied' : 'doubled');
}
$deprecation = $this->deprecation;
$returnResult = '';
if (!$this->returnType
->isNever() && !$this->returnType
->isVoid()) {
$returnResult = <<<'EOT'
return $__phpunit_result;
EOT;
}
if (null !== $this->deprecation) {
$deprecation = "The {$this->className}::{$this->methodName} method is deprecated ({$this->deprecation}).";
$deprecationTemplate = $this->loadTemplate('deprecation.tpl');
$deprecationTemplate->setVar([
'deprecation' => var_export($deprecation, true),
]);
$deprecation = $deprecationTemplate->render();
}
$template = $this->loadTemplate($templateFile);
$argumentsCount = 0;
if (str_contains($this->argumentsForCall, '...')) {
$argumentsCount = null;
}
elseif (!empty($this->argumentsForCall)) {
$argumentsCount = substr_count($this->argumentsForCall, ',') + 1;
}
$template->setVar([
'arguments_decl' => $this->argumentsForDeclaration,
'arguments_call' => $this->argumentsForCall,
'return_declaration' => !empty($this->returnType
->asString()) ? ': ' . $this->returnType
->asString() : '',
'return_type' => $this->returnType
->asString(),
'arguments_count' => $argumentsCount,
'class_name' => $this->className,
'method_name' => $this->methodName,
'modifier' => $this->modifier,
'reference' => $this->reference,
'clone_arguments' => $this->cloneArguments ? 'true' : 'false',
'deprecation' => $deprecation,
'return_result' => $returnResult,
]);
return $template->render();
}