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-2013 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 $assemblerFactory |
||
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 | $validatorMock = m::mock('Symfony\Component\Validator\Validator'); |
||
40 | |||
41 | $this->fixture = new ProjectDescriptorBuilder($this->assemblerFactory, $filterMock, $validatorMock); |
||
0 ignored issues
–
show
|
|||
42 | } |
||
43 | |||
44 | /** |
||
45 | * Demonstrates the basic usage the the ProjectDescriptorBuilder. |
||
46 | * |
||
47 | * This test scenario demonstrates how a ProjectDescriptorBuilder can be used to create a new ProjectDescriptor |
||
48 | * and populate it with a single FileDescriptor using a FileReflector as source. |
||
49 | * |
||
50 | * @covers phpDocumentor\Descriptor\ProjectDescriptorBuilder::createProjectDescriptor |
||
51 | * @covers phpDocumentor\Descriptor\ProjectDescriptorBuilder::buildFileUsingSourceData |
||
52 | * @covers phpDocumentor\Descriptor\ProjectDescriptorBuilder::getProjectDescriptor |
||
53 | * |
||
54 | * @see self::setUp on how to create an instance of the builder. |
||
55 | * |
||
56 | * @return void |
||
57 | */ |
||
58 | public function testCreateNewProjectDescriptorAndBuildFile() |
||
59 | { |
||
60 | $this->markTestIncomplete('Finish later, in a hurry now.'); |
||
61 | // we use a FileReflector as example input |
||
62 | $data = $this->createFileReflectorMock(); |
||
63 | |||
64 | $this->createFileDescriptorCreationMock(); |
||
65 | |||
66 | // usage example, see the setup how to instantiate the builder. |
||
67 | $this->fixture->createProjectDescriptor(); |
||
68 | $this->fixture->buildFileUsingSourceData($data); |
||
0 ignored issues
–
show
The method
buildFileUsingSourceData() does not seem to exist on object<phpDocumentor\Des...ojectDescriptorBuilder> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
69 | $projectDescriptor = $this->fixture->getProjectDescriptor(); |
||
70 | |||
71 | // assert functioning |
||
72 | $this->assertInstanceOf('phpDocumentor\Descriptor\ProjectDescriptor', $projectDescriptor); |
||
73 | $this->assertCount(1, $projectDescriptor->getFiles()); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @covers phpDocumentor\Descriptor\ProjectDescriptorBuilder::createProjectDescriptor |
||
78 | * @covers phpDocumentor\Descriptor\ProjectDescriptorBuilder::getProjectDescriptor |
||
79 | */ |
||
80 | public function testCreatesAnEmptyProjectDescriptorWhenCalledFor() |
||
81 | { |
||
82 | $this->fixture->createProjectDescriptor(); |
||
83 | |||
84 | $this->assertInstanceOf('phpDocumentor\Descriptor\ProjectDescriptor', $this->fixture->getProjectDescriptor()); |
||
85 | $this->assertEquals( |
||
86 | ProjectDescriptorBuilder::DEFAULT_PROJECT_NAME, |
||
87 | $this->fixture->getProjectDescriptor()->getName() |
||
88 | ); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @covers phpDocumentor\Descriptor\ProjectDescriptorBuilder::setProjectDescriptor |
||
93 | * @covers phpDocumentor\Descriptor\ProjectDescriptorBuilder::getProjectDescriptor |
||
94 | */ |
||
95 | public function testProvidingAPreExistingDescriptorToBuildOn() |
||
96 | { |
||
97 | $projectDescriptorName = 'My Descriptor'; |
||
98 | $projectDescriptorMock = new ProjectDescriptor($projectDescriptorName); |
||
99 | $this->fixture->setProjectDescriptor($projectDescriptorMock); |
||
100 | |||
101 | $this->assertSame($projectDescriptorMock, $this->fixture->getProjectDescriptor()); |
||
102 | $this->assertEquals($projectDescriptorName, $this->fixture->getProjectDescriptor()->getName()); |
||
103 | } |
||
104 | |||
105 | /** |
||
106 | * @covers phpDocumentor\Descriptor\ProjectDescriptorBuilder::isVisibilityAllowed |
||
107 | */ |
||
108 | public function testDeterminesWhetherASpecificVisibilityIsAllowedToBeIncluded() |
||
109 | { |
||
110 | $projectDescriptorName = 'My Descriptor'; |
||
111 | $projectDescriptorMock = new ProjectDescriptor($projectDescriptorName); |
||
112 | $projectDescriptorMock->getSettings()->setVisibility(Settings::VISIBILITY_PUBLIC); |
||
113 | $this->fixture->setProjectDescriptor($projectDescriptorMock); |
||
114 | |||
115 | $this->assertTrue($this->fixture->isVisibilityAllowed(Settings::VISIBILITY_PUBLIC)); |
||
116 | $this->assertFalse($this->fixture->isVisibilityAllowed(Settings::VISIBILITY_PRIVATE)); |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * Creates a new FileReflector mock that can be used as input for the builder. |
||
121 | * |
||
122 | * @return m\MockInterface|\phpDocumentor\Reflection\FileReflector |
||
123 | */ |
||
124 | protected function createFileReflectorMock() |
||
125 | { |
||
126 | return m::mock('phpDocumentor\Reflection\FileReflector'); |
||
127 | } |
||
128 | |||
129 | protected function createFileDescriptorCreationMock() |
||
130 | { |
||
131 | $fileDescriptor = m::mock('phpDocumentor\Descriptor\FileDescriptor'); |
||
132 | $fileDescriptor->shouldReceive('setErrors'); |
||
133 | $fileDescriptor->shouldReceive('getPath')->andReturn('abc'); |
||
134 | |||
135 | $fileAssembler = m::mock('stdClass'); |
||
136 | $fileAssembler->shouldReceive('setBuilder')->withAnyArgs(); |
||
137 | $fileAssembler->shouldReceive('create') |
||
138 | ->with('phpDocumentor\Reflection\FileReflector') |
||
139 | ->andReturn($fileDescriptor); |
||
140 | |||
141 | $this->assemblerFactory->shouldReceive('get') |
||
142 | ->with('phpDocumentor\Reflection\FileReflector') |
||
143 | ->andReturn($fileAssembler); |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * Creates a Mock of an AssemblerFactory. |
||
148 | * |
||
149 | * When a FileReflector (or mock thereof) is passed to the 'get' method this mock will return an |
||
150 | * empty instance of the FileDescriptor class. |
||
151 | * |
||
152 | * @return m\MockInterface|\phpDocumentor\Descriptor\Builder\AssemblerFactory |
||
153 | */ |
||
154 | protected function createAssemblerFactoryMock() |
||
155 | { |
||
156 | return m::mock('phpDocumentor\Descriptor\Builder\AssemblerFactory'); |
||
157 | } |
||
158 | } |
||
159 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.