44
55use Codeception \Lib \Interfaces \RequiresPackage ;
66use Codeception \Module as CodeceptionModule ;
7- use Codeception \TestCase ;
87use Codeception \Exception \ModuleException ;
98use Codeception \TestInterface ;
109use Predis \Client as RedisDriver ;
2120 *
2221 * * **`host`** (`string`, default `'127.0.0.1'`) - The Redis host
2322 * * **`port`** (`int`, default `6379`) - The Redis port
24- * * **`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.
2524 * * **`cleanupBefore`**: (`string`, default `'suite'`) - Whether/when to flush the database:
2625 * * `suite`: at the beginning of every suite
2726 * * `test`: at the beginning of every test
2827 * * Any other value: never
2928 *
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+ *
3040 * ## Public Properties
41+ *
3142 * * **driver** - Contains the Predis client/driver
3243 *
3344 * @author Marc Verney <[email protected] > @@ -38,7 +49,7 @@ class Redis extends CodeceptionModule implements RequiresPackage
3849 * {@inheritdoc}
3950 *
4051 * No default value is set for the database, as this module will delete
41- * 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.
4253 */
4354 protected $ config = [
4455 'host ' => '127.0.0.1 ' ,
@@ -132,25 +143,34 @@ public function cleanup()
132143 *
133144 * Examples:
134145 *
135- * ```php?start_inline=1
146+ * ``` php
147+ * <?php
136148 * // Strings
137- * $I->grabFromRedis('example:string')
149+ * $I->grabFromRedis('string');
150+ *
138151 * // Lists: get all members
139- * $I->grabFromRedis('example:list')
152+ * $I->grabFromRedis('example:list');
153+ *
140154 * // Lists: get a specific member
141- * $I->grabFromRedis('example:list', 2)
155+ * $I->grabFromRedis('example:list', 2);
156+ *
142157 * // Lists: get a range of elements
143- * $I->grabFromRedis('example:list', 2, 4)
158+ * $I->grabFromRedis('example:list', 2, 4);
159+ *
144160 * // Sets: get all members
145- * $I->grabFromRedis('example:set')
161+ * $I->grabFromRedis('example:set');
162+ *
146163 * // ZSets: get all members
147- * $I->grabFromRedis('example:zset')
164+ * $I->grabFromRedis('example:zset');
165+ *
148166 * // ZSets: get a range of members
149- * $I->grabFromRedis('example:zset', 3, 12)
167+ * $I->grabFromRedis('example:zset', 3, 12);
168+ *
150169 * // Hashes: get all fields of a key
151- * $I->grabFromRedis('example:hash')
170+ * $I->grabFromRedis('example:hash');
171+ *
152172 * // Hashes: get a specific field of a key
153- * $I->grabFromRedis('example:hash', 'foo')
173+ * $I->grabFromRedis('example:hash', 'foo');
154174 * ```
155175 *
156176 * @param string $key The key name
@@ -230,17 +250,22 @@ public function grabFromRedis($key)
230250 *
231251 * Examples:
232252 *
233- * ```php?start_inline=1
253+ * ``` php
254+ * <?php
234255 * // Strings: $value must be a scalar
235- * $I->haveInRedis('example:string', 'Obladi Oblada')
256+ * $I->haveInRedis('string', 'Obladi Oblada');
257+ *
236258 * // Lists: $value can be a scalar or an array
237- * $I->haveInRedis('example:list', ['riri', 'fifi', 'loulou'])
259+ * $I->haveInRedis('list', ['riri', 'fifi', 'loulou']);
260+ *
238261 * // Sets: $value can be a scalar or an array
239- * $I->haveInRedis('example:set', ['riri', 'fifi', 'loulou'])
262+ * $I->haveInRedis('set', ['riri', 'fifi', 'loulou']);
263+ *
240264 * // ZSets: $value must be an associative array with scores
241- * $I->haveInRedis('example:set', ['riri' => 1, 'fifi' => 2, 'loulou' => 3])
265+ * $I->haveInRedis('set', ['riri' => 1, 'fifi' => 2, 'loulou' => 3]);
266+ *
242267 * // Hashes: $value must be an associative array
243- * $I->haveInRedis('example: hash', ['obladi' => 'oblada'])
268+ * $I->haveInRedis('hash', ['obladi' => 'oblada']);
244269 * ```
245270 *
246271 * @param string $type The type of the key
@@ -308,19 +333,25 @@ public function haveInRedis($type, $key, $value)
308333 *
309334 * Examples:
310335 *
311- * ```php?start_inline=1
336+ * ``` php
337+ * <?php
312338 * // With only one argument, only checks the key does not exist
313339 * $I->dontSeeInRedis('example:string');
340+ *
314341 * // Checks a String does not exist or its value is not the one provided
315342 * $I->dontSeeInRedis('example:string', 'life');
343+ *
316344 * // Checks a List does not exist or its value is not the one provided (order of elements is compared).
317- * $I->dontSeeInRedis('example:list', ['riri', 'fifi', 'loulou'])
345+ * $I->dontSeeInRedis('example:list', ['riri', 'fifi', 'loulou']);
346+ *
318347 * // Checks a Set does not exist or its value is not the one provided (order of members is ignored).
319- * $I->dontSeeInRedis('example:set', ['riri', 'fifi', 'loulou'])
348+ * $I->dontSeeInRedis('example:set', ['riri', 'fifi', 'loulou']);
349+ *
320350 * // Checks a ZSet does not exist or its value is not the one provided (scores are required, order of members is compared)
321- * $I->dontSeeInRedis('example:zset', ['riri' => 1, 'fifi' => 2, 'loulou' => 3])
351+ * $I->dontSeeInRedis('example:zset', ['riri' => 1, 'fifi' => 2, 'loulou' => 3]);
352+ *
322353 * // Checks a Hash does not exist or its value is not the one provided (order of members is ignored).
323- * $I->dontSeeInRedis('example:hash', ['riri' => true, 'fifi' => 'Dewey', 'loulou' => 2])
354+ * $I->dontSeeInRedis('example:hash', ['riri' => true, 'fifi' => 'Dewey', 'loulou' => 2]);
324355 * ```
325356 *
326357 * @param string $key The key name
@@ -340,21 +371,28 @@ public function dontSeeInRedis($key, $value = null)
340371 *
341372 * Examples:
342373 *
343- * ```php?start_inline=1
374+ * ``` php
375+ * <?php
344376 * // Strings: performs a substring search
345- * $I->dontSeeRedisKeyContains('example:string', 'bar') // true for foobar
377+ * $I->dontSeeRedisKeyContains('string', 'bar');
378+ *
346379 * // Lists
347- * $I->dontSeeRedisKeyContains('example:list', 'poney')
380+ * $I->dontSeeRedisKeyContains('example:list', 'poney');
381+ *
348382 * // Sets
349- * $I->dontSeeRedisKeyContains('example:set', 'cat')
383+ * $I->dontSeeRedisKeyContains('example:set', 'cat');
384+ *
350385 * // ZSets: check whether the zset has this member
351- * $I->dontSeeRedisKeyContains('example:zset', 'jordan')
386+ * $I->dontSeeRedisKeyContains('example:zset', 'jordan');
387+ *
352388 * // ZSets: check whether the zset has this member with this score
353- * $I->dontSeeRedisKeyContains('example:zset', 'jordan', 23)
389+ * $I->dontSeeRedisKeyContains('example:zset', 'jordan', 23);
390+ *
354391 * // Hashes: check whether the hash has this field
355- * $I->dontSeeRedisKeyContains('example:hash', 'magic')
392+ * $I->dontSeeRedisKeyContains('example:hash', 'magic');
393+ *
356394 * // Hashes: check whether the hash has this field with this value
357- * $I->dontSeeRedisKeyContains('example:hash', 'magic', 32)
395+ * $I->dontSeeRedisKeyContains('example:hash', 'magic', 32);
358396 * ```
359397 *
360398 * @param string $key The key
@@ -377,23 +415,29 @@ public function dontSeeRedisKeyContains($key, $item, $itemValue = null)
377415 }
378416
379417 /**
380- * 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
381419 *
382420 * Examples:
383421 *
384- * ```php?start_inline=1
422+ * ``` php
423+ * <?php
385424 * // With only one argument, only checks the key exists
386425 * $I->seeInRedis('example:string');
426+ *
387427 * // Checks a String exists and has the value "life"
388428 * $I->seeInRedis('example:string', 'life');
429+ *
389430 * // Checks the value of a List. Order of elements is compared.
390- * $I->seeInRedis('example:list', ['riri', 'fifi', 'loulou'])
431+ * $I->seeInRedis('example:list', ['riri', 'fifi', 'loulou']);
432+ *
391433 * // Checks the value of a Set. Order of members is ignored.
392- * $I->seeInRedis('example:set', ['riri', 'fifi', 'loulou'])
434+ * $I->seeInRedis('example:set', ['riri', 'fifi', 'loulou']);
435+ *
393436 * // Checks the value of a ZSet. Scores are required. Order of members is compared.
394- * $I->seeInRedis('example:zset', ['riri' => 1, 'fifi' => 2, 'loulou' => 3])
437+ * $I->seeInRedis('example:zset', ['riri' => 1, 'fifi' => 2, 'loulou' => 3]);
438+ *
395439 * // Checks the value of a Hash. Order of members is ignored.
396- * $I->seeInRedis('example:hash', ['riri' => true, 'fifi' => 'Dewey', 'loulou' => 2])
440+ * $I->seeInRedis('example:hash', ['riri' => true, 'fifi' => 'Dewey', 'loulou' => 2]);
397441 * ```
398442 *
399443 * @param string $key The key name
@@ -415,7 +459,8 @@ public function seeInRedis($key, $value = null)
415459 *
416460 * Examples:
417461 *
418- * ```php?start_inline=1
462+ * ``` php
463+ * <?php
419464 * $I->sendCommandToRedis('incr', 'example:string');
420465 * $I->sendCommandToRedis('strLen', 'example:string');
421466 * $I->sendCommandToRedis('lPop', 'example:list');
@@ -440,21 +485,28 @@ public function sendCommandToRedis($command)
440485 *
441486 * Examples:
442487 *
443- * ```php?start_inline=1
488+ * ``` php
489+ * <?php
444490 * // Strings: performs a substring search
445- * $I->seeRedisKeyContains('example:string', 'bar') // true for foobar
491+ * $I->seeRedisKeyContains('example:string', 'bar');
492+ *
446493 * // Lists
447- * $I->seeRedisKeyContains('example:list', 'poney')
494+ * $I->seeRedisKeyContains('example:list', 'poney');
495+ *
448496 * // Sets
449- * $I->seeRedisKeyContains('example:set', 'cat')
497+ * $I->seeRedisKeyContains('example:set', 'cat');
498+ *
450499 * // ZSets: check whether the zset has this member
451- * $I->seeRedisKeyContains('example:zset', 'jordan')
500+ * $I->seeRedisKeyContains('example:zset', 'jordan');
501+ *
452502 * // ZSets: check whether the zset has this member with this score
453- * $I->seeRedisKeyContains('example:zset', 'jordan', 23)
503+ * $I->seeRedisKeyContains('example:zset', 'jordan', 23);
504+ *
454505 * // Hashes: check whether the hash has this field
455- * $I->seeRedisKeyContains('example:hash', 'magic')
506+ * $I->seeRedisKeyContains('example:hash', 'magic');
507+ *
456508 * // Hashes: check whether the hash has this field with this value
457- * $I->seeRedisKeyContains('example:hash', 'magic', 32)
509+ * $I->seeRedisKeyContains('example:hash', 'magic', 32);
458510 * ```
459511 *
460512 * @param string $key The key
@@ -566,7 +618,7 @@ private function checkKeyContains($key, $item, $itemValue = null)
566618 }
567619
568620 /**
569- * 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
570622 *
571623 * @param string $key The key name
572624 * @param mixed $value Optional. If specified, also checks the key has this
@@ -627,7 +679,7 @@ private function checkKeyExists($key, $value = null)
627679 }
628680
629681 /**
630- * 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
631683 *
632684 * @param array $arr The ZSet associative array
633685 *
0 commit comments