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.
		
		
		
		
			
				
					66 lines
				
				1.2 KiB
			
		
		
			
		
	
	
					66 lines
				
				1.2 KiB
			| 
											13 years ago
										 | <?php
 | ||
|  | 
 | ||
| 
											12 years ago
										 | namespace yiiunit\framework\redis;
 | ||
| 
											13 years ago
										 | 
 | ||
| 
											12 years ago
										 | use yii\redis\Connection;
 | ||
| 
											13 years ago
										 | 
 | ||
| 
											12 years ago
										 | class RedisConnectionTest extends RedisTestCase
 | ||
| 
											13 years ago
										 | {
 | ||
| 
											13 years ago
										 | 	/**
 | ||
|  | 	 * 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()
 | ||
| 
											13 years ago
										 | 	{
 | ||
|  | 		$db = new Connection();
 | ||
| 
											13 years ago
										 | 		$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();
 | ||
| 
											13 years ago
										 | 	}
 | ||
|  | 
 | ||
| 
											13 years ago
										 | 	public function keyValueData()
 | ||
| 
											13 years ago
										 | 	{
 | ||
|  | 		return array(
 | ||
|  | 			array(123),
 | ||
|  | 			array(-123),
 | ||
|  | 			array(0),
 | ||
|  | 			array('test'),
 | ||
|  | 			array("test\r\ntest"),
 | ||
| 
											13 years ago
										 | 			array(''),
 | ||
| 
											13 years ago
										 | 		);
 | ||
|  | 	}
 | ||
|  | 
 | ||
|  | 	/**
 | ||
| 
											13 years ago
										 | 	 * @dataProvider keyValueData
 | ||
| 
											13 years ago
										 | 	 */
 | ||
|  | 	public function testStoreGet($data)
 | ||
|  | 	{
 | ||
|  | 		$db = $this->getConnection(true);
 | ||
|  | 
 | ||
| 
											13 years ago
										 | 		$db->set('hi', $data);
 | ||
|  | 		$this->assertEquals($data, $db->get('hi'));
 | ||
| 
											13 years ago
										 | 	}
 | ||
|  | }
 |