You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.3 KiB
51 lines
1.3 KiB
12 years ago
|
<?php
|
||
|
|
||
11 years ago
|
namespace yiiunit\framework\redis;
|
||
12 years ago
|
|
||
11 years ago
|
use yii\redis\Connection;
|
||
12 years ago
|
use yiiunit\TestCase;
|
||
|
|
||
12 years ago
|
/**
|
||
|
* RedisTestCase is the base class for all redis related test cases
|
||
|
*/
|
||
12 years ago
|
class RedisTestCase extends TestCase
|
||
|
{
|
||
12 years ago
|
protected function setUp()
|
||
12 years ago
|
{
|
||
12 years ago
|
$this->mockApplication();
|
||
|
|
||
|
$databases = $this->getParam('databases');
|
||
|
$params = isset($databases['redis']) ? $databases['redis'] : null;
|
||
12 years ago
|
if ($params === null || !isset($params['dsn'])) {
|
||
|
$this->markTestSkipped('No redis server connection configured.');
|
||
|
}
|
||
|
$dsn = explode('/', $params['dsn']);
|
||
|
$host = $dsn[2];
|
||
|
if (strpos($host, ':')===false) {
|
||
|
$host .= ':6379';
|
||
|
}
|
||
|
if(!@stream_socket_client($host, $errorNumber, $errorDescription, 0.5)) {
|
||
|
$this->markTestSkipped('No redis server running at ' . $params['dsn'] . ' : ' . $errorNumber . ' - ' . $errorDescription);
|
||
|
}
|
||
|
|
||
|
parent::setUp();
|
||
12 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* @param bool $reset whether to clean up the test database
|
||
|
* @return Connection
|
||
|
*/
|
||
12 years ago
|
public function getConnection($reset = true)
|
||
12 years ago
|
{
|
||
12 years ago
|
$databases = $this->getParam('databases');
|
||
|
$params = isset($databases['redis']) ? $databases['redis'] : array();
|
||
11 years ago
|
$db = new Connection;
|
||
12 years ago
|
$db->dsn = $params['dsn'];
|
||
|
$db->password = $params['password'];
|
||
|
if ($reset) {
|
||
12 years ago
|
$db->open();
|
||
|
$db->flushall();
|
||
12 years ago
|
}
|
||
|
return $db;
|
||
|
}
|
||
|
}
|