I am trying to make fun of the Predis client in a PHPUnit test. When I call the method I tried to mock, at the end of the test, PHPUnit tells me that the expectations were not met.
Here is a sample code that reproduces my problem:
class MockRedisTest extends \PHPUnit_Framework_TestCase {
private $mockRedis;
public function testMockRedis() {
$mockRedis = $this->getMock('Predis\\Client');
$mockRedis->expects( $this->once())
->method("exists")
->with($this->equalTo("query-key"))
->will($this->returnValue(true));
$mockRedis->exists("query-key");
}
}
And PHPUnit believes that the method was not called:
1) MockRedisTest :: testMockRedis Waiting error for the method name is equal when called 1 time (s). It was expected that the method would be called 1 time, actually called 0 times.
Why? Is this because the Predis client uses __call to answer method calls that match redis commands?
UPDATE: I get the impression that this has something to do with the __call method. Code change for this:
public function testMockRedis() {
$mockRedis = $this->getMock('Predis\\Client');
$mockRedis->expects( $this->once())
->method("__call")
->with("exists", $this->equalTo(array("query-key")))
->will($this->returnValue(true));
$mockRedis->exists("query-key");
}
, . , __call ?