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