Completed
Push — master ( 87170e...c34495 )
by Darío
02:39
created

testRuntimeExceptionWhenDriverIsNotDefined()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 10
rs 10
c 0
b 0
f 0
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([
0 ignored issues
show
Unused Code introduced by
The assignment to $driver is dead and can be removed.
Loading history...
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([
0 ignored issues
show
Unused Code introduced by
The assignment to $driver is dead and can be removed.
Loading history...
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
}