1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
use yii\db\dao\Connection;
class ConnectionTest extends TestCase
{
function setUp()
{
if(!extension_loaded('pdo') || !extension_loaded('pdo_mysql'))
$this->markTestSkipped('pdo and pdo_mysql extensions are required.');
}
function testConstruct()
{
$connection = $this->createConnection();
$params = $this->getParam('mysql');
$this->assertEquals($params['dsn'], $connection->dsn);
$this->assertEquals($params['username'], $connection->username);
$this->assertEquals($params['password'], $connection->password);
}
function testOpenClose()
{
$connection = $this->createConnection();
$this->assertFalse($connection->active);
$this->assertEquals(null, $connection->pdo);
$connection->open();
$this->assertTrue($connection->active);
$this->assertTrue($connection->pdo instanceof PDO);
$connection->close();
$this->assertFalse($connection->active);
$this->assertEquals(null, $connection->pdo);
$connection = new Connection('unknown::memory:');
$this->setExpectedException('yii\db\Exception');
$connection->open();
}
function testGetDriverName()
{
$connection = $this->createConnection();
$this->assertEquals('mysql', $connection->driverName);
$this->assertFalse($connection->active);
}
function testQuoteValue()
{
$connection = $this->createConnection();
$this->assertEquals(123, $connection->quoteValue(123));
$this->assertEquals("'string'", $connection->quoteValue('string'));
$this->assertEquals("'It\'s interesting'", $connection->quoteValue("It's interesting"));
}
function testQuoteTableName()
{
$connection = $this->createConnection();
$this->assertEquals('`table`', $connection->quoteTableName('table'));
$this->assertEquals('`table`', $connection->quoteTableName('`table`'));
$this->assertEquals('`schema`.`table`', $connection->quoteTableName('schema.table'));
}
function testQuoteColumnName()
{
$connection = $this->createConnection();
$this->assertEquals('`column`', $connection->quoteColumnName('column'));
$this->assertEquals('`column`', $connection->quoteColumnName('`column`'));
$this->assertEquals('`table`.`column`', $connection->quoteColumnName('table.column'));
}
function testGetPdoType()
{
$connection = $this->createConnection();
$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()
{
}
function createConnection()
{
$params = $this->getParam('mysql');
return new Connection($params['dsn'], $params['username'], $params['password']);
}
}