Issue #3143173 by martin107, andypost, longwave: Followup: ProxyBuilder compatibility with Symfony 5 - needs to handle voids correctly

merge-requests/2419/head
Alex Pott 2020-06-15 11:33:53 +01:00
parent aa97890339
commit 4c29b0788c
No known key found for this signature in database
GPG Key ID: 31905460D4A69276
2 changed files with 38 additions and 1 deletions

View File

@ -300,7 +300,12 @@ EOS;
$function_name = $reflection_method->getName();
if (!$reflection_method->isStatic()) {
$output .= ' return $this->lazyLoadItself()->' . $function_name . '(';
if ($reflection_method->getReturnType() && $reflection_method->getReturnType()->getName() === 'void') {
$output .= ' $this->lazyLoadItself()->' . $function_name . '(';
}
else {
$output .= ' return $this->lazyLoadItself()->' . $function_name . '(';
}
}
else {
$class_name = $reflection_method->getDeclaringClass()->getName();

View File

@ -139,6 +139,30 @@ public function complexMethod(string $parameter, callable $function, \Drupal\Tes
return $this->lazyLoadItself()->complexMethod($parameter, $function, $test_service, $elements);
}
EOS;
$this->assertEquals($this->buildExpectedClass($class, $method_body), $result);
}
/**
* @covers ::buildMethodBody
*/
public function testBuildServiceMethodReturnsVoid() {
$class = TestServiceMethodReturnsVoid::class;
$result = $this->proxyBuilder->build($class);
// @todo Solve the silly linebreak for array()
$method_body = <<<'EOS'
/**
* {@inheritdoc}
*/
public function methodReturnsVoid(string $parameter): void
{
$this->lazyLoadItself()->methodReturnsVoid($parameter);
}
EOS;
$this->assertEquals($this->buildExpectedClass($class, $method_body), $result);
@ -387,6 +411,14 @@ class TestServiceComplexMethod {
}
class TestServiceMethodReturnsVoid {
public function methodReturnsVoid(string $parameter): void {
}
}
class TestServiceReturnReference {
public function &returnReference() {