1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace BaleenTest\Cli\Config; |
21
|
|
|
|
22
|
|
|
use Baleen\Cli\Config\Config; |
23
|
|
|
use Baleen\Cli\Provider\ApplicationProvider; |
24
|
|
|
use Baleen\Cli\Provider\CommandsProvider; |
25
|
|
|
use Baleen\Cli\Provider\HelperSetProvider; |
26
|
|
|
use Baleen\Cli\Provider\RepositoryProvider; |
27
|
|
|
use Baleen\Cli\Provider\StorageProvider; |
28
|
|
|
use Baleen\Cli\Provider\TimelineProvider; |
29
|
|
|
use BaleenTest\Cli\BaseTestCase; |
30
|
|
|
use Mockery as m; |
31
|
|
|
use Symfony\Component\Config\Definition\Exception\InvalidConfigurationException; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Class ConfigTest |
35
|
|
|
* @author Gabriel Somoza <[email protected]> |
36
|
|
|
*/ |
37
|
|
|
class ConfigTest extends BaseTestCase |
38
|
|
|
{ |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* testDefaults |
42
|
|
|
*/ |
43
|
|
|
public function testDefaults() |
44
|
|
|
{ |
45
|
|
|
$conf = new Config(); |
46
|
|
|
$expected = [ |
47
|
|
|
'providers' => [ |
48
|
|
|
'application' => ApplicationProvider::class, |
49
|
|
|
'storage' => StorageProvider::class, |
50
|
|
|
'repository' => RepositoryProvider::class, |
51
|
|
|
'timeline' => TimelineProvider::class, |
52
|
|
|
'helperSet' => HelperSetProvider::class, |
53
|
|
|
'commands' => CommandsProvider::class, |
54
|
|
|
], |
55
|
|
|
'migrations' => [ |
56
|
|
|
'directory' => 'migrations', |
57
|
|
|
'namespace' => 'Migrations', |
58
|
|
|
], |
59
|
|
|
'storage' => [ |
60
|
|
|
'file' => Config::VERSIONS_FILE_NAME |
61
|
|
|
], |
62
|
|
|
'plugins' => [], |
63
|
|
|
]; |
64
|
|
|
$this->assertEquals($expected, $conf->getDefaults()); |
65
|
|
|
$this->assertEquals($expected, $conf->toArray()); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* testConstruct |
70
|
|
|
* @dataProvider constructProvider |
71
|
|
|
*/ |
72
|
|
|
public function testConstruct($config, $useDefaults, $expected) |
73
|
|
|
{ |
74
|
|
|
if ($expected === 'ERROR') { |
75
|
|
|
$this->setExpectedException(InvalidConfigurationException::class); |
76
|
|
|
} |
77
|
|
|
$instance = new Config($config, $useDefaults); |
78
|
|
|
$this->assertEquals($expected, $instance->toArray()); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* constructProvider |
83
|
|
|
*/ |
84
|
|
|
public function constructProvider() |
85
|
|
|
{ |
86
|
|
|
$defaultConfig = [ |
87
|
|
|
'providers' => [ |
88
|
|
|
'application' => 'Baleen\Cli\Provider\ApplicationProvider', |
89
|
|
|
'storage' => 'Baleen\Cli\Provider\StorageProvider', |
90
|
|
|
'repository' => 'Baleen\Cli\Provider\RepositoryProvider', |
91
|
|
|
'timeline' => 'Baleen\Cli\Provider\TimelineProvider', |
92
|
|
|
'helperSet' => 'Baleen\Cli\Provider\HelperSetProvider', |
93
|
|
|
'commands' => 'Baleen\Cli\Provider\CommandsProvider', |
94
|
|
|
], |
95
|
|
|
'migrations' => [ |
96
|
|
|
'directory' => 'migrations', |
97
|
|
|
'namespace' => 'Migrations', |
98
|
|
|
], |
99
|
|
|
'storage' => [ |
100
|
|
|
'file' => '.baleen_versions', |
101
|
|
|
], |
102
|
|
|
'plugins' => [], |
103
|
|
|
]; |
104
|
|
|
$resultSet0 = $defaultConfig; |
105
|
|
|
$resultSet0['migrations']['directory'] = 'custom-directory'; |
106
|
|
|
return [ |
107
|
|
|
[ |
108
|
|
|
[], |
109
|
|
|
true, |
110
|
|
|
$defaultConfig, |
111
|
|
|
], |
112
|
|
|
[ |
113
|
|
|
['migrations' => ['directory' => 'custom-directory',],], |
114
|
|
|
true, |
115
|
|
|
$resultSet0, |
116
|
|
|
], |
117
|
|
|
[ |
118
|
|
|
[], |
119
|
|
|
false, |
120
|
|
|
'ERROR' |
121
|
|
|
] |
122
|
|
|
]; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* testGetMigrationsDirectoryPath |
127
|
|
|
*/ |
128
|
|
|
public function testGetMigrationsDirectoryPath() |
129
|
|
|
{ |
130
|
|
|
$customDirectory = 'some-directory'; |
131
|
|
|
$config = ['migrations' => ['directory' => $customDirectory]]; |
132
|
|
|
$instance = new Config($config); |
133
|
|
|
$this->assertContains(DIRECTORY_SEPARATOR . $customDirectory, $instance->getMigrationsDirectoryPath()); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* testGetMigrationsNamespace |
138
|
|
|
*/ |
139
|
|
|
public function testGetMigrationsNamespace() |
140
|
|
|
{ |
141
|
|
|
$customNamespace = 'some-namespace'; |
142
|
|
|
$config = ['migrations' => ['namespace' => $customNamespace]]; |
143
|
|
|
$instance = new Config($config); |
144
|
|
|
$this->assertEquals($customNamespace, $instance->getMigrationsNamespace()); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* testGetStorageFilePath |
149
|
|
|
*/ |
150
|
|
|
public function testGetStorageFilePath() |
151
|
|
|
{ |
152
|
|
|
$customStorageFile = 'some-file.txt'; |
153
|
|
|
$config = ['storage' => ['file' => $customStorageFile]]; |
154
|
|
|
$instance = new Config(); |
155
|
|
|
$this->setPropVal('config', $config, $instance); |
156
|
|
|
$this->assertContains(DIRECTORY_SEPARATOR . $customStorageFile, $instance->getStorageFilePath()); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* testGetConfigFilePath |
161
|
|
|
*/ |
162
|
|
|
public function testGetConfigFilePath() |
163
|
|
|
{ |
164
|
|
|
$configFileName = Config::CONFIG_FILE_NAME; |
165
|
|
|
$instance = new Config(); |
166
|
|
|
$this->assertContains($configFileName, $instance->getConfigFilePath()); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* testGetProviders |
171
|
|
|
*/ |
172
|
|
|
public function testGetProviders() |
173
|
|
|
{ |
174
|
|
|
$customProviders = ['foo' => 'bar']; |
175
|
|
|
$config = ['providers' => $customProviders]; |
176
|
|
|
$instance = new Config(); |
177
|
|
|
$this->setPropVal('config', $config, $instance); |
178
|
|
|
$this->assertEquals($customProviders, $instance->getProviders()); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* testGetCleanArray |
183
|
|
|
*/ |
184
|
|
|
public function testGetCleanArray() |
185
|
|
|
{ |
186
|
|
|
$config = ['providers' => ['should_be' => 'removed'], 'should' => 'remain']; |
187
|
|
|
$instance = new Config(); |
188
|
|
|
$this->setPropVal('config', $config, $instance); |
189
|
|
|
$this->assertArrayNotHasKey('providers', $instance->getCleanArray()); |
190
|
|
|
} |
191
|
|
|
} |
192
|
|
|
|