I am using PHPUnit 3.6.10 (unfortunately, I canβt upgrade to a newer version now). Dealing with a mockery of some outdated code, I got a strange error. I tried Google, only the results related to static methods appeared, which is not my business.
The presence of this class:
class ServicesMapper extends DbMapper { //... (some methods) public function saveTravel(ServiceTravel $oTravel) { $this->getAdapter()->insert('services_travels', $oTravel->getToArray()); } //... (some methods) }
I am trying to mock this:
(inside unit test class)
private function getServicesMapperStub() { $stub = $this->getMock('ServicesMapper'); $stub->expects($this->any()) ->method('searchBy') ->will($this->returnValue(array())); return $stub; }
Now, during the execution of this fake test (I know that this test does nothing, it just shows the problem):
public function fakeMockTest(){ $serviceMapper = $this->getServicesMapperStub(); $this->assertTrue(true); }
I get this error:
Declaration of Mock_ServicesMapper_60b00178::saveTravel() should be compatible with ServicesMapper::saveTravel(ServiceTravel $oTravel)
I use this style of bullying in many places, it works well, except in this particular case. What is wrong with my code?
BTW: I also tried to solve this problem by mocking the saveTravel method, with no luck.
source share