Completed
Push — develop ( d7b1aa...a27bf4 )
by Oyebanji Jacob
02:23
created

testCreateDatabaseSourceStringThrowsDatabaseDriverNotSupportedExceptionWhenUnknownDriverIsPassed()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php 
2
3
use Pyjac\ORM\DatabaseConnectionStringFactory;
4
use Pyjac\ORM\Exception\DatabaseDriverNotSupportedException;
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 $databaseConnectionStringFactoryTest;
14
15
    /**
16
     * Configuration array.
17
     * @var array
18
     */
19
    protected $config;
20
21
    protected function setUp()
22
    {   
23
        $this->config = ['DBNAME' => 'Pyjac', 'DRIVER' => '', 'PASSWORD' => 'secret', 'HOSTNAME' => 'localhost', 'USERNAME' => 'pyjac'];
24
        $this->databaseConnectionStringFactory = new DatabaseConnectionStringFactory();
0 ignored issues
show
Bug introduced by
The property databaseConnectionStringFactory does not seem to exist. Did you mean databaseConnectionStringFactoryTest?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
25
    }
26
27
    public function testCreateDatabaseSourceStringReturnsCorrectPostgresDatabaseSourceString()
28
    {
29
        $this->config['DRIVER']= 'postgres';
30
        $dsn = $this->databaseConnectionStringFactory->createDatabaseSourceString($this->config);
0 ignored issues
show
Bug introduced by
The property databaseConnectionStringFactory does not seem to exist. Did you mean databaseConnectionStringFactoryTest?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
31
        $this->assertEquals("pgsql:host=localhost;dbname=Pyjac", $dsn);
32
    }
33
34
    public function testCreateDatabaseSourceStringReturnsCorrectMYSqlDatabaseSourceString()
35
    {
36
        $this->config['DRIVER']= 'mysql';
37
        $dsn = $this->databaseConnectionStringFactory->createDatabaseSourceString($this->config);
0 ignored issues
show
Bug introduced by
The property databaseConnectionStringFactory does not seem to exist. Did you mean databaseConnectionStringFactoryTest?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
38
        $this->assertEquals("mysql:host=localhost;dbname=Pyjac", $dsn);
39
    }
40
41
    public function testCreateDatabaseSourceStringReturnsCorrectSQLiteDatabaseSourceString()
42
    {
43
        $this->config['DRIVER']= 'sqlite';
44
        $dsn = $this->databaseConnectionStringFactory->createDatabaseSourceString($this->config);
0 ignored issues
show
Bug introduced by
The property databaseConnectionStringFactory does not seem to exist. Did you mean databaseConnectionStringFactoryTest?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
45
        $this->assertEquals("sqlite::memory:", $dsn);
46
    }
47
48
     /**
49
     * @expectedException Pyjac\ORM\Exception\DatabaseDriverNotSupportedException
50
     */
51
    public function testCreateDatabaseSourceStringThrowsDatabaseDriverNotSupportedExceptionWhenUnknownDriverIsPassed()
52
    {
53
        $this->config['DRIVER']= 'pyjac';
54
        $dsn = $this->databaseConnectionStringFactory->createDatabaseSourceString($this->config);
0 ignored issues
show
Bug introduced by
The property databaseConnectionStringFactory does not seem to exist. Did you mean databaseConnectionStringFactoryTest?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
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...
55
    }
56
}