diff --git a/ChangeLog-7.5.md b/ChangeLog-7.5.md index 87f4d6d6490..2b12480374a 100644 --- a/ChangeLog-7.5.md +++ b/ChangeLog-7.5.md @@ -2,6 +2,12 @@ All notable changes of the PHPUnit 7.5 release series are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. +## [7.5.9] - 2019-MM-DD + +### Fixed + +* Fixed [#3607](https://github.com/sebastianbergmann/phpunit/issues/3607): Return value generation interferes with proxying to original method + ## [7.5.8] - 2019-03-26 ### Fixed @@ -87,6 +93,7 @@ All notable changes of the PHPUnit 7.5 release series are documented in this fil * Fixed [#3429](https://github.com/sebastianbergmann/phpunit/pull/3429): Inefficient loop in `getHookMethods()` * Fixed [#3437](https://github.com/sebastianbergmann/phpunit/pull/3437): JUnit logger skips PHPT tests +[7.5.9]: https://github.com/sebastianbergmann/phpunit/compare/7.5.8...7.5.9 [7.5.8]: https://github.com/sebastianbergmann/phpunit/compare/7.5.7...7.5.8 [7.5.7]: https://github.com/sebastianbergmann/phpunit/compare/7.5.6...7.5.7 [7.5.6]: https://github.com/sebastianbergmann/phpunit/compare/7.5.5...7.5.6 diff --git a/src/Framework/MockObject/Generator/proxied_method.tpl.dist b/src/Framework/MockObject/Generator/proxied_method.tpl.dist index fd9e71b8a54..96893e4ec3a 100644 --- a/src/Framework/MockObject/Generator/proxied_method.tpl.dist +++ b/src/Framework/MockObject/Generator/proxied_method.tpl.dist @@ -12,11 +12,13 @@ } } - $this->__phpunit_getInvocationMocker()->invoke( - new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( - '{class_name}', '{method_name}', $__phpunit_arguments, '{return_type}', $this, {clone_arguments} - ) + $invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( + '{class_name}', '{method_name}', $__phpunit_arguments, '{return_type}', $this, {clone_arguments} ); + $invocation->setProxiedCall(); + + $this->__phpunit_getInvocationMocker()->invoke($invocation); + return call_user_func_array(array($this->__phpunit_originalObject, "{method_name}"), $__phpunit_arguments); } diff --git a/src/Framework/MockObject/Generator/proxied_method_void.tpl.dist b/src/Framework/MockObject/Generator/proxied_method_void.tpl.dist index 63c337bc59b..9b209becdf8 100644 --- a/src/Framework/MockObject/Generator/proxied_method_void.tpl.dist +++ b/src/Framework/MockObject/Generator/proxied_method_void.tpl.dist @@ -12,11 +12,13 @@ } } - $this->__phpunit_getInvocationMocker()->invoke( - new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( - '{class_name}', '{method_name}', $__phpunit_arguments, '{return_type}', $this, {clone_arguments} - ) + $invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( + '{class_name}', '{method_name}', $__phpunit_arguments, '{return_type}', $this, {clone_arguments} ); + $invocation->setProxiedCall(); + + $this->__phpunit_getInvocationMocker()->invoke($invocation); + call_user_func_array(array($this->__phpunit_originalObject, "{method_name}"), $__phpunit_arguments); } diff --git a/src/Framework/MockObject/Invocation/StaticInvocation.php b/src/Framework/MockObject/Invocation/StaticInvocation.php index 61be6002e06..7d87488ca44 100644 --- a/src/Framework/MockObject/Invocation/StaticInvocation.php +++ b/src/Framework/MockObject/Invocation/StaticInvocation.php @@ -70,6 +70,11 @@ class StaticInvocation implements Invocation, SelfDescribing */ private $isReturnTypeNullable = false; + /** + * @var bool + */ + private $proxiedCall = false; + /** * @param string $className * @param string $methodName @@ -138,7 +143,7 @@ public function isReturnTypeNullable(): bool */ public function generateReturnValue() { - if ($this->isReturnTypeNullable) { + if ($this->isReturnTypeNullable || $this->proxiedCall) { return; } @@ -186,6 +191,11 @@ public function generateReturnValue() } } + public function setProxiedCall(): void + { + $this->proxiedCall = true; + } + public function toString(): string { $exporter = new Exporter; diff --git a/tests/end-to-end/mock-objects/generator/proxy.phpt b/tests/end-to-end/mock-objects/generator/proxy.phpt index 45272591b60..c5f6ba76cb0 100644 --- a/tests/end-to-end/mock-objects/generator/proxy.phpt +++ b/tests/end-to-end/mock-objects/generator/proxy.phpt @@ -49,12 +49,14 @@ class ProxyFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject } } - $this->__phpunit_getInvocationMocker()->invoke( - new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( - 'Foo', 'bar', $__phpunit_arguments, '', $this, true - ) + $invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( + 'Foo', 'bar', $__phpunit_arguments, '', $this, true ); + $invocation->setProxiedCall(); + + $this->__phpunit_getInvocationMocker()->invoke($invocation); + return call_user_func_array(array($this->__phpunit_originalObject, "bar"), $__phpunit_arguments); } @@ -71,12 +73,14 @@ class ProxyFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject } } - $this->__phpunit_getInvocationMocker()->invoke( - new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( - 'Foo', 'baz', $__phpunit_arguments, '', $this, true - ) + $invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( + 'Foo', 'baz', $__phpunit_arguments, '', $this, true ); + $invocation->setProxiedCall(); + + $this->__phpunit_getInvocationMocker()->invoke($invocation); + return call_user_func_array(array($this->__phpunit_originalObject, "baz"), $__phpunit_arguments); } diff --git a/tests/end-to-end/mock-objects/mock-method/call_original.phpt b/tests/end-to-end/mock-objects/mock-method/call_original.phpt index 4195be7f3c3..acf41265ae4 100644 --- a/tests/end-to-end/mock-objects/mock-method/call_original.phpt +++ b/tests/end-to-end/mock-objects/mock-method/call_original.phpt @@ -35,11 +35,13 @@ print $code; } } - $this->__phpunit_getInvocationMocker()->invoke( - new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( - 'Foo', 'bar', $__phpunit_arguments, '', $this, false - ) + $invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( + 'Foo', 'bar', $__phpunit_arguments, '', $this, false ); + $invocation->setProxiedCall(); + + $this->__phpunit_getInvocationMocker()->invoke($invocation); + return call_user_func_array(array($this->__phpunit_originalObject, "bar"), $__phpunit_arguments); } diff --git a/tests/end-to-end/mock-objects/mock-method/call_original_with_argument.phpt b/tests/end-to-end/mock-objects/mock-method/call_original_with_argument.phpt index cff9ab6d0ae..91cde635f66 100644 --- a/tests/end-to-end/mock-objects/mock-method/call_original_with_argument.phpt +++ b/tests/end-to-end/mock-objects/mock-method/call_original_with_argument.phpt @@ -35,11 +35,13 @@ private function bar($arg) } } - $this->__phpunit_getInvocationMocker()->invoke( - new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( - 'Foo', 'bar', $__phpunit_arguments, '', $this, false - ) + $invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( + 'Foo', 'bar', $__phpunit_arguments, '', $this, false ); + $invocation->setProxiedCall(); + + $this->__phpunit_getInvocationMocker()->invoke($invocation); + return call_user_func_array(array($this->__phpunit_originalObject, "bar"), $__phpunit_arguments); } diff --git a/tests/end-to-end/mock-objects/mock-method/call_original_with_argument_variadic.phpt b/tests/end-to-end/mock-objects/mock-method/call_original_with_argument_variadic.phpt index 8580ab1426f..e35d7bbaa58 100644 --- a/tests/end-to-end/mock-objects/mock-method/call_original_with_argument_variadic.phpt +++ b/tests/end-to-end/mock-objects/mock-method/call_original_with_argument_variadic.phpt @@ -35,11 +35,13 @@ private function bar(...$args) } } - $this->__phpunit_getInvocationMocker()->invoke( - new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( - 'Foo', 'bar', $__phpunit_arguments, '', $this, false - ) + $invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( + 'Foo', 'bar', $__phpunit_arguments, '', $this, false ); + $invocation->setProxiedCall(); + + $this->__phpunit_getInvocationMocker()->invoke($invocation); + return call_user_func_array(array($this->__phpunit_originalObject, "bar"), $__phpunit_arguments); } diff --git a/tests/end-to-end/mock-objects/mock-method/call_original_with_return_type_void.phpt b/tests/end-to-end/mock-objects/mock-method/call_original_with_return_type_void.phpt index d9512b8a418..b93fd8a5075 100644 --- a/tests/end-to-end/mock-objects/mock-method/call_original_with_return_type_void.phpt +++ b/tests/end-to-end/mock-objects/mock-method/call_original_with_return_type_void.phpt @@ -35,11 +35,13 @@ print $code; } } - $this->__phpunit_getInvocationMocker()->invoke( - new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( - 'Foo', 'bar', $__phpunit_arguments, 'void', $this, false - ) + $invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( + 'Foo', 'bar', $__phpunit_arguments, 'void', $this, false ); + $invocation->setProxiedCall(); + + $this->__phpunit_getInvocationMocker()->invoke($invocation); + call_user_func_array(array($this->__phpunit_originalObject, "bar"), $__phpunit_arguments); }