|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* phpDocumentor |
|
4
|
|
|
* |
|
5
|
|
|
* PHP Version 5.3 |
|
6
|
|
|
* |
|
7
|
|
|
* @copyright 2010-2014 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 TraitDescriptor class. |
|
18
|
|
|
*/ |
|
19
|
|
|
class TraitDescriptorTest extends \PHPUnit_Framework_TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var TraitDescriptor $fixture */ |
|
22
|
|
|
protected $fixture; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Creates a new (empty) fixture object. |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function setUp() |
|
28
|
|
|
{ |
|
29
|
|
|
$this->fixture = new TraitDescriptor(); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Tests whether all collection objects are properly initialized. |
|
34
|
|
|
* |
|
35
|
|
|
* @covers phpDocumentor\Descriptor\TraitDescriptor::__construct |
|
36
|
|
|
*/ |
|
37
|
|
|
public function testInitialize() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->assertAttributeInstanceOf('phpDocumentor\Descriptor\Collection', 'properties', $this->fixture); |
|
40
|
|
|
$this->assertAttributeInstanceOf('phpDocumentor\Descriptor\Collection', 'methods', $this->fixture); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @covers phpDocumentor\Descriptor\TraitDescriptor::setProperties |
|
45
|
|
|
* @covers phpDocumentor\Descriptor\TraitDescriptor::getProperties |
|
46
|
|
|
*/ |
|
47
|
|
|
public function testSettingAndGettingProperties() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getProperties()); |
|
50
|
|
|
|
|
51
|
|
|
$mock = m::mock('phpDocumentor\Descriptor\Collection'); |
|
52
|
|
|
|
|
53
|
|
|
$this->fixture->setProperties($mock); |
|
54
|
|
|
|
|
55
|
|
|
$this->assertSame($mock, $this->fixture->getProperties()); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @covers phpDocumentor\Descriptor\TraitDescriptor::setMethods |
|
60
|
|
|
* @covers phpDocumentor\Descriptor\TraitDescriptor::getMethods |
|
61
|
|
|
*/ |
|
62
|
|
|
public function testSettingAndGettingMethods() |
|
63
|
|
|
{ |
|
64
|
|
|
$this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getMethods()); |
|
65
|
|
|
|
|
66
|
|
|
$mock = m::mock('phpDocumentor\Descriptor\Collection'); |
|
67
|
|
|
|
|
68
|
|
|
$this->fixture->setMethods($mock); |
|
69
|
|
|
|
|
70
|
|
|
$this->assertSame($mock, $this->fixture->getMethods()); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @covers phpDocumentor\Descriptor\TraitDescriptor::getInheritedMethods |
|
75
|
|
|
*/ |
|
76
|
|
|
public function testGetInheritedMethods() |
|
77
|
|
|
{ |
|
78
|
|
|
$this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getInheritedMethods()); |
|
79
|
|
|
|
|
80
|
|
|
$collection = $this->fixture->getInheritedMethods(); |
|
81
|
|
|
|
|
82
|
|
|
$this->assertEquals(0, $collection->count()); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* @covers phpDocumentor\Descriptor\TraitDescriptor::getMagicMethods |
|
87
|
|
|
*/ |
|
88
|
|
|
public function testMagicMethodsReturnsEmptyCollectionWhenNoTags() |
|
89
|
|
|
{ |
|
90
|
|
|
$this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getMagicMethods()); |
|
91
|
|
|
|
|
92
|
|
|
$collection = $this->fixture->getMagicMethods(); |
|
93
|
|
|
|
|
94
|
|
|
$this->assertEquals(0, $collection->count()); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @covers phpDocumentor\Descriptor\TraitDescriptor::getMagicMethods |
|
99
|
|
|
* @dataProvider provideMagicMethodProperties |
|
100
|
|
|
* @param bool $isStatic |
|
101
|
|
|
*/ |
|
102
|
|
|
public function testMagicMethodsReturnsExpectedCollectionWithTags($isStatic) |
|
103
|
|
|
{ |
|
104
|
|
|
$mockMethodDescriptor = m::mock('phpDocumentor\Descriptor\Tag\MethodDescriptor'); |
|
105
|
|
|
$mockMethodDescriptor->shouldReceive('getMethodName')->andReturn('Sample'); |
|
106
|
|
|
$mockMethodDescriptor->shouldReceive('isStatic')->andReturn($isStatic); |
|
107
|
|
|
$mockMethodDescriptor->shouldReceive('getDescription')->andReturn('Sample description'); |
|
108
|
|
|
|
|
109
|
|
|
$methodCollection = new Collection(array($mockMethodDescriptor)); |
|
110
|
|
|
$this->fixture->getTags()->set('method', $methodCollection); |
|
111
|
|
|
|
|
112
|
|
|
$magicMethodsCollection = $this->fixture->getMagicMethods(); |
|
113
|
|
|
$this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $magicMethodsCollection); |
|
114
|
|
|
$this->assertSame(1, $magicMethodsCollection->count()); |
|
115
|
|
|
$this->assertSame('Sample', $magicMethodsCollection[0]->getName()); |
|
116
|
|
|
$this->assertSame('Sample description', $magicMethodsCollection[0]->getDescription()); |
|
117
|
|
|
$this->assertSame($isStatic, $magicMethodsCollection[0]->isStatic()); |
|
118
|
|
|
$this->assertSame($this->fixture, $magicMethodsCollection[0]->getParent()); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Provider to test different properties for a trait magic method |
|
123
|
|
|
* (provides isStatic) |
|
124
|
|
|
* @return bool[][] |
|
125
|
|
|
*/ |
|
126
|
|
|
public function provideMagicMethodProperties() |
|
127
|
|
|
{ |
|
128
|
|
|
return array( |
|
129
|
|
|
// Instance magic method (default) |
|
130
|
|
|
array(false), |
|
131
|
|
|
// Static magic method |
|
132
|
|
|
array(true), |
|
133
|
|
|
); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* @covers phpDocumentor\Descriptor\TraitDescriptor::getInheritedProperties |
|
138
|
|
|
*/ |
|
139
|
|
|
public function testGetInheritedProperties() |
|
140
|
|
|
{ |
|
141
|
|
|
$this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getInheritedProperties()); |
|
142
|
|
|
|
|
143
|
|
|
$collection = $this->fixture->getInheritedProperties(); |
|
144
|
|
|
|
|
145
|
|
|
$this->assertEquals(0, $collection->count()); |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @covers phpDocumentor\Descriptor\TraitDescriptor::getMagicProperties |
|
150
|
|
|
*/ |
|
151
|
|
|
public function testMagicPropertiesReturnsEmptyCollectionWhenNoTags() |
|
152
|
|
|
{ |
|
153
|
|
|
$this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getMagicProperties()); |
|
154
|
|
|
|
|
155
|
|
|
$collection = $this->fixture->getMagicProperties(); |
|
156
|
|
|
|
|
157
|
|
|
$this->assertEquals(0, $collection->count()); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* @covers phpDocumentor\Descriptor\TraitDescriptor::getMagicProperties |
|
162
|
|
|
*/ |
|
163
|
|
|
public function testMagicPropertiesReturnsExpectedCollectionWithTags() |
|
164
|
|
|
{ |
|
165
|
|
|
$mockTagPropertyDescriptor = m::mock('phpDocumentor\Descriptor\Tag\PropertyDescriptor'); |
|
166
|
|
|
$mockTagPropertyDescriptor->shouldReceive('getVariableName')->andReturn('Sample'); |
|
167
|
|
|
$mockTagPropertyDescriptor->shouldReceive('getDescription')->andReturn('Sample description'); |
|
168
|
|
|
$mockTagPropertyDescriptor->shouldReceive('getTypes')->andReturn(new Collection); |
|
169
|
|
|
|
|
170
|
|
|
$propertyCollection = new Collection(array($mockTagPropertyDescriptor)); |
|
171
|
|
|
$this->fixture->getTags()->set('property', $propertyCollection); |
|
172
|
|
|
|
|
173
|
|
|
$this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getMagicProperties()); |
|
174
|
|
|
|
|
175
|
|
|
$magicPropertiesCollection = $this->fixture->getMagicProperties(); |
|
176
|
|
|
$this->assertSame(1, $magicPropertiesCollection->count()); |
|
177
|
|
|
$this->assertSame('Sample', $magicPropertiesCollection[0]->getName()); |
|
178
|
|
|
$this->assertSame('Sample description', $magicPropertiesCollection[0]->getDescription()); |
|
179
|
|
|
$this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $magicPropertiesCollection[0]->getTypes()); |
|
180
|
|
|
$this->assertSame(0, $magicPropertiesCollection[0]->getTypes()->count()); |
|
181
|
|
|
$this->assertSame($this->fixture, $magicPropertiesCollection[0]->getParent()); |
|
182
|
|
|
} |
|
183
|
|
|
|
|
184
|
|
|
/** |
|
185
|
|
|
* @covers phpDocumentor\Descriptor\TraitDescriptor::setPackage |
|
186
|
|
|
*/ |
|
187
|
|
|
public function testSettingAndGettingPackage() |
|
188
|
|
|
{ |
|
189
|
|
|
$package = new \phpDocumentor\Descriptor\PackageDescriptor(); |
|
190
|
|
|
$mockPropertyDescriptor = m::mock('phpDocumentor\Descriptor\PropertyDescriptor'); |
|
191
|
|
|
$mockPropertyDescriptor->shouldReceive('setPackage')->with($package); |
|
192
|
|
|
|
|
193
|
|
|
$mockMethodDescriptor = m::mock('phpDocumentor\Descriptor\MethodDescriptor'); |
|
194
|
|
|
$mockMethodDescriptor->shouldReceive('setPackage')->with($package); |
|
195
|
|
|
|
|
196
|
|
|
$propertyCollection = new Collection(array($mockPropertyDescriptor)); |
|
197
|
|
|
$methodCollection = new Collection(array($mockMethodDescriptor)); |
|
198
|
|
|
$this->fixture->setProperties($propertyCollection); |
|
199
|
|
|
$this->fixture->setMethods($methodCollection); |
|
200
|
|
|
|
|
201
|
|
|
$this->fixture->setPackage($package); |
|
202
|
|
|
|
|
203
|
|
|
$this->assertSame($package, $this->fixture->getPackage()); |
|
204
|
|
|
} |
|
205
|
|
|
|
|
206
|
|
|
/** |
|
207
|
|
|
* @covers phpDocumentor\Descriptor\TraitDescriptor::getUsedTraits |
|
208
|
|
|
* @covers phpDocumentor\Descriptor\TraitDescriptor::setUsedTraits |
|
209
|
|
|
*/ |
|
210
|
|
|
public function testSettingAndGettingUsedTraits() |
|
211
|
|
|
{ |
|
212
|
|
|
$this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getUsedTraits()); |
|
213
|
|
|
|
|
214
|
|
|
$usedTraitsCollection = new Collection; |
|
215
|
|
|
$this->fixture->setUsedTraits($usedTraitsCollection); |
|
216
|
|
|
|
|
217
|
|
|
$this->assertSame($usedTraitsCollection, $this->fixture->getUsedTraits()); |
|
218
|
|
|
} |
|
219
|
|
|
} |
|
220
|
|
|
|