Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00%
0 / 1
0.00%
0 / 5
CRAP
0.00%
0 / 31
Redis
0.00%
0 / 1
0.00%
0 / 5
72
0.00%
0 / 31
 _initialize()
0.00%
0 / 1
6
0.00%
0 / 9
 _before(\Codeception\TestCase $test)
0.00%
0 / 1
6
0.00%
0 / 7
 _after(\Codeception\TestCase $test)
0.00%
0 / 1
2
0.00%
0 / 4
 cleanupRedis()
0.00%
0 / 1
2
0.00%
0 / 3
 cleanup()
0.00%
0 / 1
6
0.00%
0 / 8
<?php
namespace Codeception\Module;
use Codeception\Exception\Module as ModuleException;
use \Codeception\Util\Driver\Redis as RedisDriver;
/**
* Works with Redis database.
*
* Cleans up Redis database after each run.
*
* ## Configuration
*
* * host *required* - redis host to connect
* * port *required* - redis port.
* * database *required* - redis database.
* * cleanup: true - defined data will be purged before running every test.
*
* ## Public Properties
* * driver - contains Connection Driver
*
* ### Beta Version
*
* Report an issue if this module doesn't work for you.
*
* @author judgedim
*/
class Redis extends \Codeception\Module
{
protected $config = array(
'cleanup' => true
);
/**
* @var RedisDriver
*/
public $driver;
protected $requiredFields = array('host', 'port', 'database');
public function _initialize()
{
try {
$this->driver = new RedisDriver($this->config['host'], $this->config['port']);
$this->driver->select_db($this->config['database']);
} catch (\Exception $e) {
throw new ModuleException(__CLASS__, $e->getMessage());
}
}
public function _before(\Codeception\TestCase $test)
{
if ($this->config['cleanup']) {
$this->cleanup();
}
parent::_before($test);
}
public function _after(\Codeception\TestCase $test)
{
parent::_after($test);
}
/**
* Cleans up Redis database.
*/
public function cleanupRedis() {
$this->cleanup();
}
protected function cleanup()
{
try {
$this->driver->flushdb();
} catch (\Exception $e) {
throw new ModuleException(__CLASS__, $e->getMessage());
}
}
}