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-2017 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\Transformer; |
14
|
|
|
|
15
|
|
|
use Cilex\Application; |
16
|
|
|
use \phpDocumentor\Descriptor\ProjectDescriptorBuilder; |
17
|
|
|
use Mockery as m; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Tests for phpDocumentor\Translator\ServiceProvider |
21
|
|
|
* @coversDefaultClass \phpDocumentor\Transformer\ServiceProvider |
22
|
|
|
* @covers ::<protected> |
23
|
|
|
*/ |
24
|
|
|
class ServiceProviderTest extends \PHPUnit_Framework_TestCase |
25
|
|
|
{ |
26
|
|
|
/** @var ServiceProvider $fixture */ |
27
|
|
|
protected $fixture = null; |
28
|
|
|
|
29
|
|
|
/** @var \Cilex\Application $application */ |
30
|
|
|
protected $application = null; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Setup test fixture and mocks used in this TestCase |
34
|
|
|
*/ |
35
|
|
|
protected function setUp() |
36
|
|
|
{ |
37
|
|
|
$this->application = new Application('test'); |
38
|
|
|
|
39
|
|
|
$projectDescriptorBuilder = m::mock('phpDocumentor\Descriptor\ProjectDescriptorBuilder'); |
40
|
|
|
$serializer = m::mock('JMS\Serializer\Serializer'); |
41
|
|
|
|
42
|
|
|
$transformer = m::mock('phpDocumentor\Transformer\Transformer'); |
43
|
|
|
$transformer->shouldReceive('getExternalClassDocumentation')->andReturn([]); |
44
|
|
|
|
45
|
|
|
$configuration = m::mock('\phpDocumentor\Configuration'); |
46
|
|
|
$configuration->shouldReceive('getTransformer')->andReturn($transformer); |
47
|
|
|
|
48
|
|
|
$finder = m::mock('\phpDocumentor\Descriptor\Example\Finder'); |
49
|
|
|
$logger = m::mock('\monolog\Logger'); |
50
|
|
|
$analyzer = m::mock('\phpDocumentor\Descriptor\ProjectAnalyzer'); |
51
|
|
|
|
52
|
|
|
$loggerHelper = m::mock('\phpDocumentor\Command\Helper\LoggerHelper'); |
53
|
|
|
$loggerHelper->shouldReceive('getName')->andReturn('phpdocumentor_logger'); |
54
|
|
|
$loggerHelper->shouldReceive('setHelperSet'); |
55
|
|
|
$loggerHelper->shouldReceive('addOptions'); |
56
|
|
|
|
57
|
|
|
$this->application['descriptor.builder'] = $projectDescriptorBuilder; |
58
|
|
|
$this->application['serializer'] = $serializer; |
59
|
|
|
$this->application['config'] = $configuration; |
60
|
|
|
$this->application['parser.example.finder'] = $finder; |
61
|
|
|
$this->application['monolog'] = $logger; |
62
|
|
|
$this->application['descriptor.analyzer'] = $analyzer; |
63
|
|
|
$this->application['console']->getHelperSet()->set($loggerHelper); |
64
|
|
|
|
65
|
|
|
$this->fixture = new ServiceProvider(); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @covers ::register |
70
|
|
|
*/ |
71
|
|
|
public function testRegisterSetsLinkerSubstitutions() |
72
|
|
|
{ |
73
|
|
|
$this->fixture->register($this->application); |
74
|
|
|
|
75
|
|
|
$substitutions = $this->application['linker.substitutions']; |
76
|
|
|
$this->assertSame($substitutions, $this->givenLinkerSubstitutions()); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @covers ::register |
81
|
|
|
*/ |
82
|
|
|
public function testRegisterSetsCompiler() |
83
|
|
|
{ |
84
|
|
|
$this->fixture->register($this->application); |
85
|
|
|
|
86
|
|
|
$compiler = $this->application->offsetGet('compiler'); |
87
|
|
|
|
88
|
|
|
$this->assertInstanceOf('phpDocumentor\Compiler\Compiler', $compiler); |
89
|
|
|
$this->assertCount(9, $compiler); |
90
|
|
|
$this->assertInstanceOf('phpDocumentor\Compiler\Pass\ElementsIndexBuilder', $compiler->current()); |
91
|
|
|
$compiler->next(); |
92
|
|
|
$this->assertInstanceOf('phpDocumentor\Compiler\Linker\Linker', $compiler->current()); |
93
|
|
|
$compiler->next(); |
94
|
|
|
$this->assertInstanceOf('phpDocumentor\Compiler\Pass\ResolveInlineLinkAndSeeTags', $compiler->current()); |
95
|
|
|
$compiler->next(); |
96
|
|
|
$this->assertInstanceOf('phpDocumentor\Compiler\Pass\ExampleTagsEnricher', $compiler->current()); |
97
|
|
|
$compiler->next(); |
98
|
|
|
$this->assertInstanceOf('phpDocumentor\Compiler\Pass\PackageTreeBuilder', $compiler->current()); |
99
|
|
|
$compiler->next(); |
100
|
|
|
$this->assertInstanceOf('phpDocumentor\Compiler\Pass\NamespaceTreeBuilder', $compiler->current()); |
101
|
|
|
$compiler->next(); |
102
|
|
|
$this->assertInstanceOf('phpDocumentor\Compiler\Pass\MarkerFromTagsExtractor', $compiler->current()); |
103
|
|
|
$compiler->next(); |
104
|
|
|
$this->assertInstanceOf('phpDocumentor\Transformer\Transformer', $compiler->current()); |
105
|
|
|
$compiler->next(); |
106
|
|
|
$this->assertInstanceOf('phpDocumentor\Compiler\Pass\Debug', $compiler->current()); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @covers ::register |
111
|
|
|
*/ |
112
|
|
|
public function testRegisterSetsLinker() |
113
|
|
|
{ |
114
|
|
|
$this->fixture->register($this->application); |
115
|
|
|
|
116
|
|
|
$linker = $this->application->offsetGet('linker'); |
117
|
|
|
|
118
|
|
|
$this->assertInstanceOf('phpDocumentor\Compiler\Linker\Linker', $linker); |
119
|
|
|
$this->assertSame($this->givenLinkerSubstitutions(), $linker->getSubstitutions()); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @covers ::register |
124
|
|
|
*/ |
125
|
|
|
public function testRegisterTransformerBehaviourCollection() |
126
|
|
|
{ |
127
|
|
|
$this->fixture->register($this->application); |
128
|
|
|
|
129
|
|
|
$collection = $this->application->offsetGet('transformer.behaviour.collection'); |
130
|
|
|
|
131
|
|
|
$this->assertInstanceOf('phpDocumentor\Transformer\Behaviour\Collection', $collection); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @covers ::register |
136
|
|
|
*/ |
137
|
|
|
public function testRegisterTransformerRoutingStandard() |
138
|
|
|
{ |
139
|
|
|
$this->fixture->register($this->application); |
140
|
|
|
|
141
|
|
|
$router = $this->application->offsetGet('transformer.routing.standard'); |
142
|
|
|
|
143
|
|
|
$this->assertInstanceOf('phpDocumentor\Transformer\Router\StandardRouter', $router); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @covers ::register |
148
|
|
|
*/ |
149
|
|
|
public function testRegisterTransformerRoutingExternal() |
150
|
|
|
{ |
151
|
|
|
$this->fixture->register($this->application); |
152
|
|
|
|
153
|
|
|
$router = $this->application->offsetGet('transformer.routing.external'); |
154
|
|
|
|
155
|
|
|
$this->assertInstanceOf('phpDocumentor\Transformer\Router\ExternalRouter', $router); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* @covers ::register |
160
|
|
|
*/ |
161
|
|
|
public function testRegisterTransformerRoutingQueue() |
162
|
|
|
{ |
163
|
|
|
$this->fixture->register($this->application); |
164
|
|
|
|
165
|
|
|
$queue = $this->application->offsetGet('transformer.routing.queue'); |
166
|
|
|
|
167
|
|
|
$this->assertInstanceOf('phpDocumentor\Transformer\Router\Queue', $queue); |
168
|
|
|
$this->assertSame($this->application->offsetGet('transformer.routing.external'), $queue->current()); |
169
|
|
|
$queue->next(); |
170
|
|
|
$this->assertSame($this->application->offsetGet('transformer.routing.standard'), $queue->current()); |
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
/** |
174
|
|
|
* @covers ::register |
175
|
|
|
*/ |
176
|
|
|
public function testRegisterTransformerWriterCollection() |
177
|
|
|
{ |
178
|
|
|
$this->fixture->register($this->application); |
179
|
|
|
|
180
|
|
|
$collection = $this->application->offsetGet('transformer.writer.collection'); |
181
|
|
|
|
182
|
|
|
$this->assertInstanceOf('phpDocumentor\Transformer\Writer\Collection', $collection); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* @covers ::register |
187
|
|
|
*/ |
188
|
|
|
public function testRegisterTemplateLocation() |
189
|
|
|
{ |
190
|
|
|
$this->fixture->register($this->application); |
191
|
|
|
|
192
|
|
|
$location = $this->application->offsetGet('transformer.template.location'); |
193
|
|
|
|
194
|
|
|
$this->assertSame('templates', substr($location, -9)); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
/** |
198
|
|
|
* @covers ::register |
199
|
|
|
*/ |
200
|
|
|
public function testRegisterTemplatePathResolver() |
201
|
|
|
{ |
202
|
|
|
$this->fixture->register($this->application); |
203
|
|
|
|
204
|
|
|
$resolver = $this->application->offsetGet('transformer.template.path_resolver'); |
205
|
|
|
|
206
|
|
|
$this->assertInstanceOf('phpDocumentor\Transformer\Template\PathResolver', $resolver); |
207
|
|
|
$this->assertSame('templates', substr($resolver->getTemplatePath(), -9)); |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* @covers ::register |
212
|
|
|
*/ |
213
|
|
|
public function testRegisterTemplateFactory() |
214
|
|
|
{ |
215
|
|
|
$this->fixture->register($this->application); |
216
|
|
|
|
217
|
|
|
$factory = $this->application->offsetGet('transformer.template.factory'); |
218
|
|
|
|
219
|
|
|
$this->assertInstanceOf('phpDocumentor\Transformer\Template\Factory', $factory); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* @covers ::register |
224
|
|
|
*/ |
225
|
|
|
public function testRegisterTemplateCollection() |
226
|
|
|
{ |
227
|
|
|
$this->fixture->register($this->application); |
228
|
|
|
|
229
|
|
|
$collection = $this->application->offsetGet('transformer.template.collection'); |
230
|
|
|
|
231
|
|
|
$this->assertInstanceOf('phpDocumentor\Transformer\Template\Collection', $collection); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
235
|
|
|
* @covers ::register |
236
|
|
|
*/ |
237
|
|
|
public function testRegisterTransformer() |
238
|
|
|
{ |
239
|
|
|
$this->fixture->register($this->application); |
240
|
|
|
|
241
|
|
|
$transformer = $this->application->offsetGet('transformer'); |
242
|
|
|
|
243
|
|
|
$this->assertInstanceOf('phpDocumentor\Transformer\Transformer', $transformer); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* @covers ::register |
248
|
|
|
*/ |
249
|
|
|
public function testRegisterTransformCommand() |
250
|
|
|
{ |
251
|
|
|
$this->fixture->register($this->application); |
252
|
|
|
|
253
|
|
|
$transformCommand = $this->application->offsetGet('console')->get('transform'); |
254
|
|
|
|
255
|
|
|
$this->assertInstanceOf('phpDocumentor\Transformer\Command\Project\TransformCommand', $transformCommand); |
256
|
|
|
} |
257
|
|
|
|
258
|
|
|
/** |
259
|
|
|
* @covers ::register |
260
|
|
|
*/ |
261
|
|
|
public function testRegisterListCommand() |
262
|
|
|
{ |
263
|
|
|
$this->fixture->register($this->application); |
264
|
|
|
|
265
|
|
|
$listCommand = $this->application->offsetGet('console')->get('template:list'); |
266
|
|
|
|
267
|
|
|
$this->assertInstanceOf('phpDocumentor\Transformer\Command\Template\ListCommand', $listCommand); |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* @covers ::register |
272
|
|
|
* @expectedException \phpDocumentor\Transformer\Exception\MissingDependencyException |
273
|
|
|
* @expectedExceptionMessage The builder object that is used to construct the ProjectDescriptor is missing |
274
|
|
|
*/ |
275
|
|
|
public function testRegisterThrowsExceptionIfBuilderIsMissing() |
276
|
|
|
{ |
277
|
|
|
$this->fixture->register(new Application('test')); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* @covers ::register |
282
|
|
|
* @expectedException \phpDocumentor\Transformer\Exception\MissingDependencyException |
283
|
|
|
* @expectedExceptionMessage The serializer object that is used to read the template configuration with is missing |
284
|
|
|
*/ |
285
|
|
|
public function testRegisterThrowsExceptionIfSerializerIsMissing() |
286
|
|
|
{ |
287
|
|
|
$application = new Application('test'); |
288
|
|
|
$projectDescriptorBuilder = m::mock('phpDocumentor\Descriptor\ProjectDescriptorBuilder'); |
289
|
|
|
$application['descriptor.builder'] = $projectDescriptorBuilder; |
290
|
|
|
|
291
|
|
|
$this->fixture->register($application); |
292
|
|
|
} |
293
|
|
|
|
294
|
|
|
private function givenLinkerSubstitutions() |
295
|
|
|
{ |
296
|
|
|
$substitutions = array( |
297
|
|
|
'phpDocumentor\Descriptor\ProjectDescriptor' => array('files'), |
298
|
|
|
'phpDocumentor\Descriptor\FileDescriptor' => array( |
299
|
|
|
'tags', |
300
|
|
|
'classes', |
301
|
|
|
'interfaces', |
302
|
|
|
'traits', |
303
|
|
|
'functions', |
304
|
|
|
'constants' |
305
|
|
|
), |
306
|
|
|
'phpDocumentor\Descriptor\ClassDescriptor' => array( |
307
|
|
|
'tags', |
308
|
|
|
'parent', |
309
|
|
|
'interfaces', |
310
|
|
|
'constants', |
311
|
|
|
'properties', |
312
|
|
|
'methods', |
313
|
|
|
'usedTraits', |
314
|
|
|
), |
315
|
|
|
'phpDocumentor\Descriptor\InterfaceDescriptor' => array( |
316
|
|
|
'tags', |
317
|
|
|
'parent', |
318
|
|
|
'constants', |
319
|
|
|
'methods', |
320
|
|
|
), |
321
|
|
|
'phpDocumentor\Descriptor\TraitDescriptor' => array( |
322
|
|
|
'tags', |
323
|
|
|
'properties', |
324
|
|
|
'methods', |
325
|
|
|
'usedTraits', |
326
|
|
|
), |
327
|
|
|
'phpDocumentor\Descriptor\FunctionDescriptor' => array('tags', 'arguments'), |
328
|
|
|
'phpDocumentor\Descriptor\MethodDescriptor' => array('tags', 'arguments'), |
329
|
|
|
'phpDocumentor\Descriptor\ArgumentDescriptor' => array('types'), |
330
|
|
|
'phpDocumentor\Descriptor\PropertyDescriptor' => array('tags', 'types'), |
331
|
|
|
'phpDocumentor\Descriptor\ConstantDescriptor' => array('tags', 'types'), |
332
|
|
|
'phpDocumentor\Descriptor\Tag\ParamDescriptor' => array('types'), |
333
|
|
|
'phpDocumentor\Descriptor\Tag\ReturnDescriptor' => array('types'), |
334
|
|
|
'phpDocumentor\Descriptor\Tag\SeeDescriptor' => array('reference'), |
335
|
|
|
'phpDocumentor\Descriptor\Tag\UsesDescriptor' => array('reference'), |
336
|
|
|
'phpDocumentor\Descriptor\Type\CollectionDescriptor' => array('baseType', 'types', 'keyTypes'), |
337
|
|
|
); |
338
|
|
|
|
339
|
|
|
return $substitutions; |
340
|
|
|
} |
341
|
|
|
} |
342
|
|
|
|