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\Ini; |
14
|
|
|
use PhpSpec\ObjectBehavior; |
15
|
|
|
use Slick\Configuration\Exception\FileNotFoundException; |
16
|
|
|
use Slick\Configuration\Exception\ParserErrorException; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Ini Specs |
20
|
|
|
* |
21
|
|
|
* @package spec\Slick\Configuration\Driver |
22
|
|
|
*/ |
23
|
|
|
class IniSpec extends ObjectBehavior |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
private $file; |
27
|
|
|
|
28
|
|
|
private $dummyFile; |
29
|
|
|
|
30
|
|
|
function let() |
31
|
|
|
{ |
32
|
|
|
$this->file = __DIR__ . '/fixtures/settings.ini'; |
33
|
|
|
$this->dummyFile = __DIR__ . '/fixtures/dummy.txt'; |
34
|
|
|
$this->beConstructedWith($this->file); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
function its_a_configuration_driver_for_ini_configuration_files() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$this->shouldBeAnInstanceOf(ConfigurationInterface::class); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
function it_is_initializable_with_a_path_to_a_settings_file() |
43
|
|
|
{ |
44
|
|
|
$this->shouldHaveType(Ini::class); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
function it_throws_an_exception_if_settings_file_cannot_be_found() |
48
|
|
|
{ |
49
|
|
|
$this->beConstructedWith('/_some/missing/file/path.php'); |
50
|
|
|
$this->shouldThrow(FileNotFoundException::class) |
51
|
|
|
->duringInstantiation(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
function it_throws_an_exception_if_file_cannot_be_parsed() |
55
|
|
|
{ |
56
|
|
|
$this->beConstructedWith($this->dummyFile); |
57
|
|
|
$this->shouldThrow(ParserErrorException::class) |
58
|
|
|
->duringInstantiation(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
function it_retrieves_a_configuration_value_stored_under_a_key() |
62
|
|
|
{ |
63
|
|
|
$this->get('foo')->shouldBe('bar'); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
function it_returns_a_default_value_if_a_given_key_is_not_found() |
67
|
|
|
{ |
68
|
|
|
$setting = $this->get('baz', true); |
69
|
|
|
$setting->shouldBeBoolean(); |
70
|
|
|
$setting->shouldBe(true); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
function it_retrieves_a_value_recursively_using_a_dot_notation() |
74
|
|
|
{ |
75
|
|
|
$this->get('first.second.third')->shouldBe(123); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
function it_sets_a_value_under_a_given_key() |
79
|
|
|
{ |
80
|
|
|
$this->set('other', 'value')->shouldBe($this->getWrappedObject()); |
|
|
|
|
81
|
|
|
$this->get('other')->shouldBe('value'); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
function it_sets_a_value_recursively_using_a_dot_notation() |
85
|
|
|
{ |
86
|
|
|
$this->set('value.under.deep', 'path')->shouldBe($this->getWrappedObject()); |
87
|
|
|
$this->get('value.under.deep')->shouldBe('path'); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.