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

3
namespace yiiunit\framework\redis;
4

5
use yii\redis\Connection;
6

Carsten Brandt committed
7
class RedisConnectionTest extends RedisTestCase
8
{
9 10 11 12 13 14 15 16 17 18 19 20 21 22
	/**
	 * Empty DSN should throw exception
	 * @expectedException \yii\base\InvalidConfigException
	 */
	public function testEmptyDSN()
	{
		$db = new Connection();
		$db->open();
	}

	/**
	 * test connection to redis and selection of db
	 */
	public function testConnect()
23 24
	{
		$db = new Connection();
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
		$db->dsn = 'redis://localhost:6379';
		$db->open();
		$this->assertTrue($db->ping());
		$db->set('YIITESTKEY', 'YIITESTVALUE');
		$db->close();

		$db = new Connection();
		$db->dsn = 'redis://localhost:6379/0';
		$db->open();
		$this->assertEquals('YIITESTVALUE', $db->get('YIITESTKEY'));
		$db->close();

		$db = new Connection();
		$db->dsn = 'redis://localhost:6379/1';
		$db->open();
		$this->assertNull($db->get('YIITESTKEY'));
		$db->close();
42 43
	}

44
	public function keyValueData()
45 46 47 48 49 50 51
	{
		return array(
			array(123),
			array(-123),
			array(0),
			array('test'),
			array("test\r\ntest"),
52
			array(''),
53 54 55 56
		);
	}

	/**
57
	 * @dataProvider keyValueData
58 59 60 61 62
	 */
	public function testStoreGet($data)
	{
		$db = $this->getConnection(true);

63 64
		$db->set('hi', $data);
		$this->assertEquals($data, $db->get('hi'));
65 66
	}
}