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.
		
		
		
		
			
				
					87 lines
				
				2.6 KiB
			
		
		
			
		
	
	
					87 lines
				
				2.6 KiB
			| 
											14 years ago
										 | <?php
 | ||
|  | 
 | ||
| 
											13 years ago
										 | namespace yiiunit\framework\db;
 | ||
| 
											14 years ago
										 | 
 | ||
| 
											13 years ago
										 | use yii\db\Connection;
 | ||
| 
											14 years ago
										 | 
 | ||
| 
											14 years ago
										 | class ConnectionTest extends \yiiunit\MysqlTestCase
 | ||
| 
											14 years ago
										 | {
 | ||
|  | 	function testConstruct()
 | ||
|  | 	{
 | ||
| 
											14 years ago
										 | 		$connection = $this->getConnection(false);
 | ||
| 
											14 years ago
										 | 		$params = $this->getParam('mysql');
 | ||
| 
											14 years ago
										 | 
 | ||
| 
											14 years ago
										 | 		$this->assertEquals($params['dsn'], $connection->dsn);
 | ||
|  | 		$this->assertEquals($params['username'], $connection->username);
 | ||
|  | 		$this->assertEquals($params['password'], $connection->password);
 | ||
|  | 	}
 | ||
|  | 
 | ||
|  | 	function testOpenClose()
 | ||
|  | 	{
 | ||
| 
											14 years ago
										 | 		$connection = $this->getConnection(false);
 | ||
| 
											14 years ago
										 | 
 | ||
| 
											14 years ago
										 | 		$this->assertFalse($connection->active);
 | ||
|  | 		$this->assertEquals(null, $connection->pdo);
 | ||
|  | 
 | ||
|  | 		$connection->open();
 | ||
|  | 		$this->assertTrue($connection->active);
 | ||
| 
											14 years ago
										 | 		$this->assertTrue($connection->pdo instanceof \PDO);
 | ||
| 
											14 years ago
										 | 
 | ||
|  | 		$connection->close();
 | ||
|  | 		$this->assertFalse($connection->active);
 | ||
|  | 		$this->assertEquals(null, $connection->pdo);
 | ||
|  | 
 | ||
| 
											14 years ago
										 | 		$connection = new Connection;
 | ||
|  | 		$connection->dsn = 'unknown::memory:';
 | ||
| 
											14 years ago
										 | 		$this->setExpectedException('yii\db\Exception');
 | ||
|  | 		$connection->open();
 | ||
|  | 	}
 | ||
|  | 
 | ||
| 
											14 years ago
										 | 	function testGetDriverName()
 | ||
|  | 	{
 | ||
| 
											14 years ago
										 | 		$connection = $this->getConnection(false);
 | ||
| 
											14 years ago
										 | 		$this->assertEquals('mysql', $connection->driverName);
 | ||
|  | 		$this->assertFalse($connection->active);
 | ||
|  | 	}
 | ||
|  | 
 | ||
|  | 	function testQuoteValue()
 | ||
|  | 	{
 | ||
| 
											14 years ago
										 | 		$connection = $this->getConnection(false);
 | ||
| 
											14 years ago
										 | 		$this->assertEquals(123, $connection->quoteValue(123));
 | ||
|  | 		$this->assertEquals("'string'", $connection->quoteValue('string'));
 | ||
|  | 		$this->assertEquals("'It\'s interesting'", $connection->quoteValue("It's interesting"));
 | ||
|  | 	}
 | ||
|  | 
 | ||
|  | 	function testQuoteTableName()
 | ||
|  | 	{
 | ||
| 
											14 years ago
										 | 		$connection = $this->getConnection(false);
 | ||
| 
											14 years ago
										 | 		$this->assertEquals('`table`', $connection->quoteTableName('table'));
 | ||
|  | 		$this->assertEquals('`table`', $connection->quoteTableName('`table`'));
 | ||
|  | 		$this->assertEquals('`schema`.`table`', $connection->quoteTableName('schema.table'));
 | ||
| 
											14 years ago
										 | 		$this->assertEquals('`schema.table`', $connection->quoteTableName('schema.table', true));
 | ||
| 
											14 years ago
										 | 	}
 | ||
|  | 
 | ||
|  | 	function testQuoteColumnName()
 | ||
|  | 	{
 | ||
| 
											14 years ago
										 | 		$connection = $this->getConnection(false);
 | ||
| 
											14 years ago
										 | 		$this->assertEquals('`column`', $connection->quoteColumnName('column'));
 | ||
|  | 		$this->assertEquals('`column`', $connection->quoteColumnName('`column`'));
 | ||
|  | 		$this->assertEquals('`table`.`column`', $connection->quoteColumnName('table.column'));
 | ||
| 
											14 years ago
										 | 		$this->assertEquals('`table.column`', $connection->quoteColumnName('table.column', true));
 | ||
| 
											14 years ago
										 | 	}
 | ||
|  | 
 | ||
|  | 	function testGetPdoType()
 | ||
|  | 	{
 | ||
| 
											14 years ago
										 | 		$connection = $this->getConnection(false);
 | ||
| 
											14 years ago
										 | 		$this->assertEquals(\PDO::PARAM_BOOL, $connection->getPdoType('boolean'));
 | ||
|  | 		$this->assertEquals(\PDO::PARAM_INT, $connection->getPdoType('integer'));
 | ||
|  | 		$this->assertEquals(\PDO::PARAM_STR, $connection->getPdoType('string'));
 | ||
|  | 		$this->assertEquals(\PDO::PARAM_NULL, $connection->getPdoType('NULL'));
 | ||
|  | 	}
 | ||
|  | 
 | ||
|  | 	function testAttribute()
 | ||
|  | 	{
 | ||
|  | 
 | ||
|  | 	}
 | ||
| 
											14 years ago
										 | }
 |