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\Parser\Command\Project; |
14
|
|
|
|
15
|
|
|
use Mockery\Adapter\Phpunit\MockeryTestCase; |
16
|
|
|
use phpDocumentor\Command\Helper\ConfigurationHelper; |
17
|
|
|
use phpDocumentor\Command\Helper\LoggerHelper; |
18
|
|
|
use phpDocumentor\Console\Output\Output; |
19
|
|
|
use phpDocumentor\Descriptor\ProjectDescriptor; |
20
|
|
|
use phpDocumentor\Descriptor\ProjectDescriptorBuilder; |
21
|
|
|
use phpDocumentor\DomainModel\Parser\FileCollector; |
22
|
|
|
use phpDocumentor\Fileset\Collection; |
23
|
|
|
use phpDocumentor\Parser\Command\Project\ParseCommand; |
24
|
|
|
use \Mockery as m; |
25
|
|
|
use phpDocumentor\Parser\Parser; |
26
|
|
|
use phpDocumentor\Reflection\DocBlock\ExampleFinder; |
27
|
|
|
use Symfony\Component\Console\Helper\HelperSet; |
28
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
29
|
|
|
use Zend\Cache\Storage\StorageInterface; |
30
|
|
|
use Zend\I18n\Translator\Translator; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @coversDefaultClass phpDocumentor\Parser\Command\Project\ParseCommand |
34
|
|
|
* @covers ::<protected> |
35
|
|
|
*/ |
36
|
|
|
class ParseCommandTest extends MockeryTestCase |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* Tests the processing of target directory when non is provided. |
40
|
|
|
* @covers ::execute |
41
|
|
|
*/ |
42
|
|
|
public function testDefaultTargetDirCreation() |
43
|
|
|
{ |
44
|
|
|
$input = new ArrayInput([]); |
45
|
|
|
$output = new Output(); |
46
|
|
|
|
47
|
|
|
$configurationHelper = m::mock(ConfigurationHelper::class); |
48
|
|
|
$configurationHelper->shouldReceive('getName') |
|
|
|
|
49
|
|
|
->andReturn('phpdocumentor_configuration'); |
50
|
|
|
$configurationHelper->shouldReceive('setHelperSet'); |
51
|
|
|
$configurationHelper->shouldReceive('getOption') |
52
|
|
|
->with($input, 'extensions', 'parser/extensions', array('php', 'php3', 'phtml'), true) |
53
|
|
|
->andReturn([]); |
54
|
|
|
$configurationHelper->shouldReceive('getOption') |
55
|
|
|
->with($input, 'target', 'parser/target'); |
56
|
|
|
$configurationHelper->shouldReceive('getOption') |
57
|
|
|
->with($input, m::any(), m::any(), m::any(), m::any()) |
58
|
|
|
->andReturn([]); |
59
|
|
|
$configurationHelper->shouldReceive('getOption') |
60
|
|
|
->with($input, m::any(), m::any(), m::any()) |
61
|
|
|
->andReturn([]); |
62
|
|
|
$configurationHelper->shouldReceive('getOption') |
63
|
|
|
->with($input, m::any(), m::any()) |
64
|
|
|
->andReturn('Title'); |
65
|
|
|
$configurationHelper->shouldReceive('getConfigValueFromPath') |
66
|
|
|
->andReturn([]); |
67
|
|
|
|
68
|
|
|
$loggerHelper = m::mock(LoggerHelper::class); |
69
|
|
|
$loggerHelper->shouldReceive('getName') |
70
|
|
|
->andReturn('phpdocumentor_logger'); |
71
|
|
|
$loggerHelper->shouldReceive('setHelperSet'); |
72
|
|
|
$loggerHelper->shouldReceive('addOptions'); |
73
|
|
|
$loggerHelper->shouldReceive('connectOutputToLogging'); |
74
|
|
|
|
75
|
|
|
$translator = m::mock(Translator::class); |
76
|
|
|
$translator->shouldReceive('translate') |
77
|
|
|
->zeroOrMoreTimes(); |
78
|
|
|
|
79
|
|
|
$cache = m::mock(StorageInterface::class); |
80
|
|
|
$cache->shouldReceive('getOptions') |
81
|
|
|
->twice() |
82
|
|
|
->andReturnSelf(); |
83
|
|
|
$cache->shouldReceive('setCacheDir'); |
84
|
|
|
$cache->shouldReceive('getCacheDir'); |
85
|
|
|
$cache->shouldReceive('getItem'); |
86
|
|
|
$cache->shouldReceive('setItem'); |
87
|
|
|
$cache->shouldReceive('getIterator') |
88
|
|
|
->andReturn(new \ArrayIterator()); |
89
|
|
|
|
90
|
|
|
$parser = m::mock(Parser::class); |
91
|
|
|
$parser->shouldReceive( |
92
|
|
|
'setForced', |
93
|
|
|
'setEncoding', |
94
|
|
|
'setMarkers', |
95
|
|
|
'setIgnoredTags', |
96
|
|
|
'setValidate', |
97
|
|
|
'setDefaultPackageName', |
98
|
|
|
'setPath', |
99
|
|
|
'parse' |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
$projectDescriptorBuilder = m::mock(ProjectDescriptorBuilder::class); |
103
|
|
|
$projectDescriptorBuilder->shouldReceive('createProjectDescriptor', 'getProjectDescriptor') |
104
|
|
|
->andReturn(new ProjectDescriptor('test')); |
105
|
|
|
|
106
|
|
|
$command = new ParseCommand( |
107
|
|
|
$projectDescriptorBuilder, |
108
|
|
|
$parser, |
109
|
|
|
m::mock(FileCollector::class), |
110
|
|
|
$translator, |
111
|
|
|
$cache, |
112
|
|
|
new ExampleFinder(), |
113
|
|
|
m::mock(\phpDocumentor\Partials\Collection::class) |
114
|
|
|
); |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
|
118
|
|
|
$command->setHelperSet( |
119
|
|
|
new HelperSet( |
120
|
|
|
[ |
|
|
|
|
121
|
|
|
$configurationHelper, |
122
|
|
|
$loggerHelper |
123
|
|
|
] |
124
|
|
|
) |
125
|
|
|
); |
126
|
|
|
|
127
|
|
|
$command->run($input, $output); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: