1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* phpDocumentor |
4
|
|
|
* |
5
|
|
|
* PHP Version 5.3 |
6
|
|
|
* |
7
|
|
|
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
8
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
9
|
|
|
* @link http://phpdoc.org |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace phpDocumentor\Descriptor; |
13
|
|
|
|
14
|
|
|
use \Mockery as m; |
15
|
|
|
use phpDocumentor\Descriptor\ProjectDescriptor\Settings; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Tests the functionality for the ProjectDescriptorBuilder class. |
19
|
|
|
* @coversDefaultClass \phpDocumentor\Descriptor\ProjectDescriptorBuilder |
20
|
|
|
*/ |
21
|
|
|
class ProjectDescriptorBuilderTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
22
|
|
|
{ |
23
|
|
|
/** @var \phpDocumentor\Descriptor\ProjectDescriptorBuilder $fixture */ |
24
|
|
|
protected $fixture; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Mock of the required AssemblerFactory dependency of the $fixture. |
28
|
|
|
* |
29
|
|
|
* @var \phpDocumentor\Descriptor\Builder\AssemblerFactory|m\MockInterface |
30
|
|
|
*/ |
31
|
|
|
protected $assemblerFactory; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Sets up a minimal fixture with mocked dependencies. |
35
|
|
|
*/ |
36
|
|
|
protected function setUp() |
37
|
|
|
{ |
38
|
|
|
$this->assemblerFactory = $this->createAssemblerFactoryMock(); |
39
|
|
|
$filterMock = m::mock('phpDocumentor\Descriptor\Filter\Filter'); |
40
|
|
|
|
41
|
|
|
$this->fixture = new ProjectDescriptorBuilder($this->assemblerFactory, $filterMock); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @covers ::createProjectDescriptor |
46
|
|
|
* @covers ::getProjectDescriptor |
47
|
|
|
*/ |
48
|
|
|
public function testCreatesAnEmptyProjectDescriptorWhenCalledFor() |
49
|
|
|
{ |
50
|
|
|
$this->fixture->createProjectDescriptor(); |
51
|
|
|
|
52
|
|
|
$this->assertInstanceOf('phpDocumentor\Descriptor\ProjectDescriptor', $this->fixture->getProjectDescriptor()); |
53
|
|
|
$this->assertEquals( |
54
|
|
|
ProjectDescriptorBuilder::DEFAULT_PROJECT_NAME, |
55
|
|
|
$this->fixture->getProjectDescriptor()->getName() |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Creates a new FileReflector mock that can be used as input for the builder. |
61
|
|
|
*/ |
62
|
|
|
protected function createFileReflectorMock(): m\MockInterface |
63
|
|
|
{ |
64
|
|
|
return m::mock('phpDocumentor\Reflection\FileReflector'); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
protected function createFileDescriptorCreationMock() |
68
|
|
|
{ |
69
|
|
|
$fileDescriptor = m::mock('phpDocumentor\Descriptor\FileDescriptor'); |
70
|
|
|
$fileDescriptor->shouldReceive('setErrors'); |
71
|
|
|
$fileDescriptor->shouldReceive('getPath')->andReturn('abc'); |
|
|
|
|
72
|
|
|
|
73
|
|
|
$fileAssembler = m::mock('stdClass'); |
74
|
|
|
$fileAssembler->shouldReceive('setBuilder')->withAnyArgs(); |
75
|
|
|
$fileAssembler->shouldReceive('create') |
76
|
|
|
->with('phpDocumentor\Reflection\FileReflector') |
77
|
|
|
->andReturn($fileDescriptor); |
78
|
|
|
|
79
|
|
|
$this->assemblerFactory->shouldReceive('get') |
|
|
|
|
80
|
|
|
->with('phpDocumentor\Reflection\FileReflector') |
81
|
|
|
->andReturn($fileAssembler); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Creates a Mock of an AssemblerFactory. |
86
|
|
|
* |
87
|
|
|
* When a FileReflector (or mock thereof) is passed to the 'get' method this mock will return an |
88
|
|
|
* empty instance of the FileDescriptor class. |
89
|
|
|
* |
90
|
|
|
* @return m\MockInterface|\phpDocumentor\Descriptor\Builder\AssemblerFactory |
91
|
|
|
*/ |
92
|
|
|
protected function createAssemblerFactoryMock() |
93
|
|
|
{ |
94
|
|
|
return m::mock('phpDocumentor\Descriptor\Builder\AssemblerFactory'); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
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: