Skip to content

Commit f0db44f

Browse files
committed
Merge branch '2.2' into merge-2.2-to-master
2 parents c185c60 + aa6382b commit f0db44f

File tree

2 files changed

+241
-181
lines changed

2 files changed

+241
-181
lines changed

src/Codeception/Module/Redis.php

Lines changed: 108 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace Codeception\Module;
44

5+
use Codeception\Lib\Interfaces\RequiresPackage;
56
use Codeception\Module as CodeceptionModule;
6-
use Codeception\TestCase;
77
use Codeception\Exception\ModuleException;
88
use Codeception\TestInterface;
99
use Predis\Client as RedisDriver;
@@ -20,24 +20,36 @@
2020
*
2121
* * **`host`** (`string`, default `'127.0.0.1'`) - The Redis host
2222
* * **`port`** (`int`, default `6379`) - The Redis port
23-
* * **`database`** (`int`, no default) - The Redis database. Needs to be explicitely specified.
23+
* * **`database`** (`int`, no default) - The Redis database. Needs to be explicitly specified.
2424
* * **`cleanupBefore`**: (`string`, default `'suite'`) - Whether/when to flush the database:
2525
* * `suite`: at the beginning of every suite
2626
* * `test`: at the beginning of every test
2727
* * Any other value: never
2828
*
29+
* ### Example (`unit.suite.yml`)
30+
*
31+
* ```yaml
32+
* modules:
33+
* - Redis:
34+
* host: '127.0.0.1'
35+
* port: 6379
36+
* database: 0
37+
* cleanupBefore: 'test'
38+
* ```
39+
*
2940
* ## Public Properties
41+
*
3042
* * **driver** - Contains the Predis client/driver
3143
*
3244
* @author Marc Verney <[email protected]>
3345
*/
34-
class Redis extends CodeceptionModule
46+
class Redis extends CodeceptionModule implements RequiresPackage
3547
{
3648
/**
3749
* {@inheritdoc}
3850
*
3951
* No default value is set for the database, as this module will delete
40-
* every data in it. The user is required to explicitely set this parameter.
52+
* every data in it. The user is required to explicitly set this parameter.
4153
*/
4254
protected $config = [
4355
'host' => '127.0.0.1',
@@ -59,6 +71,11 @@ class Redis extends CodeceptionModule
5971
*/
6072
public $driver;
6173

74+
public function _requires()
75+
{
76+
return ['Predis\Client' => '"predis/predis": "^1.0"'];
77+
}
78+
6279
/**
6380
* Instructions to run after configuration is loaded
6481
*
@@ -126,25 +143,34 @@ public function cleanup()
126143
*
127144
* Examples:
128145
*
129-
* ```php?start_inline=1
146+
* ``` php
147+
* <?php
130148
* // Strings
131-
* $I->grabFromRedis('example:string')
149+
* $I->grabFromRedis('string');
150+
*
132151
* // Lists: get all members
133-
* $I->grabFromRedis('example:list')
152+
* $I->grabFromRedis('example:list');
153+
*
134154
* // Lists: get a specific member
135-
* $I->grabFromRedis('example:list', 2)
155+
* $I->grabFromRedis('example:list', 2);
156+
*
136157
* // Lists: get a range of elements
137-
* $I->grabFromRedis('example:list', 2, 4)
158+
* $I->grabFromRedis('example:list', 2, 4);
159+
*
138160
* // Sets: get all members
139-
* $I->grabFromRedis('example:set')
161+
* $I->grabFromRedis('example:set');
162+
*
140163
* // ZSets: get all members
141-
* $I->grabFromRedis('example:zset')
164+
* $I->grabFromRedis('example:zset');
165+
*
142166
* // ZSets: get a range of members
143-
* $I->grabFromRedis('example:zset', 3, 12)
167+
* $I->grabFromRedis('example:zset', 3, 12);
168+
*
144169
* // Hashes: get all fields of a key
145-
* $I->grabFromRedis('example:hash')
170+
* $I->grabFromRedis('example:hash');
171+
*
146172
* // Hashes: get a specific field of a key
147-
* $I->grabFromRedis('example:hash', 'foo')
173+
* $I->grabFromRedis('example:hash', 'foo');
148174
* ```
149175
*
150176
* @param string $key The key name
@@ -224,17 +250,22 @@ public function grabFromRedis($key)
224250
*
225251
* Examples:
226252
*
227-
* ```php?start_inline=1
253+
* ``` php
254+
* <?php
228255
* // Strings: $value must be a scalar
229-
* $I->haveInRedis('example:string', 'Obladi Oblada')
256+
* $I->haveInRedis('string', 'Obladi Oblada');
257+
*
230258
* // Lists: $value can be a scalar or an array
231-
* $I->haveInRedis('example:list', ['riri', 'fifi', 'loulou'])
259+
* $I->haveInRedis('list', ['riri', 'fifi', 'loulou']);
260+
*
232261
* // Sets: $value can be a scalar or an array
233-
* $I->haveInRedis('example:set', ['riri', 'fifi', 'loulou'])
262+
* $I->haveInRedis('set', ['riri', 'fifi', 'loulou']);
263+
*
234264
* // ZSets: $value must be an associative array with scores
235-
* $I->haveInRedis('example:set', ['riri' => 1, 'fifi' => 2, 'loulou' => 3])
265+
* $I->haveInRedis('set', ['riri' => 1, 'fifi' => 2, 'loulou' => 3]);
266+
*
236267
* // Hashes: $value must be an associative array
237-
* $I->haveInRedis('example:hash', ['obladi' => 'oblada'])
268+
* $I->haveInRedis('hash', ['obladi' => 'oblada']);
238269
* ```
239270
*
240271
* @param string $type The type of the key
@@ -302,19 +333,25 @@ public function haveInRedis($type, $key, $value)
302333
*
303334
* Examples:
304335
*
305-
* ```php?start_inline=1
336+
* ``` php
337+
* <?php
306338
* // With only one argument, only checks the key does not exist
307339
* $I->dontSeeInRedis('example:string');
340+
*
308341
* // Checks a String does not exist or its value is not the one provided
309342
* $I->dontSeeInRedis('example:string', 'life');
343+
*
310344
* // Checks a List does not exist or its value is not the one provided (order of elements is compared).
311-
* $I->dontSeeInRedis('example:list', ['riri', 'fifi', 'loulou'])
345+
* $I->dontSeeInRedis('example:list', ['riri', 'fifi', 'loulou']);
346+
*
312347
* // Checks a Set does not exist or its value is not the one provided (order of members is ignored).
313-
* $I->dontSeeInRedis('example:set', ['riri', 'fifi', 'loulou'])
348+
* $I->dontSeeInRedis('example:set', ['riri', 'fifi', 'loulou']);
349+
*
314350
* // Checks a ZSet does not exist or its value is not the one provided (scores are required, order of members is compared)
315-
* $I->dontSeeInRedis('example:zset', ['riri' => 1, 'fifi' => 2, 'loulou' => 3])
351+
* $I->dontSeeInRedis('example:zset', ['riri' => 1, 'fifi' => 2, 'loulou' => 3]);
352+
*
316353
* // Checks a Hash does not exist or its value is not the one provided (order of members is ignored).
317-
* $I->dontSeeInRedis('example:hash', ['riri' => true, 'fifi' => 'Dewey', 'loulou' => 2])
354+
* $I->dontSeeInRedis('example:hash', ['riri' => true, 'fifi' => 'Dewey', 'loulou' => 2]);
318355
* ```
319356
*
320357
* @param string $key The key name
@@ -334,21 +371,28 @@ public function dontSeeInRedis($key, $value = null)
334371
*
335372
* Examples:
336373
*
337-
* ```php?start_inline=1
374+
* ``` php
375+
* <?php
338376
* // Strings: performs a substring search
339-
* $I->dontSeeRedisKeyContains('example:string', 'bar') // true for foobar
377+
* $I->dontSeeRedisKeyContains('string', 'bar');
378+
*
340379
* // Lists
341-
* $I->dontSeeRedisKeyContains('example:list', 'poney')
380+
* $I->dontSeeRedisKeyContains('example:list', 'poney');
381+
*
342382
* // Sets
343-
* $I->dontSeeRedisKeyContains('example:set', 'cat')
383+
* $I->dontSeeRedisKeyContains('example:set', 'cat');
384+
*
344385
* // ZSets: check whether the zset has this member
345-
* $I->dontSeeRedisKeyContains('example:zset', 'jordan')
386+
* $I->dontSeeRedisKeyContains('example:zset', 'jordan');
387+
*
346388
* // ZSets: check whether the zset has this member with this score
347-
* $I->dontSeeRedisKeyContains('example:zset', 'jordan', 23)
389+
* $I->dontSeeRedisKeyContains('example:zset', 'jordan', 23);
390+
*
348391
* // Hashes: check whether the hash has this field
349-
* $I->dontSeeRedisKeyContains('example:hash', 'magic')
392+
* $I->dontSeeRedisKeyContains('example:hash', 'magic');
393+
*
350394
* // Hashes: check whether the hash has this field with this value
351-
* $I->dontSeeRedisKeyContains('example:hash', 'magic', 32)
395+
* $I->dontSeeRedisKeyContains('example:hash', 'magic', 32);
352396
* ```
353397
*
354398
* @param string $key The key
@@ -371,23 +415,29 @@ public function dontSeeRedisKeyContains($key, $item, $itemValue = null)
371415
}
372416

373417
/**
374-
* Asserts that a key exists, and optionaly that it has the provided $value
418+
* Asserts that a key exists, and optionally that it has the provided $value
375419
*
376420
* Examples:
377421
*
378-
* ```php?start_inline=1
422+
* ``` php
423+
* <?php
379424
* // With only one argument, only checks the key exists
380425
* $I->seeInRedis('example:string');
426+
*
381427
* // Checks a String exists and has the value "life"
382428
* $I->seeInRedis('example:string', 'life');
429+
*
383430
* // Checks the value of a List. Order of elements is compared.
384-
* $I->seeInRedis('example:list', ['riri', 'fifi', 'loulou'])
431+
* $I->seeInRedis('example:list', ['riri', 'fifi', 'loulou']);
432+
*
385433
* // Checks the value of a Set. Order of members is ignored.
386-
* $I->seeInRedis('example:set', ['riri', 'fifi', 'loulou'])
434+
* $I->seeInRedis('example:set', ['riri', 'fifi', 'loulou']);
435+
*
387436
* // Checks the value of a ZSet. Scores are required. Order of members is compared.
388-
* $I->seeInRedis('example:zset', ['riri' => 1, 'fifi' => 2, 'loulou' => 3])
437+
* $I->seeInRedis('example:zset', ['riri' => 1, 'fifi' => 2, 'loulou' => 3]);
438+
*
389439
* // Checks the value of a Hash. Order of members is ignored.
390-
* $I->seeInRedis('example:hash', ['riri' => true, 'fifi' => 'Dewey', 'loulou' => 2])
440+
* $I->seeInRedis('example:hash', ['riri' => true, 'fifi' => 'Dewey', 'loulou' => 2]);
391441
* ```
392442
*
393443
* @param string $key The key name
@@ -409,7 +459,8 @@ public function seeInRedis($key, $value = null)
409459
*
410460
* Examples:
411461
*
412-
* ```php?start_inline=1
462+
* ``` php
463+
* <?php
413464
* $I->sendCommandToRedis('incr', 'example:string');
414465
* $I->sendCommandToRedis('strLen', 'example:string');
415466
* $I->sendCommandToRedis('lPop', 'example:list');
@@ -434,21 +485,28 @@ public function sendCommandToRedis($command)
434485
*
435486
* Examples:
436487
*
437-
* ```php?start_inline=1
488+
* ``` php
489+
* <?php
438490
* // Strings: performs a substring search
439-
* $I->seeRedisKeyContains('example:string', 'bar') // true for foobar
491+
* $I->seeRedisKeyContains('example:string', 'bar');
492+
*
440493
* // Lists
441-
* $I->seeRedisKeyContains('example:list', 'poney')
494+
* $I->seeRedisKeyContains('example:list', 'poney');
495+
*
442496
* // Sets
443-
* $I->seeRedisKeyContains('example:set', 'cat')
497+
* $I->seeRedisKeyContains('example:set', 'cat');
498+
*
444499
* // ZSets: check whether the zset has this member
445-
* $I->seeRedisKeyContains('example:zset', 'jordan')
500+
* $I->seeRedisKeyContains('example:zset', 'jordan');
501+
*
446502
* // ZSets: check whether the zset has this member with this score
447-
* $I->seeRedisKeyContains('example:zset', 'jordan', 23)
503+
* $I->seeRedisKeyContains('example:zset', 'jordan', 23);
504+
*
448505
* // Hashes: check whether the hash has this field
449-
* $I->seeRedisKeyContains('example:hash', 'magic')
506+
* $I->seeRedisKeyContains('example:hash', 'magic');
507+
*
450508
* // Hashes: check whether the hash has this field with this value
451-
* $I->seeRedisKeyContains('example:hash', 'magic', 32)
509+
* $I->seeRedisKeyContains('example:hash', 'magic', 32);
452510
* ```
453511
*
454512
* @param string $key The key
@@ -560,7 +618,7 @@ private function checkKeyContains($key, $item, $itemValue = null)
560618
}
561619

562620
/**
563-
* Checks whether a key exists and, optionaly, whether it has a given $value
621+
* Checks whether a key exists and, optionally, whether it has a given $value
564622
*
565623
* @param string $key The key name
566624
* @param mixed $value Optional. If specified, also checks the key has this
@@ -621,7 +679,7 @@ private function checkKeyExists($key, $value = null)
621679
}
622680

623681
/**
624-
* Explicitely cast the scores of a Zset associative array as float/double
682+
* Explicitly cast the scores of a Zset associative array as float/double
625683
*
626684
* @param array $arr The ZSet associative array
627685
*

0 commit comments

Comments
 (0)