|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* DronePHP (http://www.dronephp.com) |
|
4
|
|
|
* |
|
5
|
|
|
* @link http://github.com/Pleets/DronePHP |
|
6
|
|
|
* @copyright Copyright (c) 2016-2018 Pleets. (http://www.pleets.org) |
|
7
|
|
|
* @license http://www.dronephp.com/license |
|
8
|
|
|
* @author Darío Rivera <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace DroneTest\Util; |
|
11
|
|
|
|
|
12
|
|
|
use Drone\Db\Driver\DriverFactory; |
|
13
|
|
|
use PHPUnit\Framework\TestCase; |
|
14
|
|
|
|
|
15
|
|
|
class DriverFactoryTest extends TestCase |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* Tests if we can build a ltrim statement with SQLFunction |
|
19
|
|
|
* |
|
20
|
|
|
* @return null |
|
21
|
|
|
*/ |
|
22
|
|
|
public function testDriverCreation() |
|
23
|
|
|
{ |
|
24
|
|
|
$driver = DriverFactory::create([ |
|
25
|
|
|
"dbhost" => "localhost", |
|
26
|
|
|
"dbuser" => "root", |
|
27
|
|
|
"dbpass" => "", |
|
28
|
|
|
"dbname" => "test", |
|
29
|
|
|
"dbchar" => "utf8", |
|
30
|
|
|
"dbport" => "3306", |
|
31
|
|
|
'driver' => 'Mysqli', |
|
32
|
|
|
"auto_connect" => false |
|
33
|
|
|
]); |
|
34
|
|
|
|
|
35
|
|
|
$this->assertInstanceOf('\Drone\Db\Driver\MySQL', $driver); |
|
36
|
|
|
$this->assertEquals('localhost', $driver->getDbhost()); |
|
37
|
|
|
$this->assertEquals('root', $driver->getDbuser()); |
|
38
|
|
|
$this->assertEquals('test', $driver->getDbname()); |
|
39
|
|
|
$this->assertEquals('utf8', $driver->getDbchar()); |
|
40
|
|
|
$this->assertEquals('3306', $driver->getDbport()); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Tests handling when driver has not been declared |
|
45
|
|
|
* |
|
46
|
|
|
* @expectedException RuntimeException |
|
47
|
|
|
*/ |
|
48
|
|
|
public function testRuntimeExceptionWhenDriverIsNotDefined() |
|
49
|
|
|
{ |
|
50
|
|
|
$driver = DriverFactory::create([ |
|
|
|
|
|
|
51
|
|
|
"dbhost" => "localhost", |
|
52
|
|
|
"dbuser" => "root", |
|
53
|
|
|
"dbpass" => "", |
|
54
|
|
|
"dbname" => "test", |
|
55
|
|
|
"dbchar" => "utf8", |
|
56
|
|
|
"dbport" => "3306", |
|
57
|
|
|
"auto_connect" => false |
|
58
|
|
|
]); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Tests handling when driver does not exists |
|
63
|
|
|
* |
|
64
|
|
|
* @expectedException RuntimeException |
|
65
|
|
|
*/ |
|
66
|
|
|
public function testRuntimeExceptionWhenDriverDoesNotExists() |
|
67
|
|
|
{ |
|
68
|
|
|
$driver = DriverFactory::create([ |
|
|
|
|
|
|
69
|
|
|
"dbhost" => "localhost", |
|
70
|
|
|
"dbuser" => "root", |
|
71
|
|
|
"dbpass" => "", |
|
72
|
|
|
"dbname" => "test", |
|
73
|
|
|
"dbchar" => "utf8", |
|
74
|
|
|
"dbport" => "3306", |
|
75
|
|
|
'driver' => 'fooBarDriver', |
|
76
|
|
|
"auto_connect" => false |
|
77
|
|
|
]); |
|
78
|
|
|
} |
|
79
|
|
|
} |