PhpSpec::let()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of 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\Driver;
11
12
use Slick\Configuration\ConfigurationInterface;
13
use Slick\Configuration\Driver\Php;
14
use PhpSpec\ObjectBehavior;
15
use Slick\Configuration\Exception\FileNotFoundException;
16
use Slick\Configuration\Exception\ParserErrorException;
17
18
/**
19
 * Php Specs
20
 *
21
 * @package spec\Slick\Configuration\Driver
22
 */
23
class PhpSpec extends ObjectBehavior
24
{
25
    private $file;
26
27
    private $dummyFile;
28
29
    function let()
30
    {
31
        $this->file = __DIR__ . '/fixtures/settings.php';
32
        $this->dummyFile = __DIR__ . '/fixtures/dummy.txt';
33
        $this->beConstructedWith($this->file);
34
    }
35
36
    function its_a_configuration_driver_for_php_arrays()
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...
37
    {
38
        $this->shouldBeAnInstanceOf(ConfigurationInterface::class);
39
    }
40
41
    function it_is_initializable_with_a_path_to_a_settings_file()
42
    {
43
        $this->shouldHaveType(Php::class);
44
    }
45
46
    function it_throws_an_exception_if_settings_file_cannot_be_found()
47
    {
48
        $this->beConstructedWith('/_some/missing/file/path.php');
49
        $this->shouldThrow(FileNotFoundException::class)
50
            ->duringInstantiation();
51
    }
52
53
    function it_throws_an_exception_if_file_cannot_be_parsed()
54
    {
55
        $this->beConstructedWith($this->dummyFile);
56
        $this->shouldThrow(ParserErrorException::class)
57
            ->duringInstantiation();
58
    }
59
60
    function it_retrieves_a_configuration_value_stored_under_a_key()
61
    {
62
        $this->get('foo')->shouldBe('bar');
0 ignored issues
show
Bug introduced by
The method get() does not exist on spec\Slick\Configuration\Driver\PhpSpec. 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

62
        $this->/** @scrutinizer ignore-call */ 
63
               get('foo')->shouldBe('bar');
Loading history...
63
    }
64
65
    function it_returns_a_default_value_if_a_given_key_is_not_found()
66
    {
67
        $setting = $this->get('baz', true);
68
        $setting->shouldBeBoolean();
69
        $setting->shouldBe(true);
70
    }
71
72
    function it_retrieves_a_value_recursively_using_a_dot_notation()
73
    {
74
        $this->get('first.second.third')->shouldBe(123);
75
    }
76
77
    function it_sets_a_value_under_a_given_key()
78
    {
79
        $this->set('other', 'value')->shouldBe($this->getWrappedObject());
0 ignored issues
show
Bug introduced by
The method set() does not exist on spec\Slick\Configuration\Driver\PhpSpec. 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

79
        $this->/** @scrutinizer ignore-call */ 
80
               set('other', 'value')->shouldBe($this->getWrappedObject());
Loading history...
80
        $this->get('other')->shouldBe('value');
81
    }
82
83
    function it_sets_a_value_recursively_using_a_dot_notation()
84
    {
85
        $this->set('value.under.deep', 'path')->shouldBe($this->getWrappedObject());
86
        $this->get('value.under.deep')->shouldBe('path');
87
    }
88
}
89