Completed
Branch develop (32cfca)
by Oyebanji Jacob
03:26
created

DatabaseConnectionStringFactoryTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testCreateDatabaseSourceStringReturnsCorrectPostgresDatabaseSourceString() 0 6 1
1
<?php 
2
3
use Pyjac\ORM\DatabaseConnectionStringFactory;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, DatabaseConnectionStringFactory.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
4
5
class DatabaseConnectionStringFactoryTest extends PHPUnit_Framework_TestCase
6
{
7
     /**
8
     * The instance of DatabaseConnectionStringFactory used in the test.
9
     *
10
     * @var Pyjac\ORM\DatabaseConnectionStringFactory
11
     */
12
    protected $openSourceEvangelistFactory;
13
14
    /**
15
     * Configuration array.
16
     * @var array
17
     */
18
    protected $config;
19
20
    protected function setUp()
21
    {   
22
        $this->databaseConnectionStringFactoryTest = new DatabaseConnectionStringFactory();
0 ignored issues
show
Bug introduced by
The property databaseConnectionStringFactoryTest does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
    }
24
25
    public function testCreateDatabaseSourceStringReturnsCorrectPostgresDatabaseSourceString()
26
    {
27
        $config = ['DBNAME' => 'Pyjac', 'DRIVER' => 'postgres', 'PASSWORD' => 'secret', 'HOSTNAME' => 'localhost', 'USERNAME' => 'pyjac'];
28
        $dsn = $this->databaseConnectionStringFactoryTest->createDatabaseSourceString($config);
29
        $this->assertEquals("pgsql:host=localhost;dbname=Pyjac", $dsn);
30
    }
31
}