These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | */ |
||
20 | class ProjectDescriptorBuilderTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
||
21 | { |
||
22 | /** @var \phpDocumentor\Descriptor\ProjectDescriptorBuilder $fixture */ |
||
23 | protected $fixture; |
||
24 | |||
25 | /** |
||
26 | * Mock of the required AssemblerFactory dependency of the $fixture. |
||
27 | * |
||
28 | * @var \phpDocumentor\Descriptor\Builder\AssemblerFactory|m\MockInterface |
||
29 | */ |
||
30 | protected $assemblerFactory; |
||
31 | |||
32 | /** |
||
33 | * Sets up a minimal fixture with mocked dependencies. |
||
34 | */ |
||
35 | protected function setUp() |
||
36 | { |
||
37 | $this->assemblerFactory = $this->createAssemblerFactoryMock(); |
||
38 | $filterMock = m::mock('phpDocumentor\Descriptor\Filter\Filter'); |
||
39 | |||
40 | $this->fixture = new ProjectDescriptorBuilder($this->assemblerFactory, $filterMock); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @covers phpDocumentor\Descriptor\ProjectDescriptorBuilder::createProjectDescriptor |
||
45 | * @covers phpDocumentor\Descriptor\ProjectDescriptorBuilder::getProjectDescriptor |
||
46 | */ |
||
47 | public function testCreatesAnEmptyProjectDescriptorWhenCalledFor() |
||
48 | { |
||
49 | $this->fixture->createProjectDescriptor(); |
||
50 | |||
51 | $this->assertInstanceOf('phpDocumentor\Descriptor\ProjectDescriptor', $this->fixture->getProjectDescriptor()); |
||
52 | $this->assertEquals( |
||
53 | ProjectDescriptorBuilder::DEFAULT_PROJECT_NAME, |
||
54 | $this->fixture->getProjectDescriptor()->getName() |
||
55 | ); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @covers phpDocumentor\Descriptor\ProjectDescriptorBuilder::setProjectDescriptor |
||
60 | * @covers phpDocumentor\Descriptor\ProjectDescriptorBuilder::getProjectDescriptor |
||
61 | */ |
||
62 | public function testProvidingAPreExistingDescriptorToBuildOn() |
||
63 | { |
||
64 | $projectDescriptorName = 'My Descriptor'; |
||
65 | $projectDescriptorMock = new ProjectDescriptor($projectDescriptorName); |
||
66 | $this->fixture->setProjectDescriptor($projectDescriptorMock); |
||
67 | |||
68 | $this->assertSame($projectDescriptorMock, $this->fixture->getProjectDescriptor()); |
||
69 | $this->assertEquals($projectDescriptorName, $this->fixture->getProjectDescriptor()->getName()); |
||
70 | } |
||
71 | |||
72 | /** |
||
73 | * @covers phpDocumentor\Descriptor\ProjectDescriptorBuilder::isVisibilityAllowed |
||
74 | */ |
||
75 | public function testDeterminesWhetherASpecificVisibilityIsAllowedToBeIncluded() |
||
76 | { |
||
77 | $projectDescriptorName = 'My Descriptor'; |
||
78 | $projectDescriptorMock = new ProjectDescriptor($projectDescriptorName); |
||
79 | $projectDescriptorMock->getSettings()->setVisibility(Settings::VISIBILITY_PUBLIC); |
||
80 | $this->fixture->setProjectDescriptor($projectDescriptorMock); |
||
81 | |||
82 | $this->assertTrue($this->fixture->isVisibilityAllowed(Settings::VISIBILITY_PUBLIC)); |
||
83 | $this->assertFalse($this->fixture->isVisibilityAllowed(Settings::VISIBILITY_PRIVATE)); |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * Creates a new FileReflector mock that can be used as input for the builder. |
||
88 | */ |
||
89 | protected function createFileReflectorMock(): m\MockInterface |
||
90 | { |
||
91 | return m::mock('phpDocumentor\Reflection\FileReflector'); |
||
92 | } |
||
93 | |||
94 | protected function createFileDescriptorCreationMock() |
||
95 | { |
||
96 | $fileDescriptor = m::mock('phpDocumentor\Descriptor\FileDescriptor'); |
||
97 | $fileDescriptor->shouldReceive('setErrors'); |
||
98 | $fileDescriptor->shouldReceive('getPath')->andReturn('abc'); |
||
0 ignored issues
–
show
|
|||
99 | |||
100 | $fileAssembler = m::mock('stdClass'); |
||
101 | $fileAssembler->shouldReceive('setBuilder')->withAnyArgs(); |
||
102 | $fileAssembler->shouldReceive('create') |
||
103 | ->with('phpDocumentor\Reflection\FileReflector') |
||
104 | ->andReturn($fileDescriptor); |
||
105 | |||
106 | $this->assemblerFactory->shouldReceive('get') |
||
0 ignored issues
–
show
The method
shouldReceive does only exist in Mockery\MockInterface , but not in phpDocumentor\Descriptor\Builder\AssemblerFactory .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
107 | ->with('phpDocumentor\Reflection\FileReflector') |
||
108 | ->andReturn($fileAssembler); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * Creates a Mock of an AssemblerFactory. |
||
113 | * |
||
114 | * When a FileReflector (or mock thereof) is passed to the 'get' method this mock will return an |
||
115 | * empty instance of the FileDescriptor class. |
||
116 | * |
||
117 | * @return m\MockInterface|\phpDocumentor\Descriptor\Builder\AssemblerFactory |
||
118 | */ |
||
119 | protected function createAssemblerFactoryMock() |
||
120 | { |
||
121 | return m::mock('phpDocumentor\Descriptor\Builder\AssemblerFactory'); |
||
122 | } |
||
123 | } |
||
124 |
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: