Have you considered not mocking it? If you feel that you have to mock Redis, why do you feel that way? Redis is so fast I don't think you can make a case for mocking it for speed reasons. The mocking library you are referring to claims to have un-mocked Redis features that could be a hangup. Consider using Redis instead of the mocking library, unless you have a specific reason why you can't.
If you cannot use Redis, can you extract the parts of the class that are calling redis to another class or repository and then mock that?
class SomeClassThatCallsRedis {
public function doSomething($params){
// do some stuff
$this->store($params);
return $value;
}
private function store($params)
{
// store some things using redis commands here...
}
}
becomes
class SomeClassThatCallsRedis {
public function doSomething($params){
// do some stuff
$this->store($params);
return $value;
}
private function store($params)
{
$redis = app(RedisRepository::class);
return $redis->store($params);
}
}
class RedisRepository {
public function store($params) {
// store some things using redis commands here...
}
}
In your test
public function test_some_stuff() {
$subject = new SomeClassThatCallsRedis();
$redis = Mockery::mock(RedisRepository::class);
app()->instance(RedisRepository::class, $redis);
$redis->shouldReceive('store')
->with($params)
->once()
->andReturn(true);
$subject->doSomething($params);
}
Obviously this is pseudo code but you get the general idea. Architect your class so you can mock the Redis store.