Skip to content

Commit

Permalink
Simplify fix for #3607 as the StaticInvocation and ObjectInvocation c…
Browse files Browse the repository at this point in the history
…lasses are not covered by the backward compatibility promise
  • Loading branch information
sebastianbergmann committed Apr 19, 2019
1 parent 4dca857 commit 8b9c6c3
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 76 deletions.
12 changes: 4 additions & 8 deletions src/Framework/MockObject/Generator/proxied_method.tpl.dist
Expand Up @@ -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);
}
12 changes: 4 additions & 8 deletions src/Framework/MockObject/Generator/proxied_method_void.tpl.dist
Expand Up @@ -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);
}
4 changes: 2 additions & 2 deletions src/Framework/MockObject/Invocation/ObjectInvocation.php
Expand Up @@ -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;
}
Expand Down
16 changes: 6 additions & 10 deletions src/Framework/MockObject/Invocation/StaticInvocation.php
Expand Up @@ -73,19 +73,20 @@ class StaticInvocation implements Invocation, SelfDescribing
/**
* @var bool
*/
private $proxiedCall = false;
private $proxiedCall;

/**
* @param string $className
* @param string $methodName
* @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';
Expand Down Expand Up @@ -191,11 +192,6 @@ public function generateReturnValue()
}
}

public function setProxiedCall(): void
{
$this->proxiedCall = true;
}

public function toString(): string
{
$exporter = new Exporter;
Expand Down
24 changes: 8 additions & 16 deletions tests/end-to-end/mock-objects/generator/proxy.phpt
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down
12 changes: 4 additions & 8 deletions tests/end-to-end/mock-objects/mock-method/call_original.phpt
Expand Up @@ -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);
}
Expand Up @@ -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);
}
Expand Up @@ -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);
}
Expand Up @@ -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);
}

0 comments on commit 8b9c6c3

Please sign in to comment.