diff --git a/src/Framework/MockObject/Generator/proxied_method.tpl.dist b/src/Framework/MockObject/Generator/proxied_method.tpl.dist index 4dd87cd725d..a3577dbe6d3 100644 --- a/src/Framework/MockObject/Generator/proxied_method.tpl.dist +++ b/src/Framework/MockObject/Generator/proxied_method.tpl.dist @@ -12,15 +12,11 @@ } } - $__phpunit_invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( - '{class_name}', '{method_name}', $__phpunit_arguments, '{return_type}', $this, {clone_arguments} + $this->__phpunit_getInvocationMocker()->invoke( + new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( + '{class_name}', '{method_name}', $__phpunit_arguments, '{return_type}', $this, {clone_arguments}, true + ) ); - $__phpunit_invocation->setProxiedCall(); - - $this->__phpunit_getInvocationMocker()->invoke($__phpunit_invocation); - - unset($__phpunit_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 0d868f25273..751ba51236b 100644 --- a/src/Framework/MockObject/Generator/proxied_method_void.tpl.dist +++ b/src/Framework/MockObject/Generator/proxied_method_void.tpl.dist @@ -12,15 +12,11 @@ } } - $__phpunit_invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( - '{class_name}', '{method_name}', $__phpunit_arguments, '{return_type}', $this, {clone_arguments} + $this->__phpunit_getInvocationMocker()->invoke( + new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( + '{class_name}', '{method_name}', $__phpunit_arguments, '{return_type}', $this, {clone_arguments}, true + ) ); - $__phpunit_invocation->setProxiedCall(); - - $this->__phpunit_getInvocationMocker()->invoke($__phpunit_invocation); - - unset($__phpunit_invocation); - call_user_func_array(array($this->__phpunit_originalObject, "{method_name}"), $__phpunit_arguments); } diff --git a/src/Framework/MockObject/Invocation/ObjectInvocation.php b/src/Framework/MockObject/Invocation/ObjectInvocation.php index 20eb8a69dde..b0b2ef62eaf 100644 --- a/src/Framework/MockObject/Invocation/ObjectInvocation.php +++ b/src/Framework/MockObject/Invocation/ObjectInvocation.php @@ -26,9 +26,9 @@ final class ObjectInvocation extends StaticInvocation * @param object $object * @param bool $cloneObjects */ - public function __construct($className, $methodName, array $parameters, $returnType, $object, $cloneObjects = false) + public function __construct($className, $methodName, array $parameters, $returnType, $object, $cloneObjects = false, bool $proxiedCall = false) { - parent::__construct($className, $methodName, $parameters, $returnType, $cloneObjects); + parent::__construct($className, $methodName, $parameters, $returnType, $cloneObjects, $proxiedCall); $this->object = $object; } diff --git a/src/Framework/MockObject/Invocation/StaticInvocation.php b/src/Framework/MockObject/Invocation/StaticInvocation.php index 5132043c1fb..a240c19ef03 100644 --- a/src/Framework/MockObject/Invocation/StaticInvocation.php +++ b/src/Framework/MockObject/Invocation/StaticInvocation.php @@ -73,7 +73,7 @@ class StaticInvocation implements Invocation, SelfDescribing /** * @var bool */ - private $proxiedCall = false; + private $proxiedCall; /** * @param string $className @@ -81,11 +81,12 @@ class StaticInvocation implements Invocation, SelfDescribing * @param string $returnType * @param bool $cloneObjects */ - public function __construct($className, $methodName, array $parameters, $returnType, $cloneObjects = false) + public function __construct($className, $methodName, array $parameters, $returnType, $cloneObjects = false, bool $proxiedCall = false) { - $this->className = $className; - $this->methodName = $methodName; - $this->parameters = $parameters; + $this->className = $className; + $this->methodName = $methodName; + $this->parameters = $parameters; + $this->proxiedCall = $proxiedCall; if (\strtolower($methodName) === '__tostring') { $returnType = 'string'; @@ -191,11 +192,6 @@ 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 994cfc8039c..100e5d917d3 100644 --- a/tests/end-to-end/mock-objects/generator/proxy.phpt +++ b/tests/end-to-end/mock-objects/generator/proxy.phpt @@ -49,16 +49,12 @@ class ProxyFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject } } - $__phpunit_invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( - 'Foo', 'bar', $__phpunit_arguments, '', $this, true + $this->__phpunit_getInvocationMocker()->invoke( + new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( + 'Foo', 'bar', $__phpunit_arguments, '', $this, true, true + ) ); - $__phpunit_invocation->setProxiedCall(); - - $this->__phpunit_getInvocationMocker()->invoke($__phpunit_invocation); - - unset($__phpunit_invocation); - return call_user_func_array(array($this->__phpunit_originalObject, "bar"), $__phpunit_arguments); } @@ -75,16 +71,12 @@ class ProxyFoo extends Foo implements PHPUnit\Framework\MockObject\MockObject } } - $__phpunit_invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( - 'Foo', 'baz', $__phpunit_arguments, '', $this, true + $this->__phpunit_getInvocationMocker()->invoke( + new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( + 'Foo', 'baz', $__phpunit_arguments, '', $this, true, true + ) ); - $__phpunit_invocation->setProxiedCall(); - - $this->__phpunit_getInvocationMocker()->invoke($__phpunit_invocation); - - unset($__phpunit_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 fb3a368e75a..8c7bafe7950 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,15 +35,11 @@ print $code; } } - $__phpunit_invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( - 'Foo', 'bar', $__phpunit_arguments, '', $this, false + $this->__phpunit_getInvocationMocker()->invoke( + new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( + 'Foo', 'bar', $__phpunit_arguments, '', $this, false, true + ) ); - $__phpunit_invocation->setProxiedCall(); - - $this->__phpunit_getInvocationMocker()->invoke($__phpunit_invocation); - - unset($__phpunit_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 068bff69a4b..a8b229a18b0 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,15 +35,11 @@ private function bar($arg) } } - $__phpunit_invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( - 'Foo', 'bar', $__phpunit_arguments, '', $this, false + $this->__phpunit_getInvocationMocker()->invoke( + new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( + 'Foo', 'bar', $__phpunit_arguments, '', $this, false, true + ) ); - $__phpunit_invocation->setProxiedCall(); - - $this->__phpunit_getInvocationMocker()->invoke($__phpunit_invocation); - - unset($__phpunit_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 d15fbb33958..3c698b410bc 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,15 +35,11 @@ private function bar(...$args) } } - $__phpunit_invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( - 'Foo', 'bar', $__phpunit_arguments, '', $this, false + $this->__phpunit_getInvocationMocker()->invoke( + new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( + 'Foo', 'bar', $__phpunit_arguments, '', $this, false, true + ) ); - $__phpunit_invocation->setProxiedCall(); - - $this->__phpunit_getInvocationMocker()->invoke($__phpunit_invocation); - - unset($__phpunit_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 6f50bc34074..e21007675ba 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,15 +35,11 @@ print $code; } } - $__phpunit_invocation = new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( - 'Foo', 'bar', $__phpunit_arguments, 'void', $this, false + $this->__phpunit_getInvocationMocker()->invoke( + new \PHPUnit\Framework\MockObject\Invocation\ObjectInvocation( + 'Foo', 'bar', $__phpunit_arguments, 'void', $this, false, true + ) ); - $__phpunit_invocation->setProxiedCall(); - - $this->__phpunit_getInvocationMocker()->invoke($__phpunit_invocation); - - unset($__phpunit_invocation); - call_user_func_array(array($this->__phpunit_originalObject, "bar"), $__phpunit_arguments); }