1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This file is part of phpDocumentor. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @link http://phpdoc.org |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace phpDocumentor\Configuration; |
15
|
|
|
|
16
|
|
|
use Mockery\Adapter\Phpunit\MockeryTestCase; |
17
|
|
|
use phpDocumentor\Configuration\Factory\Version3; |
18
|
|
|
use phpDocumentor\Dsn; |
19
|
|
|
use phpDocumentor\Path; |
20
|
|
|
use function current; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @coversDefaultClass \phpDocumentor\Configuration\CommandlineOptionsMiddleware |
24
|
|
|
* @covers ::__construct |
25
|
|
|
* @covers ::<private> |
26
|
|
|
*/ |
27
|
|
|
final class CommandlineOptionsMiddlewareTest extends MockeryTestCase |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @covers ::__invoke |
31
|
|
|
*/ |
32
|
|
|
public function testItShouldOverwriteTheDestinationFolderBasedOnTheTargetOption() : void |
33
|
|
|
{ |
34
|
|
|
$expected = '/abc'; |
35
|
|
|
$configuration = ['phpdocumentor' => ['paths' => ['output' => '/tmp']]]; |
36
|
|
|
|
37
|
|
|
$middleware = new CommandlineOptionsMiddleware(['target' => $expected]); |
38
|
|
|
$newConfiguration = $middleware($configuration); |
39
|
|
|
|
40
|
|
|
$this->assertEquals(new Dsn($expected), $newConfiguration['phpdocumentor']['paths']['output']); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @covers ::__invoke |
45
|
|
|
*/ |
46
|
|
|
public function testItShouldDisableTheCacheBasedOnTheForceOption() : void |
47
|
|
|
{ |
48
|
|
|
$configuration = ['phpdocumentor' => ['use-cache' => true]]; |
49
|
|
|
|
50
|
|
|
$middleware = new CommandlineOptionsMiddleware(['force' => true]); |
51
|
|
|
$newConfiguration = $middleware($configuration); |
52
|
|
|
|
53
|
|
|
$this->assertFalse($newConfiguration['phpdocumentor']['use-cache']); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @covers ::__invoke |
58
|
|
|
*/ |
59
|
|
|
public function testItShouldOverwriteTheCacheFolderBasedOnTheCacheFolderOption() : void |
60
|
|
|
{ |
61
|
|
|
$expected = '/abc'; |
62
|
|
|
$configuration = ['phpdocumentor' => ['paths' => ['cache' => '/tmp']]]; |
63
|
|
|
|
64
|
|
|
$middleware = new CommandlineOptionsMiddleware(['cache-folder' => $expected]); |
65
|
|
|
$newConfiguration = $middleware->__invoke($configuration); |
66
|
|
|
|
67
|
|
|
$this->assertEquals(new Path($expected), $newConfiguration['phpdocumentor']['paths']['cache']); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @covers ::__invoke |
72
|
|
|
*/ |
73
|
|
|
public function testItShouldOverrideTheTitleBasedOnTheTitleOption() : void |
74
|
|
|
{ |
75
|
|
|
$expected = 'phpDocumentor3'; |
76
|
|
|
$configuration = ['phpdocumentor' => ['title' => 'phpDocumentor2']]; |
77
|
|
|
|
78
|
|
|
$middleware = new CommandlineOptionsMiddleware(['title' => $expected]); |
79
|
|
|
$newConfiguration = $middleware($configuration); |
80
|
|
|
|
81
|
|
|
$this->assertSame($expected, $newConfiguration['phpdocumentor']['title']); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @covers ::__invoke |
86
|
|
|
*/ |
87
|
|
|
public function testItShouldOverrideTheListOfTemplatesBasedOnTheTemplateOption() : void |
88
|
|
|
{ |
89
|
|
|
$expected = 'clean'; |
90
|
|
|
$configuration = ['phpdocumentor' => ['templates' => [['name' => 'responsive']]]]; |
91
|
|
|
|
92
|
|
|
$middleware = new CommandlineOptionsMiddleware(['template' => $expected]); |
93
|
|
|
$newConfiguration = $middleware($configuration); |
94
|
|
|
|
95
|
|
|
$this->assertSame([['name' => $expected]], $newConfiguration['phpdocumentor']['templates']); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @covers ::__invoke |
100
|
|
|
*/ |
101
|
|
|
public function testItShouldAddSourceFilesForDefaultConfiguration() : void |
102
|
|
|
{ |
103
|
|
|
$configuration = $this->givenAConfigurationWithoutApiDefinition(); |
104
|
|
|
|
105
|
|
|
$middleware = new CommandlineOptionsMiddleware(['filename' => ['./src/index.php']]); |
106
|
|
|
$newConfiguration = $middleware($configuration); |
107
|
|
|
|
108
|
|
|
$this->assertEquals( |
109
|
|
|
[ |
110
|
|
|
'dsn' => new Dsn('file://.'), |
111
|
|
|
'paths' => [new Path('./src/index.php')], |
112
|
|
|
], |
113
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['source'] |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @covers ::__invoke |
119
|
|
|
*/ |
120
|
|
|
public function testItShouldAddSourceDirectoriesForDefaultConfiguration() : void |
121
|
|
|
{ |
122
|
|
|
$configuration = $this->givenAConfigurationWithoutApiDefinition(); |
123
|
|
|
|
124
|
|
|
$middleware = new CommandlineOptionsMiddleware(['directory' => ['./src']]); |
125
|
|
|
$newConfiguration = $middleware($configuration); |
126
|
|
|
|
127
|
|
|
$this->assertEquals( |
128
|
|
|
[ |
129
|
|
|
'dsn' => new Dsn('file://.'), |
130
|
|
|
'paths' => [new Path('./src')], |
131
|
|
|
], |
132
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['source'] |
133
|
|
|
); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* @covers ::__invoke |
138
|
|
|
*/ |
139
|
|
|
public function testItShouldKeepSourceDirectoriesWhenNoneWereProvideOnCommandLine() : void |
140
|
|
|
{ |
141
|
|
|
$configuration = $this->givenAConfiguration(); |
142
|
|
|
|
143
|
|
|
$middleware = new CommandlineOptionsMiddleware(['directory' => []]); |
144
|
|
|
$newConfiguration = $middleware($configuration); |
145
|
|
|
|
146
|
|
|
$this->assertEquals( |
147
|
|
|
[ |
148
|
|
|
'dsn' => new Dsn('file://.'), |
149
|
|
|
'paths' => [new Path('src')], |
150
|
|
|
], |
151
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['source'] |
152
|
|
|
); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
public function testItShouldAddAbsoluteSourcePathsToNewApi() : void |
156
|
|
|
{ |
157
|
|
|
$configuration = Version3::buildDefault(); |
158
|
|
|
$middleware = new CommandlineOptionsMiddleware(['directory' => ['/src']]); |
159
|
|
|
$newConfiguration = $middleware($configuration); |
160
|
|
|
|
161
|
|
|
$this->assertEquals( |
162
|
|
|
[ |
163
|
|
|
'dsn' => new Dsn('file:///src'), |
164
|
|
|
'paths' => [new Path('./')], |
165
|
|
|
], |
166
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['source'] |
167
|
|
|
); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
public function testItShouldAddAbsoluteSourcePathsToNewApiAndRelativeToCurrent() : void |
171
|
|
|
{ |
172
|
|
|
$configuration = Version3::buildDefault(); |
173
|
|
|
$middleware = new CommandlineOptionsMiddleware(['directory' => ['/src', './localSrc']]); |
174
|
|
|
$newConfiguration = $middleware($configuration); |
175
|
|
|
|
176
|
|
|
$this->assertEquals( |
177
|
|
|
[ |
178
|
|
|
'dsn' => new Dsn('file:///src'), |
179
|
|
|
'paths' => [new Path('./')], |
180
|
|
|
], |
181
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['source'] |
182
|
|
|
); |
183
|
|
|
$this->assertEquals( |
184
|
|
|
[ |
185
|
|
|
'dsn' => new Dsn('file://.'), |
186
|
|
|
'paths' => [new Path('./localSrc')], |
187
|
|
|
], |
188
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][1]['source'] |
189
|
|
|
); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @covers ::__invoke |
195
|
|
|
*/ |
196
|
|
|
public function testItShouldRegisterExtensionsForDefaultConfiguration() : void |
197
|
|
|
{ |
198
|
|
|
$configuration = $this->givenAConfigurationWithoutApiDefinition(); |
199
|
|
|
|
200
|
|
|
$extensions = ['php7', 'php5']; |
201
|
|
|
$middleware = new CommandlineOptionsMiddleware(['extensions' => $extensions]); |
202
|
|
|
$newConfiguration = $middleware($configuration); |
203
|
|
|
|
204
|
|
|
$this->assertEquals( |
205
|
|
|
$extensions, |
206
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['extensions'] |
207
|
|
|
); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @covers ::__invoke |
212
|
|
|
*/ |
213
|
|
|
public function testItShouldReplaceIgnoredDirectoriesForDefaultConfiguration() : void |
214
|
|
|
{ |
215
|
|
|
$configuration = $this->givenAConfigurationWithoutApiDefinition(); |
216
|
|
|
|
217
|
|
|
$middleware = new CommandlineOptionsMiddleware(['ignore' => ['./src']]); |
218
|
|
|
$newConfiguration = $middleware($configuration); |
219
|
|
|
|
220
|
|
|
$this->assertEquals( |
221
|
|
|
[ |
222
|
|
|
'paths' => [new Path('./src')], |
223
|
|
|
'hidden' => true, |
224
|
|
|
], |
225
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['ignore'] |
226
|
|
|
); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @covers ::__invoke |
231
|
|
|
*/ |
232
|
|
|
public function testItShouldOverwriteTheMarkersOfTheDefaultConfiguration() : void |
233
|
|
|
{ |
234
|
|
|
$configuration = $this->givenAConfigurationWithoutApiDefinition(); |
235
|
|
|
|
236
|
|
|
$markers = ['FIXME2', 'TODOSOMETIME']; |
237
|
|
|
$middleware = new CommandlineOptionsMiddleware(['markers' => $markers]); |
238
|
|
|
$newConfiguration = $middleware($configuration); |
239
|
|
|
|
240
|
|
|
$this->assertEquals( |
241
|
|
|
$markers, |
242
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['markers'] |
243
|
|
|
); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @covers ::__invoke |
248
|
|
|
*/ |
249
|
|
|
public function testItShouldOverwriteTheVisibilitySetInTheDefaultConfiguration() : void |
250
|
|
|
{ |
251
|
|
|
$configuration = $this->givenAConfigurationWithoutApiDefinition(); |
252
|
|
|
|
253
|
|
|
$visibility = ['public']; |
254
|
|
|
$middleware = new CommandlineOptionsMiddleware(['visibility' => $visibility]); |
255
|
|
|
$newConfiguration = $middleware($configuration); |
256
|
|
|
|
257
|
|
|
$this->assertEquals( |
258
|
|
|
$visibility, |
259
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['visibility'] |
260
|
|
|
); |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @covers ::__invoke |
265
|
|
|
*/ |
266
|
|
|
public function testItShouldOverwriteTheDefaultPackageNameSetInTheDefaultConfiguration() : void |
267
|
|
|
{ |
268
|
|
|
$configuration = $this->givenAConfigurationWithoutApiDefinition(); |
269
|
|
|
|
270
|
|
|
$defaultPackageName = ['public']; |
271
|
|
|
$middleware = new CommandlineOptionsMiddleware(['defaultpackagename' => $defaultPackageName]); |
272
|
|
|
$newConfiguration = $middleware($configuration); |
273
|
|
|
|
274
|
|
|
$this->assertEquals( |
275
|
|
|
$defaultPackageName, |
276
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['default-package-name'] |
277
|
|
|
); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* @covers ::__invoke |
282
|
|
|
*/ |
283
|
|
|
public function testItShouldOverwriteTheWhetherToIncludeSourcecodeInTheDefaultConfiguration() : void |
284
|
|
|
{ |
285
|
|
|
$configuration = $this->givenAConfigurationWithoutApiDefinition(); |
286
|
|
|
|
287
|
|
|
$middleware = new CommandlineOptionsMiddleware(['sourcecode' => true]); |
288
|
|
|
$newConfiguration = $middleware($configuration); |
289
|
|
|
|
290
|
|
|
$this->assertEquals( |
291
|
|
|
true, |
292
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['include-source'] |
293
|
|
|
); |
294
|
|
|
|
295
|
|
|
$middleware = new CommandlineOptionsMiddleware(['sourcecode' => false]); |
296
|
|
|
$newConfiguration = $middleware($configuration); |
297
|
|
|
|
298
|
|
|
$this->assertEquals( |
299
|
|
|
false, |
300
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['include-source'] |
301
|
|
|
); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
private function givenAConfigurationWithoutApiDefinition() : array |
305
|
|
|
{ |
306
|
|
|
$configuration = Version3::buildDefault(); |
307
|
|
|
|
308
|
|
|
// wipe version so that middleware needs to re-add the api key |
309
|
|
|
unset($configuration['phpdocumentor']['versions']); |
310
|
|
|
$configuration['phpdocumentor']['versions'] = ['1.0.0' => []]; |
311
|
|
|
|
312
|
|
|
return $configuration; |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
private function givenAConfiguration() : array |
316
|
|
|
{ |
317
|
|
|
return Version3::buildDefault(); |
318
|
|
|
} |
319
|
|
|
} |
320
|
|
|
|