2017 © Pedro PelĂĄez
 

library redis-mock

Library providing a PHP mock for Redis

image

m6web/redis-mock

Library providing a PHP mock for Redis

  • Monday, June 11, 2018
  • by M6Web
  • Repository
  • 35 Watchers
  • 47 Stars
  • 174,742 Installations
  • PHP
  • 13 Dependents
  • 0 Suggesters
  • 37 Forks
  • 13 Open issues
  • 37 Versions
  • 11 % Grown

The README.md

Redis PHP Mock Build Status Total Downloads

PHP 7.1 library providing a Redis PHP mock for your tests., (*1)

Work for now only with predis, (*2)

Installation

$ composer require --dev m6web/redis-mock

Functions

It currently mocks these Redis commands :, (*3)

Redis command Description
DBSIZE Returns the number of keys in the selected database
DEL key [key ...] Deletes one or more keys
DECR key Decrements the integer value of a key by one
DECRBY key decrement Decrements the integer value of a key by decrement value
DECRBYFLOAT key decrement Decrements the float value of a key by decrement value
EXISTS key Determines if a key exists
EXPIRE key seconds Sets a key's time to live in seconds
FLUSHDB Flushes the database
GET key Gets the value of a key
HDEL key array<fields> Delete hash fields
HEXISTS key field Determines if a hash field exists
HMGET key array<field> Gets the values of multiple hash fields
HGET key field Gets the value of a hash field
HGETALL key Gets all the fields and values in a hash
HKEYS key Gets all the fields in a hash
HLEN key Gets the number of fields in a hash
HMSET key array<field, value> Sets each value in the corresponding field
HSET key field value Sets the string value of a hash field
HSETNX key field value Sets field in the hash stored at key to value, only if field does not yet exist
HINCRBY key field increment Increments the integer stored at field in the hash stored at key by increment.
INCR key Increments the integer value of a key by one
INCRBY key increment Increments the integer value of a key by increment value
INCRBYFLOAT key increment Increments the float value of a key by increment value
KEYS pattern Finds all keys matching the given pattern
LINDEX key index Returns the element at index index in the list stored at key
LLEN key Returns the length of the list stored at key
LPUSH key value [value ...] Pushs values at the head of a list
LPOP key Pops values at the head of a list
LREM key value count Removes count instances of value from the head of a list (follows the predis parameters order)
LTRIM key start stop Removes the values of the key list which are outside the range start...stop
LRANGE key start stop Gets a range of elements from a list
MGET array<field> Gets the values of multiple keys
MSET array<field, value> Sets the string values of multiple keys
QUIT Quit the REDIS
RPUSH key value Pushs values at the tail of a list
RPOP key Pops values at the tail of a list
SCAN Iterates the set of keys in the currently selected Redis database.
SSCAN Iterates elements of Sets types.
SET key value Sets the string value of a key
SETEX key seconds value Sets the value and expiration of a key
SETNX key value Sets key to hold value if key does not exist
SADD key member [member ...] Adds one or more members to a set
SDIFF key key [key ...] Returns the members of the set resulting from the difference between the first set and all the successive sets.
SISMEMBER key member Determines if a member is in a set
SMEMBERS key Gets all the members in a set
SUNION key [key ...] Returns the members of the set resulting from the union of all the given sets.
SINTER key [key ...] Returns the members of the set resulting from the intersection of all the given sets.
SCARD key Get cardinality of set (count of members)
SREM key member [member ...] Removes one or more members from a set
TTL key  Gets the time to live for a key
TYPE key Returns the string representation of the type of the value stored at key.
ZADD key score member Adds one member to a sorted set, or update its score if it already exists
ZINCRBY key increment member Increments the score of member in the sorted set stored at key by increment
ZCARD key Returns the sorted set cardinality (number of elements) of the sorted set stored at key
ZCOUNT key min max Returns the number of elements in the stored set at key with a score between min and max.
ZRANGE key start stop [withscores] Returns the specified range of members in a sorted set
ZRANGEBYSCORE key min max options Returns a range of members in a sorted set, by score
ZRANK key member Returns the rank of member in the sorted set stored at key, with the scores ordered from low to high
ZREVRANK key member Returns the rank of member in the sorted set stored at key, with the scores ordered from high to low
ZREM key member Removes one membner from a sorted set
ZREMRANGEBYSCORE key min max Removes all members in a sorted set within the given scores
ZREVRANGE key start stop [withscores] Returns the specified range of members in a sorted set, with scores ordered from high to low
ZREVRANGEBYSCORE key min max options Returns a range of members in a sorted set, by score, with scores ordered from high to low
ZSCAN Iterates elements of Sorted Sets types.
ZSCORE key member Returns the score of member in the sorted set at key
ZUNIONSTORE dest numkeys key ... [weights ...] [aggregate SUM/MIN/MAX] Computes the union of the stored sets given by the specified keys, store the result in the destination key, and returns the number of elements of the new sorted set.

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, (*4)

Usage

RedisMock library provides a factory able to build a mocked class of your Redis library that can be directly injected in your application :, (*5)

$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 :, (*6)

$factory     = new \M6Web\Component\RedisMock\RedisMockFactory();
$myRedisMock = $factory->getAdapter('My\Redis\Library');

WARNING !, (*7)

  • 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., (*8)

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., (*9)

getAdapter($classToExtend, $failOnlyAtRuntime = false, $ignoreConstructor = true, $storage = '')

This enables the mocking of several remote Redis servers, each one with its own storage area., (*10)

However, one same area remains statically shared across all the instances bound to it., (*11)

Tests

The development environment is provided by Vagrant and the Xotelia box., (*12)

$ 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., (*13)

License

RedisMock is licensed under the MIT license., (*14)

The Versions

11/06 2018

dev-master

9999999-dev

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

mock redis

11/06 2018

v4.1.0

4.1.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

mock redis

04/06 2018

v3.3.2

3.3.2.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

mock redis

04/06 2018

v4.0.0

4.0.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

mock redis

26/03 2018

v3.3.1

3.3.1.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

mock redis

23/03 2018

dev-feature/fix-rpoplpush-null

dev-feature/fix-rpoplpush-null

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

mock redis

23/03 2018

v3.3.0

3.3.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

mock redis

19/02 2018

v3.2.0

3.2.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

mock redis

15/01 2018

v3.1.0

3.1.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

mock redis

27/11 2017

v3.0.0

3.0.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=7.1.0

 

The Development Requires

mock redis

30/10 2016

v2.8.0

2.8.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

01/07 2016

v2.7.0

2.7.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

06/02 2016

dev-feature/test-extension

dev-feature/test-extension

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

mock redis

07/12 2015

v2.6.0

2.6.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

07/10 2015

v2.5.0

2.5.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

05/10 2015

v2.4.0

2.4.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

30/08 2015

v2.3.0

2.3.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

12/11 2014

v2.2.0

2.2.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

07/11 2014

v2.1.0

2.1.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

06/08 2014

v2.0.1

2.0.1.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

30/07 2014

v2.0.0

2.0.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

19/06 2014

v1.12.0

1.12.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

10/06 2014

v1.11.0

1.11.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

20/05 2014

v1.10.0

1.10.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

13/05 2014

v1.9.0

1.9.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

03/03 2014

v1.8.0

1.8.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

18/02 2014

v1.7.0

1.7.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

17/01 2014

v1.6.0

1.6.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

16/01 2014

v1.5.0

1.5.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

07/01 2014

v1.4.0

1.4.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

27/12 2013

v1.3.0

1.3.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

19/12 2013

dev-feature-hhvm-support

dev-feature-hhvm-support

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

18/12 2013

v1.2.1

1.2.1.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

mock redis

18/12 2013

v1.2.0

1.2.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

mock redis

09/12 2013

v1.1.0

1.1.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

mock redis

06/12 2013

v1.0.1

1.0.1.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

mock redis

05/12 2013

v1.0.0

1.0.0.0

Library providing a PHP mock for Redis

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

mock redis