Using Phpunit 4.5.2, I am trying to make fun of the following class:
class Foo {
public function bar() {}
}
class MyClass
{
private $foo;
public function __construct(Foo $foo) {
$this->foo = $foo;
}
public function doSomething() {
$this->foo->bar();
}
}
I want to achieve the following:
- Fake a call to the original methods.
- Avoid the constructor (I set the foo property with reflection).
This code:
$mock = $this->getMockBuilder('MyClass')
->disableOriginalConstructor()
->enableProxyingToOriginalMethods()
->getMock()
Error with the following error message:
Argument 1 passed to MyClass :: __ construct () must be an instance of Foo, not one specified
If I remove enableProxyingToOriginalMethods (), the mock is created without errors, so it seems that when I enable proxying, this allows the constructor, despite the call to disableOriginalConstructor ().
How to enable proxy when disabling the constructor?
source
share