Skip to content

Commit

Permalink
Closes #3607
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianbergmann committed Apr 19, 2019
1 parent 2e71a95 commit fdc4cbc
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 33 deletions.
7 changes: 7 additions & 0 deletions ChangeLog-7.5.md
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions src/Framework/MockObject/Generator/proxied_method.tpl.dist
Expand Up @@ -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);
}
10 changes: 6 additions & 4 deletions src/Framework/MockObject/Generator/proxied_method_void.tpl.dist
Expand Up @@ -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);
}
12 changes: 11 additions & 1 deletion src/Framework/MockObject/Invocation/StaticInvocation.php
Expand Up @@ -70,6 +70,11 @@ class StaticInvocation implements Invocation, SelfDescribing
*/
private $isReturnTypeNullable = false;

/**
* @var bool
*/
private $proxiedCall = false;

/**
* @param string $className
* @param string $methodName
Expand Down Expand Up @@ -138,7 +143,7 @@ public function isReturnTypeNullable(): bool
*/
public function generateReturnValue()
{
if ($this->isReturnTypeNullable) {
if ($this->isReturnTypeNullable || $this->proxiedCall) {
return;
}

Expand Down Expand Up @@ -186,6 +191,11 @@ public function generateReturnValue()
}
}

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

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

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

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

0 comments on commit fdc4cbc

Please sign in to comment.