These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /** |
||
6 | * This file is part of phpDocumentor. |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | * |
||
11 | * @link https://phpdoc.org |
||
12 | */ |
||
13 | |||
14 | namespace phpDocumentor\Descriptor; |
||
15 | |||
16 | use Mockery as m; |
||
17 | use Mockery\Adapter\Phpunit\MockeryTestCase; |
||
18 | use phpDocumentor\Descriptor\Tag\AuthorDescriptor; |
||
19 | use phpDocumentor\Descriptor\Tag\VarDescriptor; |
||
20 | use phpDocumentor\Descriptor\Tag\VersionDescriptor; |
||
21 | use phpDocumentor\Reflection\Fqsen; |
||
22 | use phpDocumentor\Reflection\Types\Array_; |
||
23 | |||
24 | /** |
||
25 | * Tests the functionality for the PropertyDescriptor class. |
||
26 | * |
||
27 | * @coversDefaultClass \phpDocumentor\Descriptor\PropertyDescriptor |
||
28 | */ |
||
29 | final class PropertyDescriptorTest extends MockeryTestCase |
||
30 | { |
||
31 | /** @var PropertyDescriptor $fixture */ |
||
32 | protected $fixture; |
||
33 | |||
34 | /** |
||
35 | * Creates a new (empty) fixture object. |
||
36 | */ |
||
37 | protected function setUp() : void |
||
38 | { |
||
39 | $this->fixture = new PropertyDescriptor(); |
||
40 | $this->fixture->setName('property'); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @covers ::isStatic |
||
45 | * @covers ::setStatic |
||
46 | */ |
||
47 | public function testSettingAndGettingWhetherPropertyIsStatic() : void |
||
48 | { |
||
49 | $this->assertFalse($this->fixture->isStatic()); |
||
50 | |||
51 | $this->fixture->setStatic(true); |
||
52 | |||
53 | $this->assertTrue($this->fixture->isStatic()); |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * @covers ::getVisibility |
||
58 | * @covers ::setVisibility |
||
59 | */ |
||
60 | public function testSettingAndGettingVisibility() : void |
||
61 | { |
||
62 | $this->assertEquals('public', $this->fixture->getVisibility()); |
||
63 | |||
64 | $this->fixture->setVisibility('private'); |
||
65 | |||
66 | $this->assertEquals('private', $this->fixture->getVisibility()); |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @covers ::getType |
||
71 | * @covers ::setType |
||
72 | */ |
||
73 | public function testSetAndGetTypes() : void |
||
74 | { |
||
75 | $this->assertEquals(null, $this->fixture->getType()); |
||
76 | $expected = new Array_(); |
||
77 | |||
78 | $this->fixture->setType($expected); |
||
79 | |||
80 | $this->assertSame($expected, $this->fixture->getType()); |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @covers ::getTypes |
||
85 | */ |
||
86 | public function testGetTypesCollection() : void |
||
87 | { |
||
88 | $this->assertSame([], $this->fixture->getTypes()); |
||
89 | $expected = new Array_(); |
||
90 | |||
91 | $this->fixture->setType($expected); |
||
92 | |||
93 | $this->assertSame(['array'], $this->fixture->getTypes()); |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * @covers ::getType |
||
98 | * @covers ::setType |
||
99 | */ |
||
100 | public function testSetAndGetTypesWhenVarIsPresent() : void |
||
101 | { |
||
102 | // Arrange |
||
103 | $typesCollection = new Array_(); |
||
104 | $varTagDescriptor = new VarDescriptor('var'); |
||
105 | $varTagDescriptor->setType($typesCollection); |
||
106 | $varCollection = new Collection([$varTagDescriptor]); |
||
107 | $this->fixture->getTags()->clear(); |
||
108 | $this->fixture->getTags()->set('var', $varCollection); |
||
109 | |||
110 | // Act |
||
111 | $result = $this->fixture->getType(); |
||
112 | |||
113 | // Assert |
||
114 | $this->assertSame($typesCollection, $result); |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * @covers ::getDefault |
||
119 | * @covers ::setDefault |
||
120 | */ |
||
121 | public function testSetAndGetDefault() : void |
||
122 | { |
||
123 | $this->assertNull($this->fixture->getDefault()); |
||
124 | |||
125 | $this->fixture->setDefault('a'); |
||
126 | |||
127 | $this->assertSame('a', $this->fixture->getDefault()); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * @covers ::getFile |
||
132 | */ |
||
133 | public function testRetrieveFileAssociatedWithAProperty() : void |
||
134 | { |
||
135 | // Arrange |
||
136 | $file = $this->whenFixtureIsRelatedToAClassWithFile(); |
||
137 | |||
138 | // Act |
||
139 | $result = $this->fixture->getFile(); |
||
140 | |||
141 | // Assert |
||
142 | $this->assertSame($file, $result); |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * @covers ::getSummary |
||
147 | */ |
||
148 | public function testSummaryInheritsWhenNoneIsPresent() : void |
||
149 | { |
||
150 | // Arrange |
||
151 | $summary = 'This is a summary'; |
||
152 | $this->fixture->setSummary(''); |
||
153 | $parentProperty = $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
154 | $parentProperty->setSummary($summary); |
||
155 | |||
156 | // Act |
||
157 | $result = $this->fixture->getSummary(); |
||
158 | |||
159 | // Assert |
||
160 | $this->assertSame($summary, $result); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * @covers ::getDescription |
||
165 | */ |
||
166 | public function testDescriptionInheritsWhenNoneIsPresent() : void |
||
167 | { |
||
168 | // Arrange |
||
169 | $description = 'This is a description'; |
||
170 | $this->fixture->setDescription(''); |
||
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 ::getDescription() |
||
183 | */ |
||
184 | public function testDescriptionInheritsWhenInheritDocIsPresent() : void |
||
185 | { |
||
186 | // Arrange |
||
187 | $description = 'This is a description'; |
||
188 | $this->fixture->setDescription('{@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($description, $result); |
||
197 | } |
||
198 | |||
199 | /** |
||
200 | * @covers ::getDescription() |
||
201 | */ |
||
202 | public function testDescriptionIsAugmentedWhenInheritDocInlineTagIsPresent() : void |
||
203 | { |
||
204 | // Arrange |
||
205 | $description = 'This is a description'; |
||
206 | $this->fixture->setDescription('Original description {@inheritDoc}'); |
||
207 | $parentProperty = $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
208 | $parentProperty->setDescription($description); |
||
209 | |||
210 | // Act |
||
211 | $result = $this->fixture->getDescription(); |
||
212 | |||
213 | // Assert |
||
214 | $this->assertSame('Original description ' . $description, $result); |
||
215 | } |
||
216 | |||
217 | /** |
||
218 | * @covers ::getVar |
||
219 | */ |
||
220 | public function testVarTagsInheritWhenNoneArePresent() : void |
||
221 | { |
||
222 | // Arrange |
||
223 | $varTagDescriptor = new VarDescriptor('var'); |
||
224 | $varCollection = new Collection([$varTagDescriptor]); |
||
225 | $this->fixture->getTags()->clear(); |
||
226 | $parentProperty = $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
227 | $parentProperty->getTags()->set('var', $varCollection); |
||
228 | |||
229 | // Act |
||
230 | $result = $this->fixture->getVar(); |
||
231 | |||
232 | // Assert |
||
233 | $this->assertSame($varCollection, $result); |
||
234 | } |
||
235 | |||
236 | /** |
||
237 | * @covers ::getVar |
||
238 | */ |
||
239 | public function testVarTagsWhenNoneArePresent() : void |
||
240 | { |
||
241 | $varCollection = new Collection(); |
||
242 | $result = $this->fixture->getVar(); |
||
243 | |||
244 | $this->assertEquals($varCollection, $result); |
||
245 | } |
||
246 | |||
247 | /** |
||
248 | * @covers ::getAuthor |
||
249 | * @covers \phpDocumentor\Descriptor\DescriptorAbstract::getAuthor |
||
250 | */ |
||
251 | public function testAuthorTagsInheritWhenNoneArePresent() : void |
||
252 | { |
||
253 | // Arrange |
||
254 | $authorTagDescriptor = new AuthorDescriptor('author'); |
||
255 | $authorCollection = new Collection([$authorTagDescriptor]); |
||
256 | $this->fixture->getTags()->clear(); |
||
257 | $parentProperty = $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
258 | $parentProperty->getTags()->set('author', $authorCollection); |
||
259 | |||
260 | // Act |
||
261 | $result = $this->fixture->getAuthor(); |
||
262 | |||
263 | // Assert |
||
264 | $this->assertSame($authorCollection, $result); |
||
265 | } |
||
266 | |||
267 | /** |
||
268 | * @covers ::getVersion |
||
269 | * @covers \phpDocumentor\Descriptor\DescriptorAbstract::getVersion |
||
270 | */ |
||
271 | public function testVersionTagsInheritWhenNoneArePresent() : void |
||
272 | { |
||
273 | // Arrange |
||
274 | $versionTagDescriptor = new VersionDescriptor('version'); |
||
275 | $versionCollection = new Collection([$versionTagDescriptor]); |
||
276 | $this->fixture->getTags()->clear(); |
||
277 | $parentProperty = $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
278 | $parentProperty->getTags()->set('version', $versionCollection); |
||
279 | |||
280 | // Act |
||
281 | $result = $this->fixture->getVersion(); |
||
282 | |||
283 | // Assert |
||
284 | $this->assertSame($versionCollection, $result); |
||
285 | } |
||
286 | |||
287 | /** |
||
288 | * @covers ::getCopyright |
||
289 | * @covers \phpDocumentor\Descriptor\DescriptorAbstract::getCopyright |
||
290 | */ |
||
291 | public function testCopyrightTagsInheritWhenNoneArePresent() : void |
||
292 | { |
||
293 | // Arrange |
||
294 | $copyrightTagDescriptor = new TagDescriptor('copyright'); |
||
295 | $copyrightCollection = new Collection([$copyrightTagDescriptor]); |
||
296 | $this->fixture->getTags()->clear(); |
||
297 | $parentProperty = $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
298 | $parentProperty->getTags()->set('copyright', $copyrightCollection); |
||
299 | |||
300 | // Act |
||
301 | $result = $this->fixture->getCopyright(); |
||
302 | |||
303 | // Assert |
||
304 | $this->assertSame($copyrightCollection, $result); |
||
305 | } |
||
306 | |||
307 | /** |
||
308 | * @covers ::setParent |
||
309 | */ |
||
310 | public function testFqsenHasDollarSignWhenParentIsSet() : void |
||
311 | { |
||
312 | $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
313 | $this->assertSame( |
||
314 | '\MyOther\Class::$property', |
||
315 | (string) $this->fixture->getFullyQualifiedStructuralElementName() |
||
316 | ); |
||
317 | } |
||
318 | |||
319 | /** |
||
320 | * @covers ::setParent |
||
321 | * @covers ::getParent |
||
322 | */ |
||
323 | public function testSettingAndGettingAParent() : void |
||
324 | { |
||
325 | $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
326 | $this->assertInstanceOf(ClassDescriptor::class, $this->fixture->getParent()); |
||
327 | } |
||
328 | |||
329 | /** |
||
330 | * @covers ::getInheritedElement |
||
331 | */ |
||
332 | public function testGettingAnInheritedElement() : void |
||
333 | { |
||
334 | $this->whenFixtureHasPropertyInParentClassWithSameName($this->fixture->getName()); |
||
335 | |||
336 | $inheritedProperty = $this->fixture->getInheritedElement(); |
||
337 | |||
338 | $this->assertSame($inheritedProperty->getName(), $this->fixture->getName()); |
||
339 | } |
||
340 | |||
341 | /** |
||
342 | * @covers ::getInheritedElement |
||
343 | */ |
||
344 | public function testGettingAnInheritedElementWhenThereIsNone() : void |
||
345 | { |
||
346 | $this->assertNull($this->fixture->getInheritedElement()); |
||
347 | } |
||
348 | |||
349 | /** |
||
350 | * Sets up mocks as such that the fixture has a file. |
||
351 | * |
||
352 | * @return m\MockInterface|FileDescriptor |
||
353 | */ |
||
354 | protected function whenFixtureIsDirectlyRelatedToAFile() |
||
355 | { |
||
356 | $file = m::mock(FileDescriptor::class); |
||
357 | $this->fixture->setFile($file); |
||
0 ignored issues
–
show
|
|||
358 | |||
359 | return $file; |
||
360 | } |
||
361 | |||
362 | /** |
||
363 | * Sets up mocks as such that the fixture has a parent class, with a file. |
||
364 | * |
||
365 | * @return m\MockInterface|FileDescriptor |
||
366 | */ |
||
367 | protected function whenFixtureIsRelatedToAClassWithFile() |
||
368 | { |
||
369 | $file = m::mock(FileDescriptor::class); |
||
370 | $parent = m::mock(ClassDescriptor::class); |
||
371 | $parent->shouldReceive('getFile')->andReturn($file); |
||
372 | $parent->shouldReceive('getFullyQualifiedStructuralElementName')->andReturn(new Fqsen('\Class1')); |
||
373 | $this->fixture->setParent($parent); |
||
374 | |||
375 | return $file; |
||
376 | } |
||
377 | |||
378 | /** |
||
379 | * @param string $name The name of the current property. |
||
380 | */ |
||
381 | protected function whenFixtureHasPropertyInParentClassWithSameName(string $name) : PropertyDescriptor |
||
382 | { |
||
383 | $parent = new ClassDescriptor(); |
||
384 | $parent->setFullyQualifiedStructuralElementName(new Fqsen('\MyClass')); |
||
385 | |||
386 | $result = new PropertyDescriptor(); |
||
387 | $result->setName($name); |
||
388 | $result->setParent($parent); |
||
389 | |||
390 | $parent->getProperties()->set($name, $result); |
||
391 | |||
392 | $class = new ClassDescriptor(); |
||
393 | $class->setFullyQualifiedStructuralElementName(new Fqsen('\MyOther\Class')); |
||
394 | $class->setParent($parent); |
||
395 | |||
396 | $this->fixture->setParent($class); |
||
397 | |||
398 | return $result; |
||
399 | } |
||
400 | } |
||
401 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: