class baseClass
{
public function __construct()
{
}
public function methodToBeMocked()
{
// do somthing
}
}
class childClass extends baseClass
{
public function __construct()
{
parent::__construct($doctrine, $securityContext);
}
public function methodUsingMethodToBeMocked()
{
// do somthing
$this->methodToBeMocked();
}
}
When I am trying to mock the methodToBeMocked in stubbed childClass.
$this->mockChildClass = $this->getMockBuilder('\childClass')
->setMockClassName('Mock_Child_Class')
->setConstructorArgs(
[
// arguments
]
)
->setMethods(['methodToBeMocked'])
->getMock();
$this->mockChildClass
->expects($this->once())
->method('methodToBeMocked')
->will($this->returnValue(null));
Instead of calling mocked method and return value, actual baseClass method is called. Need to call the mocked method.