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 | |||
16 | /** |
||
17 | * Tests the functionality for the FileDescriptor class. |
||
18 | */ |
||
19 | class FileDescriptorTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
||
20 | { |
||
21 | const EXAMPLE_HASH = 'a-hash-string'; |
||
22 | const EXAMPLE_PATH = 'a-path-string'; |
||
23 | const EXAMPLE_SOURCE = 'a-source-string'; |
||
24 | |||
25 | /** @var FileDescriptor $fixture */ |
||
26 | protected $fixture; |
||
27 | |||
28 | /** |
||
29 | * Creates a new (empty) fixture object. |
||
30 | */ |
||
31 | protected function setUp() |
||
32 | { |
||
33 | $this->fixture = new FileDescriptor(self::EXAMPLE_HASH); |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Tests whether all collection objects and hash are properly initialized |
||
38 | * |
||
39 | * @covers phpDocumentor\Descriptor\FileDescriptor::__construct |
||
40 | */ |
||
41 | public function testInitialize() |
||
42 | { |
||
43 | $this->assertAttributeEquals(self::EXAMPLE_HASH, 'hash', $this->fixture); |
||
44 | |||
45 | $this->assertAttributeInstanceOf('phpDocumentor\Descriptor\Collection', 'namespaceAliases', $this->fixture); |
||
46 | $this->assertAttributeInstanceOf('phpDocumentor\Descriptor\Collection', 'includes', $this->fixture); |
||
47 | $this->assertAttributeInstanceOf('phpDocumentor\Descriptor\Collection', 'constants', $this->fixture); |
||
48 | $this->assertAttributeInstanceOf('phpDocumentor\Descriptor\Collection', 'functions', $this->fixture); |
||
49 | $this->assertAttributeInstanceOf('phpDocumentor\Descriptor\Collection', 'classes', $this->fixture); |
||
50 | $this->assertAttributeInstanceOf('phpDocumentor\Descriptor\Collection', 'interfaces', $this->fixture); |
||
51 | $this->assertAttributeInstanceOf('phpDocumentor\Descriptor\Collection', 'traits', $this->fixture); |
||
52 | $this->assertAttributeInstanceOf('phpDocumentor\Descriptor\Collection', 'markers', $this->fixture); |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * @covers phpDocumentor\Descriptor\FileDescriptor::__construct |
||
57 | * @covers phpDocumentor\Descriptor\FileDescriptor::getHash |
||
58 | */ |
||
59 | public function testGetHash() |
||
60 | { |
||
61 | $this->assertSame(self::EXAMPLE_HASH, $this->fixture->getHash()); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @covers phpDocumentor\Descriptor\FileDescriptor::setPath |
||
66 | * @covers phpDocumentor\Descriptor\FileDescriptor::getPath |
||
67 | */ |
||
68 | public function testSetAndGetPath() |
||
69 | { |
||
70 | $this->assertSame('', $this->fixture->getPath()); |
||
71 | |||
72 | $this->fixture->setPath(self::EXAMPLE_PATH); |
||
73 | |||
74 | $this->assertSame(self::EXAMPLE_PATH, $this->fixture->getPath()); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @covers phpDocumentor\Descriptor\FileDescriptor::setSource |
||
79 | * @covers phpDocumentor\Descriptor\FileDescriptor::getSource |
||
80 | */ |
||
81 | public function testSetAndGetSource() |
||
82 | { |
||
83 | $this->assertNull($this->fixture->getSource()); |
||
84 | |||
85 | $this->fixture->setSource(self::EXAMPLE_SOURCE); |
||
86 | |||
87 | $this->assertSame(self::EXAMPLE_SOURCE, $this->fixture->getSource()); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * @covers phpDocumentor\Descriptor\FileDescriptor::setNamespaceAliases |
||
92 | * @covers phpDocumentor\Descriptor\FileDescriptor::getNamespaceAliases |
||
93 | */ |
||
94 | public function testSetAndGetNamespaceAliases() |
||
95 | { |
||
96 | $this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getNamespaceAliases()); |
||
97 | |||
98 | $mockInstance = m::mock('phpDocumentor\Descriptor\Collection'); |
||
99 | $mock = $mockInstance; |
||
100 | |||
101 | $this->fixture->setNamespaceAliases($mock); |
||
102 | |||
103 | $this->assertSame($mockInstance, $this->fixture->getNamespaceAliases()); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * @covers phpDocumentor\Descriptor\FileDescriptor::setIncludes |
||
108 | * @covers phpDocumentor\Descriptor\FileDescriptor::getIncludes |
||
109 | */ |
||
110 | public function testSetAndGetIncludes() |
||
111 | { |
||
112 | $this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getIncludes()); |
||
113 | |||
114 | $mockInstance = m::mock('phpDocumentor\Descriptor\Collection'); |
||
115 | $mock = $mockInstance; |
||
116 | |||
117 | $this->fixture->setIncludes($mock); |
||
118 | |||
119 | $this->assertSame($mockInstance, $this->fixture->getIncludes()); |
||
120 | } |
||
121 | |||
122 | /** |
||
123 | * @covers phpDocumentor\Descriptor\FileDescriptor::setConstants |
||
124 | * @covers phpDocumentor\Descriptor\FileDescriptor::getConstants |
||
125 | */ |
||
126 | public function testSetAndGetConstants() |
||
127 | { |
||
128 | $this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getConstants()); |
||
129 | |||
130 | $mockInstance = m::mock('phpDocumentor\Descriptor\Collection'); |
||
131 | $mock = $mockInstance; |
||
132 | |||
133 | $this->fixture->setConstants($mock); |
||
134 | |||
135 | $this->assertSame($mockInstance, $this->fixture->getConstants()); |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * @covers phpDocumentor\Descriptor\FileDescriptor::setFunctions |
||
140 | * @covers phpDocumentor\Descriptor\FileDescriptor::getFunctions |
||
141 | */ |
||
142 | public function testSetAndGetFunctions() |
||
143 | { |
||
144 | $this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getFunctions()); |
||
145 | |||
146 | $mockInstance = m::mock('phpDocumentor\Descriptor\Collection'); |
||
147 | $mock = $mockInstance; |
||
148 | |||
149 | $this->fixture->setFunctions($mock); |
||
150 | |||
151 | $this->assertSame($mockInstance, $this->fixture->getFunctions()); |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * @covers phpDocumentor\Descriptor\FileDescriptor::setClasses |
||
156 | * @covers phpDocumentor\Descriptor\FileDescriptor::getClasses |
||
157 | */ |
||
158 | public function testSetAndGetClasses() |
||
159 | { |
||
160 | $this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getClasses()); |
||
161 | |||
162 | $mockInstance = m::mock('phpDocumentor\Descriptor\Collection'); |
||
163 | $mock = $mockInstance; |
||
164 | |||
165 | $this->fixture->setClasses($mock); |
||
166 | |||
167 | $this->assertSame($mockInstance, $this->fixture->getClasses()); |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * @covers phpDocumentor\Descriptor\FileDescriptor::setInterfaces |
||
172 | * @covers phpDocumentor\Descriptor\FileDescriptor::getInterfaces |
||
173 | */ |
||
174 | public function testSetAndGetInterfaces() |
||
175 | { |
||
176 | $this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getInterfaces()); |
||
177 | |||
178 | $mockInstance = m::mock('phpDocumentor\Descriptor\Collection'); |
||
179 | $mock = $mockInstance; |
||
180 | |||
181 | $this->fixture->setInterfaces($mock); |
||
182 | |||
183 | $this->assertSame($mockInstance, $this->fixture->getInterfaces()); |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * @covers phpDocumentor\Descriptor\FileDescriptor::setTraits |
||
188 | * @covers phpDocumentor\Descriptor\FileDescriptor::getTraits |
||
189 | */ |
||
190 | public function testSetAndGetTraits() |
||
191 | { |
||
192 | $this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getTraits()); |
||
193 | |||
194 | $mockInstance = m::mock('phpDocumentor\Descriptor\Collection'); |
||
195 | $mock = $mockInstance; |
||
196 | |||
197 | $this->fixture->setTraits($mock); |
||
198 | |||
199 | $this->assertSame($mockInstance, $this->fixture->getTraits()); |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * @covers phpDocumentor\Descriptor\FileDescriptor::setMarkers |
||
204 | * @covers phpDocumentor\Descriptor\FileDescriptor::getMarkers |
||
205 | */ |
||
206 | public function testSetAndGetMarkers() |
||
207 | { |
||
208 | $this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getMarkers()); |
||
209 | |||
210 | $mockInstance = m::mock('phpDocumentor\Descriptor\Collection'); |
||
211 | $mock = $mockInstance; |
||
212 | |||
213 | $this->fixture->setMarkers($mock); |
||
214 | |||
215 | $this->assertSame($mockInstance, $this->fixture->getMarkers()); |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * @covers phpDocumentor\Descriptor\FileDescriptor::__construct |
||
220 | * @covers phpDocumentor\Descriptor\FileDescriptor::getAllErrors |
||
221 | */ |
||
222 | public function testIfErrorsAreInitializedToAnEmptyCollectionOnInstantiation() |
||
223 | { |
||
224 | // construct |
||
225 | $this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getAllErrors()); |
||
226 | |||
227 | // default returns empty array |
||
228 | $this->assertObjectHasAttribute('items', $this->fixture->getAllErrors()); |
||
229 | |||
230 | $items = $this->fixture->getAllErrors()->items; |
||
0 ignored issues
–
show
|
|||
231 | $this->assertEmpty($items); |
||
232 | } |
||
233 | |||
234 | /** |
||
235 | * @covers phpDocumentor\Descriptor\FileDescriptor::__construct |
||
236 | * @covers phpDocumentor\Descriptor\FileDescriptor::getAllErrors |
||
237 | */ |
||
238 | public function testGetAllErrors() |
||
239 | { |
||
240 | /* |
||
241 | * constant |
||
242 | * function |
||
243 | * class |
||
244 | * property |
||
245 | * constant |
||
246 | * method |
||
247 | * interface |
||
248 | * constant |
||
249 | * method |
||
250 | * traits |
||
251 | * property |
||
252 | * method |
||
253 | */ |
||
254 | |||
255 | // setup error list |
||
256 | $errorGlobal = array('error-global'); |
||
257 | $errorClasses = array('error-class'); |
||
258 | $errorClassMethods = array('error-class-method'); |
||
259 | $errorClassConstants = array('error-class-constant'); |
||
260 | $errorClassProperties = array('error-class-property'); |
||
261 | $errorInterfaces = array('error-interface'); |
||
262 | $errorInterfacesConstants = array('error-interface-constant'); |
||
263 | $errorInterfacesMethods = array('error-interface-method'); |
||
264 | $errorTraits = array('error-traits'); |
||
265 | $errorTraitsProperties = array('error-traits-property'); |
||
266 | $errorTraitsMethods = array('error-traits-method'); |
||
267 | $errorFunctions = array('error-functions'); |
||
268 | |||
269 | // setup global check |
||
270 | $collection = new Collection($errorGlobal); |
||
271 | $this->fixture->setErrors($collection); |
||
272 | |||
273 | // setup class-property check |
||
274 | $mockClassProperties = m::mock('phpDocumentor\Descriptor\PropertyDescriptor'); |
||
275 | $mockClassProperties->shouldReceive('getErrors')->andReturn(new Collection($errorClassProperties)); |
||
276 | |||
277 | // setup class-constant check |
||
278 | $mockClassConstants = m::mock('phpDocumentor\Descriptor\ConstantDescriptor'); |
||
279 | $mockClassConstants->shouldReceive('getErrors')->andReturn(new Collection($errorClassConstants)); |
||
280 | |||
281 | // setup class-method check |
||
282 | $mockClassMethods = m::mock('phpDocumentor\Descriptor\MethodDescriptor'); |
||
283 | $mockClassMethods->shouldReceive('getErrors')->andReturn(new Collection($errorClassMethods)); |
||
284 | |||
285 | // setup class check |
||
286 | $mockClasses = m::mock('phpDocumentor\Descriptor\ClassDescriptor'); |
||
287 | $mockClasses->shouldReceive('getProperties')->andReturn(new Collection(array($mockClassProperties))); |
||
288 | $mockClasses->shouldReceive('getConstants')->andReturn(new Collection(array($mockClassConstants))); |
||
289 | $mockClasses->shouldReceive('getMethods')->andReturn(new Collection(array($mockClassMethods))); |
||
290 | $mockClasses->shouldReceive('getErrors')->andReturn(new Collection($errorClasses)); |
||
291 | |||
292 | $this->fixture->getClasses()->set('my-test-class', $mockClasses); |
||
293 | |||
294 | // setup interface-constant check |
||
295 | $mockInterfaceConstants = m::mock('phpDocumentor\Descriptor\ConstantDescriptor'); |
||
296 | $mockInterfaceConstants->shouldReceive('getErrors')->andReturn(new Collection($errorInterfacesConstants)); |
||
297 | |||
298 | // setup interface-method check |
||
299 | $mockInterfaceMethods = m::mock('phpDocumentor\Descriptor\MethodDescriptor'); |
||
300 | $mockInterfaceMethods->shouldReceive('getErrors')->andReturn(new Collection($errorInterfacesMethods)); |
||
301 | |||
302 | // setup interface check |
||
303 | $mockInterfaces = m::mock('phpDocumentor\Descriptor\ClassDescriptor'); |
||
304 | $mockInterfaces->shouldReceive('getProperties')->andReturn(array()); |
||
305 | $mockInterfaces->shouldReceive('getConstants')->andReturn(new Collection(array($mockInterfaceConstants))); |
||
306 | $mockInterfaces->shouldReceive('getMethods')->andReturn(new Collection(array($mockInterfaceMethods))); |
||
307 | $mockInterfaces->shouldReceive('getErrors')->andReturn(new Collection($errorInterfaces)); |
||
308 | |||
309 | $this->fixture->getClasses()->set('my-test-interface', $mockInterfaces); |
||
310 | |||
311 | // setup traits-constant check |
||
312 | $mockTraitsProperties = m::mock('phpDocumentor\Descriptor\ConstantDescriptor'); |
||
313 | $mockTraitsProperties->shouldReceive('getErrors')->andReturn(new Collection($errorTraitsProperties)); |
||
314 | |||
315 | // setup traits-method check |
||
316 | $mockTraitsMethods = m::mock('phpDocumentor\Descriptor\MethodDescriptor'); |
||
317 | $mockTraitsMethods->shouldReceive('getErrors')->andReturn(new Collection($errorTraitsMethods)); |
||
318 | |||
319 | // setup traits check |
||
320 | $mockTraits = m::mock('phpDocumentor\Descriptor\ClassDescriptor'); |
||
321 | $mockTraits->shouldReceive('getConstants')->andReturn(array()); |
||
322 | $mockTraits->shouldReceive('getProperties')->andReturn(new Collection(array($mockTraitsProperties))); |
||
323 | $mockTraits->shouldReceive('getMethods')->andReturn(new Collection(array($mockTraitsMethods))); |
||
324 | $mockTraits->shouldReceive('getErrors')->andReturn(new Collection($errorTraits)); |
||
325 | |||
326 | $this->fixture->getClasses()->set('my-test-traits', $mockTraits); |
||
327 | |||
328 | // setup functions check |
||
329 | $mockFunctions = m::mock('phpDocumentor\Descriptor\FunctionDescriptor'); |
||
330 | |||
331 | // create dummy instances of constants/methods |
||
332 | $mockFunctions->shouldReceive('getConstants')->andReturn(array()); |
||
333 | $mockFunctions->shouldReceive('getProperties')->andReturn(array()); |
||
334 | $mockFunctions->shouldReceive('getMethods')->andReturn(array()); |
||
335 | $mockFunctions->shouldReceive('getErrors')->andReturn(new Collection($errorFunctions)); |
||
336 | |||
337 | $this->fixture->getClasses()->set('my-test-function', $mockFunctions); |
||
338 | |||
339 | // final merge and check |
||
340 | $expectedErrors = array_merge( |
||
341 | $errorGlobal, |
||
342 | $errorClasses, |
||
343 | $errorInterfaces, |
||
344 | $errorTraits, |
||
345 | $errorFunctions, |
||
346 | $errorClassMethods, |
||
347 | $errorClassConstants, |
||
348 | $errorClassProperties, |
||
349 | $errorInterfacesMethods, |
||
350 | $errorInterfacesConstants, |
||
351 | $errorTraitsMethods, |
||
352 | $errorTraitsProperties |
||
353 | ); |
||
354 | |||
355 | $this->assertSame($expectedErrors, $this->fixture->getAllErrors()->getAll()); |
||
356 | } |
||
357 | } |
||
358 |
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.