Skip to content
Snippets Groups Projects
Unverified Commit 4c29b078 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3143173 by martin107, andypost, longwave: Followup: ProxyBuilder...

Issue #3143173 by martin107, andypost, longwave: Followup: ProxyBuilder compatibility with Symfony 5  - needs to handle voids correctly
parent aa978903
No related branches found
No related tags found
Loading
...@@ -300,7 +300,12 @@ protected function buildMethodBody(\ReflectionMethod $reflection_method) { ...@@ -300,7 +300,12 @@ protected function buildMethodBody(\ReflectionMethod $reflection_method) {
$function_name = $reflection_method->getName(); $function_name = $reflection_method->getName();
if (!$reflection_method->isStatic()) { 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 { else {
$class_name = $reflection_method->getDeclaringClass()->getName(); $class_name = $reflection_method->getDeclaringClass()->getName();
......
...@@ -139,6 +139,30 @@ public function complexMethod(string $parameter, callable $function, \Drupal\Tes ...@@ -139,6 +139,30 @@ public function complexMethod(string $parameter, callable $function, \Drupal\Tes
return $this->lazyLoadItself()->complexMethod($parameter, $function, $test_service, $elements); 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; EOS;
$this->assertEquals($this->buildExpectedClass($class, $method_body), $result); $this->assertEquals($this->buildExpectedClass($class, $method_body), $result);
...@@ -387,6 +411,14 @@ public function complexMethod(string $parameter, callable $function, TestService ...@@ -387,6 +411,14 @@ public function complexMethod(string $parameter, callable $function, TestService
} }
class TestServiceMethodReturnsVoid {
public function methodReturnsVoid(string $parameter): void {
}
}
class TestServiceReturnReference { class TestServiceReturnReference {
public function &returnReference() { public function &returnReference() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment