Skip to content

Commit 0c4f073

Browse files
author
Dmitriy Maltsev
committed
Redis module and driver added
0 parents  commit 0c4f073

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

src/Codeception/Module/Redis.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/**
3+
* @author judgedim
4+
*/
5+
6+
namespace Codeception\Module;
7+
8+
use \Codeception\Util\Driver\Redis as RedisDriver;
9+
10+
class Redis extends \Codeception\Module
11+
{
12+
/**
13+
* @api
14+
* @var
15+
*/
16+
public $dbh;
17+
18+
protected $isDumpFileEmpty = false;
19+
20+
protected $config = array(
21+
'cleanup' => true
22+
);
23+
24+
/**
25+
* @var \Codeception\Util\Driver\Redis
26+
*/
27+
public $driver;
28+
29+
protected $requiredFields = array('host', 'port', 'database');
30+
31+
public function _initialize()
32+
{
33+
try {
34+
$this->driver = new RedisDriver($this->config['host'], $this->config['port']);
35+
$this->driver->select_db($this->config['database']);
36+
} catch (\Exception $e) {
37+
throw new \Codeception\Exception\Module(__CLASS__, $e->getMessage());
38+
}
39+
40+
}
41+
42+
public function _before(\Codeception\TestCase $test)
43+
{
44+
if ($this->config['cleanup']) {
45+
$this->cleanup();
46+
}
47+
parent::_before($test);
48+
}
49+
50+
public function _after(\Codeception\TestCase $test)
51+
{
52+
parent::_after($test);
53+
}
54+
55+
protected function cleanup()
56+
{
57+
try {
58+
$this->driver->flushdb();
59+
60+
} catch (\Exception $e) {
61+
throw new \Codeception\Exception\Module(__CLASS__, $e->getMessage());
62+
}
63+
}
64+
65+
}

0 commit comments

Comments
 (0)