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\Tag\AuthorDescriptor; |
||
16 | use \phpDocumentor\Descriptor\Tag\VarDescriptor; |
||
17 | use \phpDocumentor\Descriptor\Tag\VersionDescriptor; |
||
18 | use phpDocumentor\Reflection\Types\Array_; |
||
19 | |||
20 | /** |
||
21 | * Tests the functionality for the PropertyDescriptor class. |
||
22 | */ |
||
23 | class PropertyDescriptorTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
||
24 | { |
||
25 | /** @var PropertyDescriptor $fixture */ |
||
26 | protected $fixture; |
||
27 | |||
28 | /** |
||
29 | * Creates a new (empty) fixture object. |
||
30 | */ |
||
31 | protected function setUp() |
||
32 | { |
||
33 | $this->fixture = new PropertyDescriptor(); |
||
34 | $this->fixture->setName('property'); |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::isStatic |
||
39 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::setStatic |
||
40 | */ |
||
41 | public function testSettingAndGettingWhetherPropertyIsStatic() |
||
42 | { |
||
43 | $this->assertFalse($this->fixture->isStatic()); |
||
44 | |||
45 | $this->fixture->setStatic(true); |
||
46 | |||
47 | $this->assertTrue($this->fixture->isStatic()); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::getVisibility |
||
52 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::setVisibility |
||
53 | */ |
||
54 | public function testSettingAndGettingVisibility() |
||
55 | { |
||
56 | $this->assertEquals('public', $this->fixture->getVisibility()); |
||
57 | |||
58 | $this->fixture->setVisibility('private'); |
||
59 | |||
60 | $this->assertEquals('private', $this->fixture->getVisibility()); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::getType |
||
65 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::setType |
||
66 | */ |
||
67 | public function testSetAndGetTypes() |
||
68 | { |
||
69 | $this->assertEquals(null, $this->fixture->getType()); |
||
70 | $expected = new Array_(); |
||
71 | |||
72 | $this->fixture->setType($expected); |
||
73 | |||
74 | $this->assertSame($expected, $this->fixture->getType()); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::getType |
||
79 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::setType |
||
80 | */ |
||
81 | public function testSetAndGetTypesWhenVarIsPresent() |
||
82 | { |
||
83 | // Arrange |
||
84 | $typesCollection = new Array_(); |
||
85 | $varTagDescriptor = new VarDescriptor('var'); |
||
86 | $varTagDescriptor->setType($typesCollection); |
||
87 | $varCollection = new Collection([$varTagDescriptor]); |
||
88 | $this->fixture->getTags()->clear(); |
||
89 | $this->fixture->getTags()->set('var', $varCollection); |
||
90 | |||
91 | // Act |
||
92 | $result = $this->fixture->getType(); |
||
93 | |||
94 | // Assert |
||
95 | $this->assertSame($typesCollection, $result); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::getDefault |
||
100 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::setDefault |
||
101 | */ |
||
102 | public function testSetAndGetDefault() |
||
103 | { |
||
104 | $this->assertNull($this->fixture->getDefault()); |
||
105 | |||
106 | $this->fixture->setDefault('a'); |
||
107 | |||
108 | $this->assertSame('a', $this->fixture->getDefault()); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::getFile |
||
113 | */ |
||
114 | public function testRetrieveFileAssociatedWithAProperty() |
||
115 | { |
||
116 | // Arrange |
||
117 | $file = $this->whenFixtureIsRelatedToAClassWithFile(); |
||
118 | |||
119 | // Act |
||
120 | $result = $this->fixture->getFile(); |
||
121 | |||
122 | // Assert |
||
123 | $this->assertAttributeSame(null, 'fileDescriptor', $this->fixture); |
||
124 | $this->assertSame($file, $result); |
||
125 | } |
||
126 | |||
127 | /** |
||
128 | * @covers \phpDocumentor\Descriptor\DescriptorAbstract::getSummary |
||
129 | */ |
||
130 | public function testSummaryInheritsWhenNoneIsPresent() |
||
131 | { |
||
132 | // Arrange |
||
133 | $summary = 'This is a summary'; |
||
134 | $this->fixture->setSummary(null); |
||
135 | $parentProperty = $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
136 | $parentProperty->setSummary($summary); |
||
137 | |||
138 | // Act |
||
139 | $result = $this->fixture->getSummary(); |
||
140 | |||
141 | // Assert |
||
142 | $this->assertSame($summary, $result); |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * @covers \phpDocumentor\Descriptor\DescriptorAbstract::getDescription |
||
147 | */ |
||
148 | public function testDescriptionInheritsWhenNoneIsPresent() |
||
149 | { |
||
150 | // Arrange |
||
151 | $description = 'This is a description'; |
||
152 | $this->fixture->setDescription(null); |
||
153 | $parentProperty = $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
154 | $parentProperty->setDescription($description); |
||
155 | |||
156 | // Act |
||
157 | $result = $this->fixture->getDescription(); |
||
158 | |||
159 | // Assert |
||
160 | $this->assertSame($description, $result); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * @covers \phpDocumentor\Descriptor\DescriptorAbstract::getDescription |
||
165 | */ |
||
166 | public function testDescriptionInheritsWhenInheritDocIsPresent() |
||
167 | { |
||
168 | // Arrange |
||
169 | $description = 'This is a description'; |
||
170 | $this->fixture->setDescription('{@inheritDoc}'); |
||
171 | $parentProperty = $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
172 | $parentProperty->setDescription($description); |
||
173 | |||
174 | // Act |
||
175 | $result = $this->fixture->getDescription(); |
||
176 | |||
177 | // Assert |
||
178 | $this->assertSame($description, $result); |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * @covers \phpDocumentor\Descriptor\DescriptorAbstract::getDescription |
||
183 | */ |
||
184 | public function testDescriptionIsAugmentedWhenInheritDocInlineTagIsPresent() |
||
185 | { |
||
186 | // Arrange |
||
187 | $description = 'This is a description'; |
||
188 | $this->fixture->setDescription('Original description {@inheritDoc}'); |
||
189 | $parentProperty = $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
190 | $parentProperty->setDescription($description); |
||
191 | |||
192 | // Act |
||
193 | $result = $this->fixture->getDescription(); |
||
194 | |||
195 | // Assert |
||
196 | $this->assertSame('Original description ' . $description, $result); |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::getVar |
||
201 | */ |
||
202 | public function testVarTagsInheritWhenNoneArePresent() |
||
203 | { |
||
204 | // Arrange |
||
205 | $varTagDescriptor = new VarDescriptor('var'); |
||
206 | $varCollection = new Collection([$varTagDescriptor]); |
||
207 | $this->fixture->getTags()->clear(); |
||
208 | $parentProperty = $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
209 | $parentProperty->getTags()->set('var', $varCollection); |
||
210 | |||
211 | // Act |
||
212 | $result = $this->fixture->getVar(); |
||
213 | |||
214 | // Assert |
||
215 | $this->assertSame($varCollection, $result); |
||
216 | } |
||
217 | |||
218 | /** |
||
219 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::getVar |
||
220 | */ |
||
221 | public function testVarTagsWhenNoneArePresent() |
||
222 | { |
||
223 | $varCollection = new Collection(); |
||
224 | $result = $this->fixture->getVar(); |
||
225 | |||
226 | $this->assertEquals($varCollection, $result); |
||
227 | } |
||
228 | |||
229 | /** |
||
230 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::getAuthor |
||
231 | * @covers \phpDocumentor\Descriptor\DescriptorAbstract::getAuthor |
||
232 | */ |
||
233 | public function testAuthorTagsInheritWhenNoneArePresent() |
||
234 | { |
||
235 | // Arrange |
||
236 | $authorTagDescriptor = new AuthorDescriptor('author'); |
||
237 | $authorCollection = new Collection([$authorTagDescriptor]); |
||
238 | $this->fixture->getTags()->clear(); |
||
239 | $parentProperty = $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
240 | $parentProperty->getTags()->set('author', $authorCollection); |
||
241 | |||
242 | // Act |
||
243 | $result = $this->fixture->getAuthor(); |
||
244 | |||
245 | // Assert |
||
246 | $this->assertSame($authorCollection, $result); |
||
247 | } |
||
248 | |||
249 | /** |
||
250 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::getVersion |
||
251 | * @covers \phpDocumentor\Descriptor\DescriptorAbstract::getVersion |
||
252 | */ |
||
253 | public function testVersionTagsInheritWhenNoneArePresent() |
||
254 | { |
||
255 | // Arrange |
||
256 | $versionTagDescriptor = new VersionDescriptor('version'); |
||
257 | $versionCollection = new Collection([$versionTagDescriptor]); |
||
258 | $this->fixture->getTags()->clear(); |
||
259 | $parentProperty = $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
260 | $parentProperty->getTags()->set('version', $versionCollection); |
||
261 | |||
262 | // Act |
||
263 | $result = $this->fixture->getVersion(); |
||
264 | |||
265 | // Assert |
||
266 | $this->assertSame($versionCollection, $result); |
||
267 | } |
||
268 | |||
269 | /** |
||
270 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::getCopyright |
||
271 | * @covers \phpDocumentor\Descriptor\DescriptorAbstract::getCopyright |
||
272 | */ |
||
273 | public function testCopyrightTagsInheritWhenNoneArePresent() |
||
274 | { |
||
275 | // Arrange |
||
276 | $copyrightTagDescriptor = new TagDescriptor('copyright'); |
||
277 | $copyrightCollection = new Collection([$copyrightTagDescriptor]); |
||
278 | $this->fixture->getTags()->clear(); |
||
279 | $parentProperty = $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
280 | $parentProperty->getTags()->set('copyright', $copyrightCollection); |
||
281 | |||
282 | // Act |
||
283 | $result = $this->fixture->getCopyright(); |
||
284 | |||
285 | // Assert |
||
286 | $this->assertSame($copyrightCollection, $result); |
||
287 | } |
||
288 | |||
289 | /** |
||
290 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::setParent |
||
291 | */ |
||
292 | public function testFqsenHasDollarSignWhenParentIsSet() |
||
293 | { |
||
294 | $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
295 | $this->assertSame('::$property', $this->fixture->getFullyQualifiedStructuralElementName()); |
||
296 | } |
||
297 | |||
298 | /** |
||
299 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::setParent |
||
300 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::getParent |
||
301 | */ |
||
302 | public function testSettingAndGettingAParent() |
||
303 | { |
||
304 | $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
305 | $this->assertInstanceOf('\phpDocumentor\Descriptor\ClassDescriptor', $this->fixture->getParent()); |
||
306 | } |
||
307 | |||
308 | /** |
||
309 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::getInheritedElement |
||
310 | */ |
||
311 | public function testGettingAnInheritedElement() |
||
312 | { |
||
313 | $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
314 | |||
315 | $inheritedProperty = $this->fixture->getInheritedElement(); |
||
316 | |||
317 | $this->assertSame($inheritedProperty->getName(), $this->fixture->getName()); |
||
318 | } |
||
319 | |||
320 | /** |
||
321 | * @covers \phpDocumentor\Descriptor\PropertyDescriptor::getInheritedElement |
||
322 | */ |
||
323 | public function testGettingAnInheritedElementWhenThereIsNone() |
||
324 | { |
||
325 | $this->assertNull($this->fixture->getInheritedElement()); |
||
326 | } |
||
327 | |||
328 | /** |
||
329 | * Sets up mocks as such that the fixture has a file. |
||
330 | * |
||
331 | * @return m\MockInterface|FileDescriptor |
||
332 | */ |
||
333 | protected function whenFixtureIsDirectlyRelatedToAFile() |
||
334 | { |
||
335 | $file = m::mock('\phpDocumentor\Descriptor\FileDescriptor'); |
||
336 | $this->fixture->setFile($file); |
||
337 | return $file; |
||
338 | } |
||
339 | |||
340 | /** |
||
341 | * Sets up mocks as such that the fixture has a parent class, with a file. |
||
342 | * |
||
343 | * @return m\MockInterface|FileDescriptor |
||
344 | */ |
||
345 | protected function whenFixtureIsRelatedToAClassWithFile() |
||
346 | { |
||
347 | $file = m::mock('\phpDocumentor\Descriptor\FileDescriptor'); |
||
348 | $parent = m::mock('\phpDocumentor\Descriptor\ClassDescriptor'); |
||
349 | $parent->shouldReceive('getFile')->andReturn($file); |
||
0 ignored issues
–
show
|
|||
350 | $parent->shouldReceive('getFullyQualifiedStructuralElementName')->andReturn('Class1'); |
||
351 | $this->fixture->setParent($parent); |
||
352 | |||
353 | return $file; |
||
354 | } |
||
355 | |||
356 | /** |
||
357 | * @param string $name The name of the current property. |
||
358 | * |
||
359 | * @return PropertyDescriptor |
||
360 | */ |
||
361 | protected function whenFixtureHasPropertyInParentClassWithSameName($name) |
||
362 | { |
||
363 | $result = new PropertyDescriptor(); |
||
364 | $result->setName($name); |
||
365 | |||
366 | $parent = new ClassDescriptor(); |
||
367 | $parent->getProperties()->set($name, $result); |
||
368 | |||
369 | $class = new ClassDescriptor(); |
||
370 | $class->setParent($parent); |
||
371 | |||
372 | $this->fixture->setParent($class); |
||
373 | |||
374 | return $result; |
||
375 | } |
||
376 | } |
||
377 |
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: