Completed
Push — master ( 456549...47da6e )
by Łukasz
02:25
created

EnvironmentLoaderSpec   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 3
dl 0
loc 14
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A it_should_load_from_dot_env() 0 11 1
1
<?php
2
3
namespace spec\Tworzenieweb\SqlProvisioner\Filesystem;
4
5
use Tworzenieweb\SqlProvisioner\Filesystem\EnvironmentLoader;
6
use PhpSpec\ObjectBehavior;
7
use Prophecy\Argument;
8
use Tworzenieweb\SqlProvisioner\Filesystem\WorkingDirectory;
9
10
/**
11
 * Class EnvironmentLoaderSpec
12
 * @package spec\Tworzenieweb\SqlProvisioner\Filesystem
13
 * @mixin EnvironmentLoader
14
 */
15
class EnvironmentLoaderSpec extends ObjectBehavior
16
{
17
    function it_should_load_from_dot_env(WorkingDirectory $workingDirectory)
0 ignored issues
show
Coding Style introduced by
it_should_load_from_dot_env uses the super-global variable $_ENV which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
18
    {
19
        $workingDirectory->getCurrentDirectoryAbsolute()->willReturn(__DIR__ . DIRECTORY_SEPARATOR . 'fixture');
20
        $this->load($workingDirectory);
21
        expect($_ENV['DATABASE_USER'])->shouldBe('[user]');
22
        expect($_ENV['DATABASE_PASSWORD'])->shouldBe('[password]');
23
        expect($_ENV['DATABASE_PORT'])->shouldBe('[port]');
24
        expect($_ENV['DATABASE_NAME'])->shouldBe('[database]');
25
        expect($_ENV['PROVISIONING_TABLE'])->shouldBe('changelog_database_deployments');
26
        expect($_ENV['PROVISIONING_TABLE_CANDIDATE_NUMBER_COLUMN'])->shouldBe('deploy_script_number');
27
    }
28
}
29