Passed
Pull Request — master (#14)
by
unknown
02:46
created

FactoryTest::testEnvironment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 21
nc 1
nop 0
dl 0
loc 40
rs 9.584
c 0
b 0
f 0
1
<?php
2
3
namespace Northwoods\Config;
4
5
use PHPUnit\Framework\TestCase;
6
7
class FactoryTest extends TestCase
8
{
9
    /**
10
     * @var ConfigFactory
11
     */
12
    private $factory;
0 ignored issues
show
Coding Style introduced by
Private member variable "factory" must contain a leading underscore
Loading history...
Coding Style introduced by
Expected 1 blank line before member var; 0 found
Loading history...
13
14
    public function setUp()
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines before function; 1 found
Loading history...
15
    {
16
        $this->factory = new ConfigFactory();
17
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
18
19
    public function testDirectory()
20
    {
21
        $config = ConfigFactory::make([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
22
            'directory' => __DIR__ . '/../examples',
23
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
24
25
        // it implements the configuration interfaces
26
        $this->assertInstanceOf(ConfigInterface::class, $config);
27
        $this->assertInstanceOf(ConfigDirectory::class, $config);
28
29
        // it can fetch existing values
30
        $this->assertSame('America/New_York', $config->get('app.timezone'));
31
        $this->assertSame('my_password', $config->get('database.connections.default.password'));
32
33
        // it returns null for values that do not exist
34
        $this->assertNull($config->get('custom.key.option'));
35
36
        // it can set custom values
37
        $this->assertNull($config->set('custom.key.option', true));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $config->set('custom.key.option', true) targeting Northwoods\Config\ConfigCollection::set() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure the usage of $config->set('custom.key.option', true) targeting Northwoods\Config\ConfigDirectory::set() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
38
        $this->assertTrue($config->get('custom.key.option'));
39
40
        // it can sync news value with the source file
41
        
42
        // Notice: it will add any value in the memory too
43
        // for example: the following `set` will include the `custom.key.option` value from the previous `set`
44
        // $config->set('custom.dynamic.key', 'value', true);
45
        // if we use that filename 'custom ' some tests will fail ( the tests that assert custom.dotath do not exists )
46
        // 
47
        // in order to make the test run smoothly i will change the filename
48
        $config->set('customSafe.dynamic.key', 'value', true);
49
        $config = ConfigFactory::make([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
50
            'directory' => __DIR__ . '/../examples',
51
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
52
        $this->assertSame('value', $config->get('customSafe.dynamic.key'));
53
54
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
55
56
    public function testEnvironment()
57
    {
58
        $config = ConfigFactory::make([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
59
            'directory' => __DIR__ . '/../examples',
60
            'environment' => 'dev',
61
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
62
63
        // it implements the configuration interfaces
64
        $this->assertInstanceOf(ConfigInterface::class, $config);
65
        $this->assertInstanceOf(ConfigCollection::class, $config);
66
67
        // it can fetch existing values
68
        $this->assertSame('Europe/Berlin', $config->get('app.timezone'));
69
70
        // it returns null for values that do not exist
71
        $this->assertNull($config->get('custom.key.option'));
72
73
        // it can set custom values
74
        $this->assertNull($config->set('custom.key.option', true));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $config->set('custom.key.option', true) targeting Northwoods\Config\ConfigDirectory::set() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure the usage of $config->set('custom.key.option', true) targeting Northwoods\Config\ConfigCollection::set() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
75
        $this->assertTrue($config->get('custom.key.option'));
76
77
        // new environments can be created
78
        $config = ConfigFactory::make([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
79
            'directory' => __DIR__ . '/../examples',
80
            'environment' => 'prod',
81
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
82
83
        // it can fetch existing values
84
        $this->assertSame('America/New_York', $config->get('app.timezone'));
85
86
        // it will merge base config + prod config
87
        $this->assertSame([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
88
            'default' => [
89
                'driver' => 'pdo_mysql',
90
                'host' => '127.0.0.1',
91
                'dbname' => 'my_database',
92
                'user' => 'my_user',
93
                'password' => 'production-password',
94
            ]
95
        ], $config->get('database.connections'));
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
96
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 1 found
Loading history...
97
98
    public function testYamlDirectory()
99
    {
100
        $config = ConfigFactory::make([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
101
            'directory' => __DIR__ . '/../examples',
102
            'environment' => 'dev',
103
            'type' => 'yaml',
104
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
105
106
        // it implements the configuration interfaces
107
        $this->assertInstanceOf(ConfigInterface::class, $config);
108
        $this->assertInstanceOf(ConfigCollection::class, $config);
109
110
        // it can fetch existing values
111
        $this->assertSame(['shadowhand'], $config->get('users.admins'));
112
        $this->assertSame(['ada'], $config->get('users.developers'));
113
114
        // it returns null for values that do not exist
115
        $this->assertNull($config->get('custom.key.option'));
116
117
        // it can set custom values
118
        $this->assertNull($config->set('custom.key.option', true));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $config->set('custom.key.option', true) targeting Northwoods\Config\ConfigDirectory::set() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
Bug introduced by
Are you sure the usage of $config->set('custom.key.option', true) targeting Northwoods\Config\ConfigCollection::set() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
119
        $this->assertTrue($config->get('custom.key.option'));
120
121
        // new environments can be created
122
        $config = ConfigFactory::make([
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
123
            'directory' => __DIR__ . '/../examples',
124
            'environment' => 'prod',
125
            'type' => 'yaml',
126
        ]);
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
127
128
        // it can fetch existing values
129
        $this->assertSame(['shadowhand'], $config->get('users.admins'));
130
131
        // it returns null for values that do not exist
132
        $this->assertNull($config->get('users.developers'));
133
    }
0 ignored issues
show
Coding Style introduced by
Expected 2 blank lines after function; 0 found
Loading history...
134
}
135