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.
48 lines
1.3 KiB
48 lines
1.3 KiB
12 years ago
|
<?php
|
||
|
|
||
11 years ago
|
namespace yiiunit\extensions\redis;
|
||
12 years ago
|
|
||
11 years ago
|
use Yii;
|
||
11 years ago
|
use yii\redis\Connection;
|
||
12 years ago
|
use yiiunit\TestCase;
|
||
|
|
||
11 years ago
|
Yii::setAlias('@yii/redis', __DIR__ . '/../../../../extensions/redis');
|
||
|
|
||
12 years ago
|
/**
|
||
|
* RedisTestCase is the base class for all redis related test cases
|
||
|
*/
|
||
11 years ago
|
abstract class RedisTestCase extends TestCase
|
||
12 years ago
|
{
|
||
12 years ago
|
protected function setUp()
|
||
12 years ago
|
{
|
||
11 years ago
|
$databases = $this->getParam('databases');
|
||
|
$params = isset($databases['redis']) ? $databases['redis'] : null;
|
||
11 years ago
|
if ($params === null) {
|
||
12 years ago
|
$this->markTestSkipped('No redis server connection configured.');
|
||
|
}
|
||
11 years ago
|
$connection = new Connection($params);
|
||
|
if(!@stream_socket_client($connection->hostname . ':' . $connection->port, $errorNumber, $errorDescription, 0.5)) {
|
||
|
$this->markTestSkipped('No redis server running at ' . $connection->hostname . ':' . $connection->port . ' : ' . $errorNumber . ' - ' . $errorDescription);
|
||
12 years ago
|
}
|
||
|
|
||
11 years ago
|
$this->mockApplication(['components' => ['redis' => $connection]]);
|
||
|
|
||
12 years ago
|
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
|
{
|
||
11 years ago
|
$databases = $this->getParam('databases');
|
||
11 years ago
|
$params = isset($databases['redis']) ? $databases['redis'] : [];
|
||
|
$db = new Connection($params);
|
||
12 years ago
|
if ($reset) {
|
||
12 years ago
|
$db->open();
|
||
11 years ago
|
$db->flushdb();
|
||
12 years ago
|
}
|
||
|
return $db;
|
||
|
}
|
||
|
}
|