1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Gerrie package. |
4
|
|
|
* |
5
|
|
|
* (c) Andreas Grunwald <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace Gerrie\Tests\Component\Configuration; |
12
|
|
|
|
13
|
|
|
use Gerrie\Component\Configuration\Configuration; |
14
|
|
|
|
15
|
|
|
class ConfigurationTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var Configuration |
20
|
|
|
*/ |
21
|
|
|
private $configuration; |
22
|
|
|
|
23
|
|
|
public function setUp() |
24
|
|
|
{ |
25
|
|
|
$this->configuration = new Configuration(); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function tearDown() |
29
|
|
|
{ |
30
|
|
|
$this->configuration = null; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
protected function getDummyConfig() |
34
|
|
|
{ |
35
|
|
|
$dummyConfig = [ |
36
|
|
|
'Foo' => 'Bar', |
37
|
|
|
'Bar' => [ |
38
|
|
|
'Bar' => 'Baz', |
39
|
|
|
'Baz' => 'Gerrie', |
40
|
|
|
'Gerrie' => [ |
41
|
|
|
'Nested' => true |
42
|
|
|
] |
43
|
|
|
] |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
return $dummyConfig; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testGetterConfigurationWithConstructor() |
50
|
|
|
{ |
51
|
|
|
$dummyConfig = $this->getDummyConfig(); |
52
|
|
|
$configuration = new Configuration($dummyConfig); |
53
|
|
|
|
54
|
|
|
$this->assertEquals('Bar', $configuration->getConfigurationValue('Foo')); |
55
|
|
|
$this->assertEquals($dummyConfig['Bar'], $configuration->getConfigurationValue('Bar')); |
56
|
|
|
|
57
|
|
|
$this->assertEquals('Baz', $configuration->getConfigurationValue('Bar.Bar')); |
58
|
|
|
$this->assertEquals('Gerrie', $configuration->getConfigurationValue('Bar.Baz')); |
59
|
|
|
$this->assertEquals('Gerrie', $configuration->getConfigurationValue('bar.baz')); |
60
|
|
|
$this->assertEquals('Gerrie', $configuration->getConfigurationValue('bar.Baz')); |
61
|
|
|
$this->assertEquals('Gerrie', $configuration->getConfigurationValue('Bar.baz')); |
62
|
|
|
|
63
|
|
|
$this->assertEquals($dummyConfig['Bar']['Gerrie'], $configuration->getConfigurationValue('Bar.Gerrie')); |
64
|
|
|
$this->assertEquals(true, $configuration->getConfigurationValue('Bar.Gerrie.Nested')); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testGetterConfigurationWithSetConfiguration() |
68
|
|
|
{ |
69
|
|
|
$dummyConfig = $this->getDummyConfig(); |
70
|
|
|
$this->configuration->setConfiguration($dummyConfig); |
71
|
|
|
|
72
|
|
|
$this->assertEquals('Bar', $this->configuration->getConfigurationValue('Foo')); |
73
|
|
|
$this->assertEquals($dummyConfig['Bar'], $this->configuration->getConfigurationValue('Bar')); |
74
|
|
|
|
75
|
|
|
$this->assertEquals('Baz', $this->configuration->getConfigurationValue('Bar.Bar')); |
76
|
|
|
$this->assertEquals('Gerrie', $this->configuration->getConfigurationValue('Bar.Baz')); |
77
|
|
|
$this->assertEquals('Gerrie', $this->configuration->getConfigurationValue('bar.baz')); |
78
|
|
|
$this->assertEquals('Gerrie', $this->configuration->getConfigurationValue('bar.Baz')); |
79
|
|
|
$this->assertEquals('Gerrie', $this->configuration->getConfigurationValue('Bar.baz')); |
80
|
|
|
|
81
|
|
|
$this->assertEquals($dummyConfig['Bar']['Gerrie'], $this->configuration->getConfigurationValue('Bar.Gerrie')); |
82
|
|
|
$this->assertEquals(true, $this->configuration->getConfigurationValue('Bar.Gerrie.Nested')); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testGetConfigurationWithConstructor() |
86
|
|
|
{ |
87
|
|
|
$dummyConfig = $this->getDummyConfig(); |
88
|
|
|
$this->configuration->setConfiguration($dummyConfig); |
89
|
|
|
|
90
|
|
|
$this->assertEquals($dummyConfig, $this->configuration->getConfiguration()); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function testGetConfigurationWithSetter() |
94
|
|
|
{ |
95
|
|
|
$dummyConfig = $this->getDummyConfig(); |
96
|
|
|
$configuration = new Configuration($dummyConfig); |
97
|
|
|
|
98
|
|
|
$this->assertEquals($dummyConfig, $configuration->getConfiguration()); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testSetConfigurationValueWithEmptyConfiguration() |
102
|
|
|
{ |
103
|
|
|
$this->assertEquals('', $this->configuration->getConfigurationValue('Foo')); |
104
|
|
|
$this->assertEquals('', $this->configuration->getConfigurationValue('Foo.Bar.Baz')); |
105
|
|
|
$this->assertEquals('', $this->configuration->getConfigurationValue('Foo.Gerrie')); |
106
|
|
|
$this->assertEquals('', $this->configuration->getConfigurationValue('Awesome.Application.YOLO')); |
107
|
|
|
|
108
|
|
|
$this->configuration->setConfigurationValue('Foo', 'Bar'); |
109
|
|
|
$this->assertEquals('Bar', $this->configuration->getConfigurationValue('Foo')); |
110
|
|
|
|
111
|
|
|
$this->configuration->setConfigurationValue('Foo', 'Weekend'); |
112
|
|
|
$this->assertEquals('Weekend', $this->configuration->getConfigurationValue('Foo')); |
113
|
|
|
|
114
|
|
|
$this->configuration->setConfigurationValue('Foo.Bar', 'Baz'); |
115
|
|
|
$this->configuration->setConfigurationValue('Foo.Bar.Baz', 'Hello'); |
116
|
|
|
$this->configuration->setConfigurationValue('Foo.Gerrie', 'World'); |
117
|
|
|
$this->configuration->setConfigurationValue('Awesome.Application.YOLO', 'Google Google Google'); |
118
|
|
|
|
119
|
|
|
$this->assertEquals(['Baz' => 'Hello'], $this->configuration->getConfigurationValue('Foo.Bar')); |
120
|
|
|
$this->assertEquals('Hello', $this->configuration->getConfigurationValue('Foo.Bar.Baz')); |
121
|
|
|
$this->assertEquals('World', $this->configuration->getConfigurationValue('Foo.Gerrie')); |
122
|
|
|
$this->assertEquals('Google Google Google', $this->configuration->getConfigurationValue('Awesome.Application.YOLO')); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function testHasConfigurationKey() |
126
|
|
|
{ |
127
|
|
|
$dummyConfig = $this->getDummyConfig(); |
128
|
|
|
$configuration = new Configuration($dummyConfig); |
129
|
|
|
|
130
|
|
|
$this->assertTrue($configuration->hasConfigurationKey('Foo')); |
131
|
|
|
$this->assertTrue($configuration->hasConfigurationKey('Bar.Gerrie.Nested')); |
132
|
|
|
$this->assertTrue($configuration->hasConfigurationKey('Bar.Gerrie')); |
133
|
|
|
$this->assertTrue($configuration->hasConfigurationKey('Bar.Bar')); |
134
|
|
|
|
135
|
|
|
$this->assertFalse($configuration->hasConfigurationKey('Baz.Foo')); |
136
|
|
|
$this->assertFalse($configuration->hasConfigurationKey('Gerrie')); |
137
|
|
|
} |
138
|
|
|
} |