Completed
Pull Request — master (#4)
by Oyebanji Jacob
02:18
created

DatabaseConnectionStringFactoryTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 5
c 3
b 1
f 1
lcom 1
cbo 2
dl 0
loc 52
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 5 1
A testCreateDatabaseSourceStringReturnsCorrectPostgresDatabaseSourceString() 0 6 1
A testCreateDatabaseSourceStringReturnsCorrectMYSqlDatabaseSourceString() 0 6 1
A testCreateDatabaseSourceStringReturnsCorrectSQLiteDatabaseSourceString() 0 6 1
A testCreateDatabaseSourceStringThrowsDatabaseDriverNotSupportedExceptionWhenUnknownDriverIsPassed() 0 5 1
1
<?php
2
3
4
use Pyjac\ORM\DatabaseConnectionStringFactory;
5
6
class DatabaseConnectionStringFactoryTest extends PHPUnit_Framework_TestCase
7
{
8
    /**
9
     * The instance of DatabaseConnectionStringFactory used in the test.
10
     *
11
     * @var Pyjac\ORM\DatabaseConnectionStringFactory
12
     */
13
    protected $databaseConnectionStringFactory;
14
15
    /**
16
     * Configuration array.
17
     *
18
     * @var array
19
     */
20
    protected $config;
21
22
    protected function setUp()
23
    {
24
        $this->config = ['DBNAME' => 'Pyjac', 'DRIVER' => '', 'PASSWORD' => 'secret', 'HOSTNAME' => 'localhost', 'USERNAME' => 'pyjac'];
25
        $this->databaseConnectionStringFactory = new DatabaseConnectionStringFactory();
26
    }
27
28
    public function testCreateDatabaseSourceStringReturnsCorrectPostgresDatabaseSourceString()
29
    {
30
        $this->config['DRIVER'] = 'postgres';
31
        $dsn = $this->databaseConnectionStringFactory->createDatabaseSourceString($this->config);
32
        $this->assertEquals('pgsql:host=localhost;dbname=Pyjac', $dsn);
33
    }
34
35
    public function testCreateDatabaseSourceStringReturnsCorrectMYSqlDatabaseSourceString()
36
    {
37
        $this->config['DRIVER'] = 'mysql';
38
        $dsn = $this->databaseConnectionStringFactory->createDatabaseSourceString($this->config);
39
        $this->assertEquals('mysql:host=localhost;dbname=Pyjac', $dsn);
40
    }
41
42
    public function testCreateDatabaseSourceStringReturnsCorrectSQLiteDatabaseSourceString()
43
    {
44
        $this->config['DRIVER'] = 'sqlite';
45
        $dsn = $this->databaseConnectionStringFactory->createDatabaseSourceString($this->config);
46
        $this->assertEquals('sqlite::memory:', $dsn);
47
    }
48
49
    /**
50
     * @expectedException Pyjac\ORM\Exception\DatabaseDriverNotSupportedException
51
     */
52
    public function testCreateDatabaseSourceStringThrowsDatabaseDriverNotSupportedExceptionWhenUnknownDriverIsPassed()
53
    {
54
        $this->config['DRIVER'] = 'pyjac';
55
        $dsn = $this->databaseConnectionStringFactory->createDatabaseSourceString($this->config);
0 ignored issues
show
Unused Code introduced by
$dsn is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
56
    }
57
}
58