How to mock a Predis client for testing Redis operations

Viewed 2220

In a Laravel Lumen 5.5 installation, I have created a class that interacts with a Redis instance via Predis. I have the predis/predis and illuminate/redis packages and registered the Redis service provider.

My class runs some redis commands by pipelining them, as to save on the number of operations. My manual tests against a local redis server seem to work fine, as I can verify that the data gets written as expected.

I now want to create unit tests for my class with a mocked Predis client. I have found the following library that seems to provide the functionality that I require:

https://github.com/M6Web/RedisMock

It does support all of the operations that I use. However, I am uncertain as how to force the use of this mocked client by my class, since it simply uses the Redis client provided by the Illuminate service provider. Is that even possible?

If not through the use of the RedisMock library, are there any other ways for me to write unit tests for the redis operations - without having an actual redis server to support it?

Thanks in advance.

0 Answers
Related