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.
58 lines
1.0 KiB
58 lines
1.0 KiB
12 years ago
|
<?php
|
||
|
|
||
11 years ago
|
namespace yiiunit\extensions\redis;
|
||
12 years ago
|
|
||
11 years ago
|
use yii\redis\Connection;
|
||
12 years ago
|
|
||
11 years ago
|
/**
|
||
|
* @group redis
|
||
|
*/
|
||
12 years ago
|
class RedisConnectionTest extends RedisTestCase
|
||
12 years ago
|
{
|
||
12 years ago
|
/**
|
||
|
* test connection to redis and selection of db
|
||
|
*/
|
||
|
public function testConnect()
|
||
12 years ago
|
{
|
||
11 years ago
|
$db = $this->getConnection(false);
|
||
12 years ago
|
$db->open();
|
||
|
$this->assertTrue($db->ping());
|
||
|
$db->set('YIITESTKEY', 'YIITESTVALUE');
|
||
|
$db->close();
|
||
|
|
||
11 years ago
|
$db = $this->getConnection(false);
|
||
|
$db->database = 0;
|
||
12 years ago
|
$db->open();
|
||
|
$this->assertEquals('YIITESTVALUE', $db->get('YIITESTKEY'));
|
||
|
$db->close();
|
||
|
|
||
11 years ago
|
$db = $this->getConnection(false);
|
||
|
$db->database = 1;
|
||
12 years ago
|
$db->open();
|
||
|
$this->assertNull($db->get('YIITESTKEY'));
|
||
|
$db->close();
|
||
12 years ago
|
}
|
||
|
|
||
12 years ago
|
public function keyValueData()
|
||
12 years ago
|
{
|
||
|
return array(
|
||
|
array(123),
|
||
|
array(-123),
|
||
|
array(0),
|
||
|
array('test'),
|
||
|
array("test\r\ntest"),
|
||
12 years ago
|
array(''),
|
||
12 years ago
|
);
|
||
|
}
|
||
|
|
||
|
/**
|
||
12 years ago
|
* @dataProvider keyValueData
|
||
12 years ago
|
*/
|
||
|
public function testStoreGet($data)
|
||
|
{
|
||
|
$db = $this->getConnection(true);
|
||
|
|
||
12 years ago
|
$db->set('hi', $data);
|
||
|
$this->assertEquals($data, $db->get('hi'));
|
||
12 years ago
|
}
|
||
|
}
|