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.
		
		
		
		
			
				
					51 lines
				
				1.3 KiB
			
		
		
			
		
	
	
					51 lines
				
				1.3 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
										 
									 | 
							
								use yiiunit\TestCase;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
								/**
							 | 
						||
| 
								 | 
							
								 * RedisTestCase is the base class for all redis related test cases
							 | 
						||
| 
								 | 
							
								 */
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
								class RedisTestCase extends TestCase
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
									protected function setUp()
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
									{
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
										$this->mockApplication();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										$databases = $this->getParam('databases');
							 | 
						||
| 
								 | 
							
										$params = isset($databases['redis']) ? $databases['redis'] : null;
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
										if ($params === null || !isset($params['dsn'])) {
							 | 
						||
| 
								 | 
							
											$this->markTestSkipped('No redis server connection configured.');
							 | 
						||
| 
								 | 
							
										}
							 | 
						||
| 
								 | 
							
										$dsn = explode('/', $params['dsn']);
							 | 
						||
| 
								 | 
							
										$host = $dsn[2];
							 | 
						||
| 
								 | 
							
										if (strpos($host, ':')===false) {
							 | 
						||
| 
								 | 
							
											$host .= ':6379';
							 | 
						||
| 
								 | 
							
										}
							 | 
						||
| 
								 | 
							
										if(!@stream_socket_client($host, $errorNumber, $errorDescription, 0.5)) {
							 | 
						||
| 
								 | 
							
											$this->markTestSkipped('No redis server running at ' . $params['dsn'] . ' : ' . $errorNumber . ' - ' . $errorDescription);
							 | 
						||
| 
								 | 
							
										}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										parent::setUp();
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
									}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
									/**
							 | 
						||
| 
								 | 
							
									 * @param bool $reset whether to clean up the test database
							 | 
						||
| 
								 | 
							
									 * @return Connection
							 | 
						||
| 
								 | 
							
									 */
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
									public function getConnection($reset = true)
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
									{
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
										$databases = $this->getParam('databases');
							 | 
						||
| 
								 | 
							
										$params = isset($databases['redis']) ? $databases['redis'] : array();
							 | 
						||
| 
								 
											12 years ago
										 
									 | 
							
										$db = new Connection;
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
										$db->dsn = $params['dsn'];
							 | 
						||
| 
								 | 
							
										$db->password = $params['password'];
							 | 
						||
| 
								 | 
							
										if ($reset) {
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
											$db->open();
							 | 
						||
| 
								 | 
							
											$db->flushall();
							 | 
						||
| 
								 
											13 years ago
										 
									 | 
							
										}
							 | 
						||
| 
								 | 
							
										return $db;
							 | 
						||
| 
								 | 
							
									}
							 | 
						||
| 
								 | 
							
								}
							 |