m6web / redis-mock
Library providing a PHP mock for Redis
Installs: 2 546 120
Dependents: 27
Suggesters: 0
Security: 0
Stars: 81
Watchers: 65
Forks: 59
Open Issues: 15
Requires
- php: >=7.1.0
Requires (Dev)
- atoum/atoum: ~3.4||~4.0
- predis/predis: ~1.1
- dev-master
- v5.6.0
- v5.5.0
- v5.4.0
- v5.3.0
- v5.2.0
- v5.1.0
- v5.0.1
- v5.0.0
- v4.7.0
- v4.6.1
- v4.6.0
- v4.5.0
- v4.4.1
- v4.4.0
- v4.3.0
- v4.2.1
- v4.2.0
- v4.1.0
- v4.0.0
- v3.3.2
- v3.3.1
- v3.3.0
- v3.2.0
- v3.1.0
- v3.0.0
- v2.8.0
- v2.7.0
- v2.6.0
- v2.5.0
- v2.4.0
- v2.3.0
- v2.2.0
- v2.1.0
- v2.0.1
- v2.0.0
- v1.12.0
- v1.11.0
- v1.10.0
- v1.9.0
- v1.8.0
- v1.7.0
- v1.6.0
- v1.5.0
- v1.4.0
- v1.3.0
- v1.2.1
- v1.2.0
- v1.1.0
- v1.0.1
- v1.0.0
- dev-feature/test-extension
- dev-feature-hhvm-support
This package is auto-updated.
Last update: 2024-12-01 00:08:40 UTC
README
PHP 7.1 library providing a Redis PHP mock for your tests.
Work for now only with predis
Installation
$ composer require --dev m6web/redis-mock
Functions
It currently mocks these Redis commands :
It mocks MULTI, DISCARD and EXEC commands but without any transaction behaviors, they just make the interface fluent and return each command results. PIPELINE and EXECUTE pseudo commands (client pipelining) are also mocked. EVAL, EVALSHA, WATCH and UNWATCH are just stubs—they won't execute anything
Usage
RedisMock library provides a factory able to build a mocked class of your Redis library that can be directly injected in your application :
$factory = new \M6Web\Component\RedisMock\RedisMockFactory(); $myRedisMockClass = $factory->getAdapterClass('My\Redis\Library'); $myRedisMock = new $myRedisMockClass($myParameters);
In a simpler way, if you don't need to instanciate the mocked class with custom parameters (e.g. to easier inject the mock using Symfony config file), you can use getAdapter
instead of getAdapterClass
to directly create the adapter :
$factory = new \M6Web\Component\RedisMock\RedisMockFactory(); $myRedisMock = $factory->getAdapter('My\Redis\Library');
WARNING !
- RedisMock doesn't implement all Redis features and commands. The mock can have undesired behavior if your parent class uses unsupported features.
- Storage is static and therefore shared by all instances.
Note : the factory will throw an exception by default if your parent class implements unsupported commands. If you want even so partially use the mock, you can specify the second parameter when you build it $factory->getAdapter('My\Redis\Library', true)
. The exception will then thrown only when the command is called.
Static storage & Multiple servers
The storage in the RedisMock class is organized by named areas. The default area's name is the empty string ''
but you can
specify an alternate area name when calling the factory's getAdapter
method.
getAdapter($classToExtend, $failOnlyAtRuntime = false, $ignoreConstructor = true, $storage = '')
This enables the mocking of several remote Redis servers, each one with its own storage area.
However, one same area remains statically shared across all the instances bound to it.
Tests
The development environment is provided by Vagrant and the Xotelia box.
$ cp Vagrantfile.dist Vagrantfile $ vagrant up $ vagrant ssh
$ cd /vagrant
$ composer install
$ ./vendor/bin/atoum
Credits
Developped by the Cytron Team of M6 Web.
Tested with atoum.
License
RedisMock is licensed under the MIT license.