its_a_configuration_chain()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of slick/configuration
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace spec\Slick\Configuration;
11
12
use Slick\Configuration\Common\PriorityList;
13
use Slick\Configuration\Configuration;
14
use Slick\Configuration\ConfigurationChainInterface;
15
use Slick\Configuration\ConfigurationInterface;
16
use Slick\Configuration\Driver\Environment;
17
use Slick\Configuration\Driver\Php;
18
use Slick\Configuration\PriorityConfigurationChain;
19
use PhpSpec\ObjectBehavior;
20
21
/**
22
 * PriorityConfigurationChainSpec specs
23
 *
24
 * @package spec\Slick\Configuration
25
 */
26
class PriorityConfigurationChainSpec extends ObjectBehavior
27
{
28
29
    function its_a_configuration_chain()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
30
    {
31
        $this->shouldBeAnInstanceOf(ConfigurationChainInterface::class);
32
    }
33
34
    function it_is_initializable_with_an_empty_chain()
35
    {
36
        $this->shouldHaveType(PriorityConfigurationChain::class);
37
    }
38
39
    function it_adds_configuration_drivers(ConfigurationInterface $driverA)
40
    {
41
        $this->add($driverA)->shouldBe($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method add() does not exist on spec\Slick\Configuration...yConfigurationChainSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
        $this->/** @scrutinizer ignore-call */ 
42
               add($driverA)->shouldBe($this->getWrappedObject());
Loading history...
42
    }
43
44
    function it_accepts_priority_when_adding_a_driver(
45
        ConfigurationInterface $driverA,
46
        ConfigurationInterface $driverB
47
    )
48
    {
49
        $this->add($driverA ,100);
50
        $this->add($driverB, 10);
51
        $this->priorityList()->shouldBeAnInstanceOf(PriorityList::class);
0 ignored issues
show
Bug introduced by
The method priorityList() does not exist on spec\Slick\Configuration...yConfigurationChainSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        $this->/** @scrutinizer ignore-call */ 
52
               priorityList()->shouldBeAnInstanceOf(PriorityList::class);
Loading history...
52
        $this->priorityList()->asArray()[0]->shouldBe($driverB);
53
    }
54
55
    function it_retrieves_a_configuration_value_stored_under_a_key(
56
        ConfigurationInterface $driverA,
57
        ConfigurationInterface $driverB
58
    ) {
59
        $this->add($driverA, 100);
60
        $this->add($driverB, 10);
61
62
        $driverA->asArray()->willReturn(['foo' => 'fooA']);
63
        $driverB->asArray()->willReturn([]);
64
65
        $this->get('foo')->shouldBe('fooA');
0 ignored issues
show
Bug introduced by
The method get() does not exist on spec\Slick\Configuration...yConfigurationChainSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
        $this->/** @scrutinizer ignore-call */ 
66
               get('foo')->shouldBe('fooA');
Loading history...
66
        $driverA->asArray()->shouldHaveBeenCalled();
67
        $driverB->asArray()->shouldHaveBeenCalled();
68
    }
69
70
    function it_retrieves_a_configuration_value_respecting_chain_priority(
71
        ConfigurationInterface $driverA,
72
        ConfigurationInterface $driverB
73
    )
74
    {
75
        $this->add($driverA ,100);
76
        $this->add($driverB, 10);
77
78
        $driverA->asArray()->willReturn(['bar' => 'fooA']);
79
        $driverB->asArray()->willReturn(['bar' => 'fooB']);
80
81
        $this->get('bar')->shouldBe('fooB');
82
        $driverA->asArray()->shouldHaveBeenCalled();
83
        $driverB->asArray()->shouldHaveBeenCalled();
84
    }
85
86
    function it_returns_a_default_value_if_a_given_key_is_not_found()
87
    {
88
        $setting = $this->get('baz', true);
89
        $setting->shouldBeBoolean();
90
        $setting->shouldBe(true);
91
    }
92
93
    function it_retrieves_a_value_recursively_using_a_dot_notation(
94
        ConfigurationInterface $driverA
95
    )
96
    {
97
        $driverA->asArray()->willReturn([
98
            'first' => [
99
                'second' => ['third' => 123]
100
            ]
101
        ]);
102
        $this->add($driverA);
103
        $this->get('first.second.third')->shouldBe(123);
104
    }
105
106
    function it_sets_a_value_under_a_given_key()
107
    {
108
        $this->set('other', 'value')->shouldBe($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method set() does not exist on spec\Slick\Configuration...yConfigurationChainSpec. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

108
        $this->/** @scrutinizer ignore-call */ 
109
               set('other', 'value')->shouldBe($this->getWrappedObject());
Loading history...
109
        $this->get('other')->shouldBe('value');
110
    }
111
112
    function it_sets_a_value_recursively_using_a_dot_notation()
113
    {
114
        $this->set('value.under.deep', 'path')->shouldBe($this->getWrappedObject());
115
        $this->get('value.under.deep')->shouldBe('path');
116
    }
117
118
    function it_should_merge_all_settings_with_prioriry()
119
    {
120
        $this->add(new Environment(), 10)->add(new Php(__DIR__.'/settings.php'), 20);
121
        $this->get('testenv')->shouldBe([
122
            'enabled' => true,
123
            'mode' => "develop,debug,coverage",
124
        ]);
125
    }
126
}
127