Completed
Push — develop ( 8eb671...133594 )
by Mike
19:30 queued 09:24
created

Descriptor/InterfaceDescriptorTest.php (1 issue)

mismatching argument types.

Documentation Minor

Upgrade to new PHP Analysis Engine

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\VersionDescriptor;
17
18
/**
19
 * Tests the functionality for the InterfaceDescriptor class.
20
 */
21
class InterfaceDescriptorTest extends \Mockery\Adapter\Phpunit\MockeryTestCase
22
{
23
    /** @var InterfaceDescriptor $fixture */
24
    protected $fixture;
25
26
    /**
27
     * Creates a new (empty) fixture object.
28
     */
29
    protected function setUp()
30
    {
31
        $this->fixture = new InterfaceDescriptor();
32
    }
33
34
    /**
35
     * Tests whether all collection objects are properly initialized.
36
     *
37
     * @covers phpDocumentor\Descriptor\InterfaceDescriptor::__construct
38
     */
39
    public function testInitialize()
40
    {
41
        $this->assertAttributeInstanceOf('phpDocumentor\Descriptor\Collection', 'parents', $this->fixture);
42
        $this->assertAttributeInstanceOf('phpDocumentor\Descriptor\Collection', 'constants', $this->fixture);
43
        $this->assertAttributeInstanceOf('phpDocumentor\Descriptor\Collection', 'methods', $this->fixture);
44
    }
45
46
    /**
47
     * @covers phpDocumentor\Descriptor\InterfaceDescriptor::setParent
48
     * @covers phpDocumentor\Descriptor\InterfaceDescriptor::getParent
49
     */
50
    public function testSettingAndGettingParentInterfaces()
51
    {
52
        $this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getParent());
53
54
        $mock = m::mock('phpDocumentor\Descriptor\Collection');
55
56
        $this->fixture->setParent($mock);
57
58
        $this->assertSame($mock, $this->fixture->getParent());
59
    }
60
61
    /**
62
     * @covers phpDocumentor\Descriptor\InterfaceDescriptor::setConstants
63
     * @covers phpDocumentor\Descriptor\InterfaceDescriptor::getConstants
64
     */
65
    public function testSettingAndGettingConstants()
66
    {
67
        $this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getConstants());
68
69
        $mock = m::mock('phpDocumentor\Descriptor\Collection');
70
71
        $this->fixture->setConstants($mock);
72
73
        $this->assertSame($mock, $this->fixture->getConstants());
74
    }
75
76
    /**
77
     * @covers phpDocumentor\Descriptor\InterfaceDescriptor::setMethods
78
     * @covers phpDocumentor\Descriptor\InterfaceDescriptor::getMethods
79
     */
80
    public function testSettingAndGettingMethods()
81
    {
82
        $this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $this->fixture->getMethods());
83
84
        $mock = m::mock('phpDocumentor\Descriptor\Collection');
85
86
        $this->fixture->setMethods($mock);
87
88
        $this->assertSame($mock, $this->fixture->getMethods());
89
    }
90
91
    /**
92
     * @covers phpDocumentor\Descriptor\InterfaceDescriptor::getInheritedConstants
93
     */
94
    public function testGetInheritedConstantsNoParent()
95
    {
96
        $descriptor = new InterfaceDescriptor();
97
        $this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $descriptor->getInheritedConstants());
98
99
        $descriptor->setParent(new \stdClass());
0 ignored issues
show
new \stdClass() is of type object<stdClass>, but the function expects a object<phpDocumentor\Descriptor\Collection>.

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:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
100
        $this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $descriptor->getInheritedConstants());
101
    }
102
103
    /**
104
     * @covers phpDocumentor\Descriptor\DescriptorAbstract::getSummary
105
     */
106
    public function testSummaryInheritsWhenNoneIsPresent()
107
    {
108
        // Arrange
109
        $summary = 'This is a summary';
110
        $this->fixture->setSummary(null);
111
        $parentInterface = $this->whenFixtureHasParentInterface();
112
        $parentInterface->setSummary($summary);
113
114
        // Act
115
        $result = $this->fixture->getSummary();
116
117
        // Assert
118
        $this->assertSame($summary, $result);
119
    }
120
121
    /**
122
     * @covers phpDocumentor\Descriptor\DescriptorAbstract::getDescription
123
     */
124
    public function testDescriptionInheritsWhenNoneIsPresent()
125
    {
126
        // Arrange
127
        $description = 'This is a description';
128
        $this->fixture->setDescription(null);
129
        $parentInterface = $this->whenFixtureHasParentInterface();
130
        $parentInterface->setDescription($description);
131
132
        // Act
133
        $result = $this->fixture->getDescription();
134
135
        // Assert
136
        $this->assertSame($description, $result);
137
    }
138
139
    /**
140
     * @covers phpDocumentor\Descriptor\DescriptorAbstract::getAuthor
141
     */
142
    public function testAuthorTagsInheritWhenNoneArePresent()
143
    {
144
        // Arrange
145
        $authorTagDescriptor = new AuthorDescriptor('author');
146
        $authorCollection = new Collection([$authorTagDescriptor]);
147
        $this->fixture->getTags()->clear();
148
        $parentProperty = $this->whenFixtureHasParentInterface();
149
        $parentProperty->getTags()->set('author', $authorCollection);
150
151
        // Act
152
        $result = $this->fixture->getAuthor();
153
154
        // Assert
155
        $this->assertSame($authorCollection, $result);
156
    }
157
158
    /**
159
     * @covers phpDocumentor\Descriptor\DescriptorAbstract::getCopyright
160
     */
161
    public function testCopyrightTagsInheritWhenNoneArePresent()
162
    {
163
        // Arrange
164
        $copyrightTagDescriptor = new TagDescriptor('copyright');
165
        $copyrightCollection = new Collection([$copyrightTagDescriptor]);
166
        $this->fixture->getTags()->clear();
167
        $parentProperty = $this->whenFixtureHasParentInterface();
168
        $parentProperty->getTags()->set('copyright', $copyrightCollection);
169
170
        // Act
171
        $result = $this->fixture->getCopyright();
172
173
        // Assert
174
        $this->assertSame($copyrightCollection, $result);
175
    }
176
177
    /**
178
     * @covers phpDocumentor\Descriptor\DescriptorAbstract::getVersion
179
     */
180
    public function testVersionTagsInheritWhenNoneArePresent()
181
    {
182
        // Arrange
183
        $versionTagDescriptor = new VersionDescriptor('version');
184
        $versionCollection = new Collection([$versionTagDescriptor]);
185
        $this->fixture->getTags()->clear();
186
        $parentProperty = $this->whenFixtureHasParentInterface();
187
        $parentProperty->getTags()->set('version', $versionCollection);
188
189
        // Act
190
        $result = $this->fixture->getVersion();
191
192
        // Assert
193
        $this->assertSame($versionCollection, $result);
194
    }
195
196
    /**
197
     * @covers phpDocumentor\Descriptor\InterfaceDescriptor::getInheritedConstants
198
     */
199
    public function testGetInheritedConstantsWithClassDescriptorParent()
200
    {
201
        $parentDescriptor = new ConstantDescriptor();
202
        $parentDescriptor->setName('parent');
203
        $parentDescriptorCollection = new Collection();
204
        $parentDescriptorCollection->add($parentDescriptor);
205
        $parent = new InterfaceDescriptor();
206
        $parent->setConstants($parentDescriptorCollection);
207
208
        $grandParentDescriptor = new ConstantDescriptor();
209
        $grandParentDescriptor->setName('grandparent');
210
        $grandParentDescriptorCollection = new Collection();
211
        $grandParentDescriptorCollection->add($grandParentDescriptor);
212
        $grandParent = new InterfaceDescriptor();
213
        $grandParent->setConstants($grandParentDescriptorCollection);
214
215
        $grandParentCollection = new Collection();
216
        $grandParentCollection->add($grandParent);
217
        $parent->setParent($grandParentCollection);
218
219
        $parentCollection = new Collection();
220
        $parentCollection->add($parent);
221
222
        $this->fixture->setParent($parentCollection);
223
        $result = $this->fixture->getInheritedConstants();
224
225
        $this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $result);
226
227
        $this->assertSame([$parentDescriptor, $grandParentDescriptor], $result->getAll());
228
    }
229
230
    /**
231
     * @covers phpDocumentor\Descriptor\InterfaceDescriptor::getInheritedMethods
232
     */
233
    public function testRetrievingInheritedMethodsReturnsEmptyCollectionWithoutParent()
234
    {
235
        $inheritedMethods = $this->fixture->getInheritedMethods();
236
        $this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $inheritedMethods);
237
        $this->assertCount(0, $inheritedMethods);
238
    }
239
240
    /**
241
     * @covers phpDocumentor\Descriptor\InterfaceDescriptor::getInheritedMethods
242
     */
243
    public function testRetrievingInheritedMethodsReturnsCollectionWithParent()
244
    {
245
        $parentDescriptor = new MethodDescriptor();
246
        $parentDescriptor->setName('parent');
247
        $parentDescriptorCollection = new Collection();
248
        $parentDescriptorCollection->add($parentDescriptor);
249
        $parent = new InterfaceDescriptor();
250
        $parent->setMethods($parentDescriptorCollection);
251
        $parentCollection = new Collection();
252
        $parentCollection->add($parent);
253
254
        $grandParentDescriptor = new MethodDescriptor();
255
        $grandParentDescriptor->setName('grandparent');
256
        $grandParentDescriptorCollection = new Collection();
257
        $grandParentDescriptorCollection->add($grandParentDescriptor);
258
        $grandParent = new InterfaceDescriptor();
259
        $grandParent->setMethods($grandParentDescriptorCollection);
260
        $grandParentCollection = new Collection();
261
        $grandParentCollection->add($grandParent);
262
263
        $parent->setParent($grandParentCollection);
264
265
        $this->fixture->setParent($parentCollection);
266
        $result = $this->fixture->getInheritedMethods();
267
268
        $this->assertInstanceOf('phpDocumentor\Descriptor\Collection', $result);
269
270
        $this->assertSame([$parentDescriptor, $grandParentDescriptor], $result->getAll());
271
    }
272
273
    /**
274
     * @return InterfaceDescriptor
275
     */
276
    protected function whenFixtureHasParentInterface()
277
    {
278
        $interface = new InterfaceDescriptor();
279
        $this->fixture->getParent()->set('IA', $interface);
280
281
        return $interface;
282
    }
283
}
284