testRuntimeExceptionWhenDriverIsNotDefined()   A
last analyzed

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
11
namespace DroneTest\Util;
12
13
use Drone\Db\Driver\DriverFactory;
14
use PHPUnit\Framework\TestCase;
15
16
class DriverFactoryTest extends TestCase
17
{
18
    /**
19
     * Tests if we can build a ltrim statement with SQLFunction
20
     *
21
     * @return null
22
     */
23
    public function testDriverCreation()
24
    {
25
        $driver = DriverFactory::create([
26
            "dbhost"       => "localhost",
27
            "dbuser"       => "root",
28
            "dbpass"       => "",
29
            "dbname"       => "test",
30
            "dbchar"       => "utf8",
31
            "dbport"       => "3306",
32
            'driver'       => 'Mysqli',
33
            "auto_connect" => false,
34
        ]);
35
36
        $this->assertInstanceOf('\Drone\Db\Driver\MySQL', $driver);
37
        $this->assertEquals('localhost', $driver->getDbhost());
38
        $this->assertEquals('root', $driver->getDbuser());
39
        $this->assertEquals('test', $driver->getDbname());
40
        $this->assertEquals('utf8', $driver->getDbchar());
41
        $this->assertEquals('3306', $driver->getDbport());
42
    }
43
44
    /**
45
     * Tests handling when driver has not been declared
46
     *
47
     * @expectedException RuntimeException
48
     */
49
    public function testRuntimeExceptionWhenDriverIsNotDefined()
50
    {
51
        $driver = DriverFactory::create([
0 ignored issues
show
Unused Code introduced by
The assignment to $driver is dead and can be removed.
Loading history...
52
            "dbhost"       => "localhost",
53
            "dbuser"       => "root",
54
            "dbpass"       => "",
55
            "dbname"       => "test",
56
            "dbchar"       => "utf8",
57
            "dbport"       => "3306",
58
            "auto_connect" => false,
59
        ]);
60
    }
61
62
    /**
63
     * Tests handling when driver does not exists
64
     *
65
     * @expectedException RuntimeException
66
     */
67
    public function testRuntimeExceptionWhenDriverDoesNotExists()
68
    {
69
        $driver = DriverFactory::create([
0 ignored issues
show
Unused Code introduced by
The assignment to $driver is dead and can be removed.
Loading history...
70
            "dbhost"       => "localhost",
71
            "dbuser"       => "root",
72
            "dbpass"       => "",
73
            "dbname"       => "test",
74
            "dbchar"       => "utf8",
75
            "dbport"       => "3306",
76
            'driver'       => 'fooBarDriver',
77
            "auto_connect" => false,
78
        ]);
79
    }
80
}
81