RedisConnectionTest.php 1 KB
Newer Older
1 2
<?php

3
namespace yiiunit\extensions\redis;
4

5
use yii\redis\Connection;
6

7 8 9
/**
 * @group redis
 */
Carsten Brandt committed
10
class RedisConnectionTest extends RedisTestCase
11
{
12 13 14 15
	/**
	 * test connection to redis and selection of db
	 */
	public function testConnect()
16
	{
17
		$db = $this->getConnection(false);
18 19 20 21 22
		$db->open();
		$this->assertTrue($db->ping());
		$db->set('YIITESTKEY', 'YIITESTVALUE');
		$db->close();

23 24
		$db = $this->getConnection(false);
		$db->database = 0;
25 26 27 28
		$db->open();
		$this->assertEquals('YIITESTVALUE', $db->get('YIITESTKEY'));
		$db->close();

29 30
		$db = $this->getConnection(false);
		$db->database = 1;
31 32 33
		$db->open();
		$this->assertNull($db->get('YIITESTKEY'));
		$db->close();
34 35
	}

36
	public function keyValueData()
37 38 39 40 41 42 43
	{
		return array(
			array(123),
			array(-123),
			array(0),
			array('test'),
			array("test\r\ntest"),
44
			array(''),
45 46 47 48
		);
	}

	/**
49
	 * @dataProvider keyValueData
50 51 52 53 54
	 */
	public function testStoreGet($data)
	{
		$db = $this->getConnection(true);

55 56
		$db->set('hi', $data);
		$this->assertEquals($data, $db->get('hi'));
57 58
	}
}