I am writing PHP Unit test and I have class with public method testMeMethod
(which I want to test) and private method privateMethod
(which is called by public method). I am mocking my class like this:
$constructorArgs = array(
'foo',
'void'
);
$myMock = $this->getMockBuilder('\some\namespace\MockMeClass')
->setConstructorArgs($constructorArgs)
->getMock();
But this will make all methods stubs and I need to test my public method. I need stub just private method, so I tried:
$myMock = $this->getMockBuilder('\some\namespace\MockMeClass')
->setConstructorArgs($constructorArgs)
->setMethods(array('privateMethod'))
->getMock();
$myMock->expects($this->any())->method('privateMethod')->will($this->returnValue('Return this'));
But even after that, if I call:
$myMock->testMeMethod();
Actual public method code is processed, but for private method too. Why is not private method overwritten to simply return Return this
without running actual code?