1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of phpDocumentor. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright 2010-2016 Mike van Riel<[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace phpDocumentor\Configuration; |
14
|
|
|
|
15
|
|
|
use Mockery\Adapter\Phpunit\MockeryTestCase; |
16
|
|
|
use phpDocumentor\Configuration\Factory\Version3; |
17
|
|
|
use phpDocumentor\DomainModel\Dsn; |
18
|
|
|
use phpDocumentor\DomainModel\Path; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @coversDefaultClass \phpDocumentor\Configuration\CommandlineOptionsMiddleware |
22
|
|
|
* @covers ::__construct |
23
|
|
|
* @covers ::<private> |
24
|
|
|
*/ |
25
|
|
|
final class CommandlineOptionsMiddlewareTest extends MockeryTestCase |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @covers ::__invoke |
29
|
|
|
*/ |
30
|
|
|
public function testItShouldOverwriteTheDestinationFolderBasedOnTheTargetOption() |
31
|
|
|
{ |
32
|
|
|
$expected = '/abc'; |
33
|
|
|
$configuration = ['phpdocumentor' => ['paths' => ['output' => '/tmp']]]; |
34
|
|
|
|
35
|
|
|
$middleware = new CommandlineOptionsMiddleware(['target' => $expected]); |
36
|
|
|
$newConfiguration = $middleware($configuration); |
37
|
|
|
|
38
|
|
|
$this->assertEquals(new Dsn($expected), $newConfiguration['phpdocumentor']['paths']['output']); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @covers ::__invoke |
43
|
|
|
*/ |
44
|
|
|
public function testItShouldDisableTheCacheBasedOnTheForceOption() |
45
|
|
|
{ |
46
|
|
|
$configuration = ['phpdocumentor' => ['use-cache' => true]]; |
47
|
|
|
|
48
|
|
|
$middleware = new CommandlineOptionsMiddleware(['force' => true]); |
49
|
|
|
$newConfiguration = $middleware($configuration); |
50
|
|
|
|
51
|
|
|
$this->assertFalse($newConfiguration['phpdocumentor']['use-cache']); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @covers ::__invoke |
56
|
|
|
*/ |
57
|
|
|
public function testItShouldOverwriteTheCacheFolderBasedOnTheCacheFolderOption() |
58
|
|
|
{ |
59
|
|
|
$expected = '/abc'; |
60
|
|
|
$configuration = ['phpdocumentor' => ['paths' => ['cache' => '/tmp']]]; |
61
|
|
|
|
62
|
|
|
$middleware = new CommandlineOptionsMiddleware(['cache-folder' => $expected]); |
63
|
|
|
$newConfiguration = $middleware->__invoke($configuration); |
64
|
|
|
|
65
|
|
|
$this->assertEquals(new Path($expected), $newConfiguration['phpdocumentor']['paths']['cache']); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @covers ::__invoke |
70
|
|
|
*/ |
71
|
|
|
public function testItShouldOverrideTheTitleBasedOnTheTitleOption() |
72
|
|
|
{ |
73
|
|
|
$expected = 'phpDocumentor3'; |
74
|
|
|
$configuration = ['phpdocumentor' => ['title' => 'phpDocumentor2']]; |
75
|
|
|
|
76
|
|
|
$middleware = new CommandlineOptionsMiddleware(['title' => $expected]); |
77
|
|
|
$newConfiguration = $middleware($configuration); |
78
|
|
|
|
79
|
|
|
$this->assertSame($expected, $newConfiguration['phpdocumentor']['title']); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @covers ::__invoke |
84
|
|
|
*/ |
85
|
|
|
public function testItShouldOverrideTheListOfTemplatesBasedOnTheTemplateOption() |
86
|
|
|
{ |
87
|
|
|
$expected = 'clean'; |
88
|
|
|
$configuration = ['phpdocumentor' => ['templates' => ['responsive']]]; |
89
|
|
|
|
90
|
|
|
$middleware = new CommandlineOptionsMiddleware(['template' => $expected]); |
91
|
|
|
$newConfiguration = $middleware($configuration); |
92
|
|
|
|
93
|
|
|
$this->assertSame([$expected], $newConfiguration['phpdocumentor']['templates']); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @covers ::__invoke |
98
|
|
|
*/ |
99
|
|
|
public function testItShouldAddSourceFilesForDefaultConfiguration() |
100
|
|
|
{ |
101
|
|
|
$configuration = $this->givenAConfigurationWithoutApiDefinition(); |
102
|
|
|
|
103
|
|
|
$middleware = new CommandlineOptionsMiddleware(['filename' => ['./src/index.php']]); |
104
|
|
|
$newConfiguration = $middleware($configuration); |
105
|
|
|
|
106
|
|
|
$this->assertEquals( |
107
|
|
|
[ |
108
|
|
|
'dsn' => new Dsn('file://.'), |
109
|
|
|
'paths' => [new Path('./src/index.php')], |
110
|
|
|
], |
111
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['source'] |
112
|
|
|
); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @covers ::__invoke |
117
|
|
|
*/ |
118
|
|
|
public function testItShouldAddSourceDirectoriesForDefaultConfiguration() |
119
|
|
|
{ |
120
|
|
|
$configuration = $this->givenAConfigurationWithoutApiDefinition(); |
121
|
|
|
|
122
|
|
|
$middleware = new CommandlineOptionsMiddleware(['directory' => ['./src']]); |
123
|
|
|
$newConfiguration = $middleware($configuration); |
124
|
|
|
|
125
|
|
|
$this->assertEquals( |
126
|
|
|
[ |
127
|
|
|
'dsn' => new Dsn('file://.'), |
128
|
|
|
'paths' => [new Path('./src')], |
129
|
|
|
], |
130
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['source'] |
131
|
|
|
); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @covers ::__invoke |
136
|
|
|
*/ |
137
|
|
|
public function testItShouldRegisterExtensionsForDefaultConfiguration() |
138
|
|
|
{ |
139
|
|
|
$configuration = $this->givenAConfigurationWithoutApiDefinition(); |
140
|
|
|
|
141
|
|
|
$extensions = ['php7', 'php5']; |
142
|
|
|
$middleware = new CommandlineOptionsMiddleware(['extensions' => $extensions]); |
143
|
|
|
$newConfiguration = $middleware($configuration); |
144
|
|
|
|
145
|
|
|
$this->assertEquals( |
146
|
|
|
$extensions, |
147
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['extensions'] |
148
|
|
|
); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* @covers ::__invoke |
153
|
|
|
*/ |
154
|
|
|
public function testItShouldReplaceIgnoredDirectoriesForDefaultConfiguration() |
155
|
|
|
{ |
156
|
|
|
$configuration = $this->givenAConfigurationWithoutApiDefinition(); |
157
|
|
|
|
158
|
|
|
$middleware = new CommandlineOptionsMiddleware(['ignore' => ['./src']]); |
159
|
|
|
$newConfiguration = $middleware($configuration); |
160
|
|
|
|
161
|
|
|
$this->assertEquals( |
162
|
|
|
[ |
163
|
|
|
'paths' => [new Path('./src')], |
164
|
|
|
'hidden' => true |
165
|
|
|
], |
166
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['ignore'] |
167
|
|
|
); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @covers ::__invoke |
172
|
|
|
*/ |
173
|
|
|
public function testItShouldOverwriteTheMarkersOfTheDefaultConfiguration() |
174
|
|
|
{ |
175
|
|
|
$configuration = $this->givenAConfigurationWithoutApiDefinition(); |
176
|
|
|
|
177
|
|
|
$markers = ['FIXME2', 'TODOSOMETIME']; |
178
|
|
|
$middleware = new CommandlineOptionsMiddleware(['markers' => $markers]); |
179
|
|
|
$newConfiguration = $middleware($configuration); |
180
|
|
|
|
181
|
|
|
$this->assertEquals( |
182
|
|
|
$markers, |
183
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['markers'] |
184
|
|
|
); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* @covers ::__invoke |
189
|
|
|
*/ |
190
|
|
|
public function testItShouldOverwriteTheVisibilitySetInTheDefaultConfiguration() |
191
|
|
|
{ |
192
|
|
|
$configuration = $this->givenAConfigurationWithoutApiDefinition(); |
193
|
|
|
|
194
|
|
|
$visibility = ['public']; |
195
|
|
|
$middleware = new CommandlineOptionsMiddleware(['visibility' => $visibility]); |
196
|
|
|
$newConfiguration = $middleware($configuration); |
197
|
|
|
|
198
|
|
|
$this->assertEquals( |
199
|
|
|
$visibility, |
200
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['visibility'] |
201
|
|
|
); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* @covers ::__invoke |
206
|
|
|
*/ |
207
|
|
|
public function testItShouldOverwriteTheDefaultPackageNameSetInTheDefaultConfiguration() |
208
|
|
|
{ |
209
|
|
|
$configuration = $this->givenAConfigurationWithoutApiDefinition(); |
210
|
|
|
|
211
|
|
|
$defaultPackageName = ['public']; |
212
|
|
|
$middleware = new CommandlineOptionsMiddleware(['defaultpackagename' => $defaultPackageName]); |
213
|
|
|
$newConfiguration = $middleware($configuration); |
214
|
|
|
|
215
|
|
|
$this->assertEquals( |
216
|
|
|
$defaultPackageName, |
217
|
|
|
current($newConfiguration['phpdocumentor']['versions'])['api'][0]['default-package-name'] |
218
|
|
|
); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
private function givenAConfigurationWithoutApiDefinition(): array |
222
|
|
|
{ |
223
|
|
|
$configuration = Version3::buildDefault(); |
224
|
|
|
|
225
|
|
|
// wipe version so that middleware needs to re-add the api key |
226
|
|
|
unset($configuration['phpdocumentor']['versions']); |
227
|
|
|
$configuration['phpdocumentor']['versions'] = ['1.0.0' => []]; |
228
|
|
|
|
229
|
|
|
return $configuration; |
230
|
|
|
} |
231
|
|
|
} |
232
|
|
|
|