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 | |||
16 | /** |
||
17 | * Tests the functionality for the DescriptorAbstract class. |
||
18 | */ |
||
19 | class DescriptorAbstractTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
||
20 | { |
||
21 | /** @var DescriptorAbstract $fixture */ |
||
22 | protected $fixture; |
||
23 | |||
24 | /** |
||
25 | * Creates a new mocked fixture object. |
||
26 | */ |
||
27 | protected function setUp() |
||
28 | { |
||
29 | $this->fixture = m::mock('phpDocumentor\Descriptor\DescriptorAbstract'); |
||
30 | $this->fixture->shouldDeferMissing(); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::__construct |
||
35 | */ |
||
36 | public function testInitialize() |
||
37 | { |
||
38 | /** @var m\MockInterface|DescriptorAbstract */ |
||
39 | $mock = $this->getMockBuilder('phpDocumentor\Descriptor\DescriptorAbstract') |
||
40 | ->disableOriginalConstructor() |
||
41 | ->getMock(); |
||
42 | $mock->expects($this->once())->method('setTags')->with(new Collection()); |
||
43 | $mock->expects($this->once())->method('setErrors')->with(new Collection()); |
||
44 | $mock->__construct(); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::setFullyQualifiedStructuralElementName |
||
49 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::getFullyQualifiedStructuralElementName |
||
50 | */ |
||
51 | public function testSettingAndGettingFullyQualifiedStructuralElementName() |
||
52 | { |
||
53 | $this->assertSame('', $this->fixture->getFullyQualifiedStructuralElementName()); |
||
54 | |||
55 | $this->fixture->setFullyQualifiedStructuralElementName('elementname'); |
||
56 | |||
57 | $this->assertSame('elementname', $this->fixture->getFullyQualifiedStructuralElementName()); |
||
58 | } |
||
59 | |||
60 | /** |
||
61 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::setName |
||
62 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::getName |
||
63 | */ |
||
64 | public function testSettingAndGettingName() |
||
65 | { |
||
66 | $this->assertSame('', $this->fixture->getName()); |
||
67 | |||
68 | $this->fixture->setName('name'); |
||
69 | |||
70 | $this->assertSame('name', $this->fixture->getName()); |
||
71 | } |
||
72 | |||
73 | /** |
||
74 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::setNamespace |
||
75 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::getNamespace |
||
76 | */ |
||
77 | public function testSettingAndGettingNamespace() |
||
78 | { |
||
79 | $this->assertEquals('', $this->fixture->getNamespace()); |
||
80 | |||
81 | $mock = m::mock('phpDocumentor\Descriptor\NamespaceDescriptor'); |
||
82 | |||
83 | $this->fixture->setNamespace($mock); |
||
84 | |||
85 | $this->assertSame($mock, $this->fixture->getNamespace()); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::setSummary |
||
90 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::getSummary |
||
91 | */ |
||
92 | public function testSettingAndGettingSummary() |
||
93 | { |
||
94 | $this->assertSame('', $this->fixture->getSummary()); |
||
95 | |||
96 | $this->fixture->setSummary('summary'); |
||
97 | |||
98 | $this->assertSame('summary', $this->fixture->getSummary()); |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::setDescription |
||
103 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::getDescription |
||
104 | */ |
||
105 | public function testSettingAndGettingDescription() |
||
106 | { |
||
107 | $this->assertSame('', $this->fixture->getDescription()); |
||
108 | |||
109 | $this->fixture->setDescription('description'); |
||
110 | |||
111 | $this->assertSame('description', $this->fixture->getDescription()); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::setPackage |
||
116 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::getPackage |
||
117 | */ |
||
118 | public function testSettingAndGettingPackage() |
||
119 | { |
||
120 | $package = new PackageDescriptor(); |
||
121 | $this->assertNull($this->fixture->getPackage()); |
||
122 | |||
123 | $this->fixture->setPackage($package); |
||
124 | |||
125 | $this->assertSame($package, $this->fixture->getPackage()); |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::getAuthor |
||
130 | */ |
||
131 | public function testGetAuthor() |
||
132 | { |
||
133 | /** @var m\MockInterface|DescriptorAbstract */ |
||
134 | $mock = m::mock( |
||
135 | 'phpDocumentor\Descriptor\DescriptorAbstract, phpDocumentor\Descriptor\Interfaces\ChildInterface' |
||
136 | ); |
||
137 | $mock->shouldDeferMissing(); |
||
138 | |||
139 | $author = new Collection(['author']); |
||
140 | |||
141 | $collection = new Collection(); |
||
142 | $collection->offsetSet('author', $author); |
||
143 | |||
144 | $mock->shouldReceive('getTags')->andReturn($collection); |
||
0 ignored issues
–
show
|
|||
145 | $this->assertSame($author, $mock->getAuthor()); |
||
0 ignored issues
–
show
The method
getAuthor() does not seem to exist on object<Mockery\MockInterface> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
146 | } |
||
147 | |||
148 | /** |
||
149 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::getVersion |
||
150 | */ |
||
151 | public function testGetVersion() |
||
152 | { |
||
153 | /** @var m\MockInterface|DescriptorAbstract */ |
||
154 | $mock = m::mock( |
||
155 | 'phpDocumentor\Descriptor\DescriptorAbstract, phpDocumentor\Descriptor\Interfaces\ChildInterface' |
||
156 | ); |
||
157 | $mock->shouldDeferMissing(); |
||
158 | |||
159 | $version = new Collection(['version']); |
||
160 | |||
161 | $collection = new Collection(); |
||
162 | $collection->offsetSet('version', $version); |
||
163 | |||
164 | $mock->shouldReceive('getTags')->andReturn($collection); |
||
0 ignored issues
–
show
The method
andReturn does only exist in Mockery\ExpectationInterface , but not in Mockery\HigherOrderMessage .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
165 | $this->assertSame($version, $mock->getVersion()); |
||
0 ignored issues
–
show
The method
getVersion() does not seem to exist on object<Mockery\MockInterface> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
166 | } |
||
167 | |||
168 | /** |
||
169 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::getCopyright |
||
170 | */ |
||
171 | public function testGetCopyRight() |
||
172 | { |
||
173 | /** @var m\MockInterface|DescriptorAbstract */ |
||
174 | $mock = m::mock( |
||
175 | 'phpDocumentor\Descriptor\DescriptorAbstract, phpDocumentor\Descriptor\Interfaces\ChildInterface' |
||
176 | ); |
||
177 | $mock->shouldDeferMissing(); |
||
178 | |||
179 | $copyright = new Collection(['copyright']); |
||
180 | |||
181 | $collection = new Collection(); |
||
182 | $collection->offsetSet('copyright', $copyright); |
||
183 | |||
184 | $mock->shouldReceive('getTags')->andReturn($collection); |
||
0 ignored issues
–
show
The method
andReturn does only exist in Mockery\ExpectationInterface , but not in Mockery\HigherOrderMessage .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
185 | $this->assertSame($copyright, $mock->getCopyright()); |
||
0 ignored issues
–
show
The method
getCopyright() does not seem to exist on object<Mockery\MockInterface> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
186 | } |
||
187 | |||
188 | /** |
||
189 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::setLocation |
||
190 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::getFile |
||
191 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::getLine |
||
192 | */ |
||
193 | public function testSettingAndGettingLocation() |
||
194 | { |
||
195 | $this->assertNull($this->fixture->getFile()); |
||
196 | $this->assertSame(0, $this->fixture->getLine()); |
||
197 | |||
198 | $this->fixture->setLocation(m::mock('phpDocumentor\Descriptor\FileDescriptor'), 5); |
||
199 | |||
200 | $this->assertInstanceOf('phpDocumentor\Descriptor\FileDescriptor', $this->fixture->getFile()); |
||
201 | $this->assertSame(5, $this->fixture->getLine()); |
||
202 | } |
||
203 | |||
204 | /** |
||
205 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::setLine |
||
206 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::getLine |
||
207 | */ |
||
208 | public function testSetLineNumber() |
||
209 | { |
||
210 | $this->assertSame(0, $this->fixture->getLine()); |
||
211 | |||
212 | $this->fixture->setLine(5); |
||
213 | |||
214 | $this->assertSame(5, $this->fixture->getLine()); |
||
215 | } |
||
216 | |||
217 | /** |
||
218 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::getPath |
||
219 | */ |
||
220 | public function testGetPath() |
||
221 | { |
||
222 | $this->assertSame('', $this->fixture->getPath()); |
||
223 | |||
224 | /** @var m\MockInterface $file */ |
||
225 | $file = m::mock('phpDocumentor\Descriptor\FileDescriptor'); |
||
226 | $file->shouldReceive('getPath')->andReturn('path'); |
||
0 ignored issues
–
show
The method
andReturn does only exist in Mockery\ExpectationInterface , but not in Mockery\HigherOrderMessage .
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: class A
{
public function foo() { }
}
class B extends A
{
public function bar() { }
}
/**
* @param A|B $x
*/
function someFunction($x)
{
$x->foo(); // This call is fine as the method exists in A and B.
$x->bar(); // This method only exists in B and might cause an error.
}
Available Fixes
Loading history...
|
|||
227 | $this->fixture->setLocation($file); |
||
228 | |||
229 | $this->assertSame('path', $this->fixture->getPath()); |
||
230 | } |
||
231 | |||
232 | /** |
||
233 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::setTags |
||
234 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::getTags |
||
235 | */ |
||
236 | public function testSettingAndGettingTags() |
||
237 | { |
||
238 | $this->assertNull($this->fixture->getTags()); |
||
239 | |||
240 | /** @var Collection $mock */ |
||
241 | $mock = m::mock('phpDocumentor\Descriptor\Collection'); |
||
242 | $this->fixture->setTags($mock); |
||
243 | |||
244 | $this->assertSame($mock, $this->fixture->getTags()); |
||
245 | } |
||
246 | |||
247 | /** |
||
248 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::isDeprecated |
||
249 | */ |
||
250 | public function testIsDeprecated() |
||
251 | { |
||
252 | $this->assertFalse($this->fixture->isDeprecated()); |
||
253 | |||
254 | $this->fixture->setTags(new Collection(['deprecated' => 'deprecated'])); |
||
255 | |||
256 | $this->assertTrue($this->fixture->isDeprecated()); |
||
257 | } |
||
258 | |||
259 | /** |
||
260 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::setErrors |
||
261 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::getErrors |
||
262 | */ |
||
263 | public function testSettingAndGettingErrors() |
||
264 | { |
||
265 | $this->assertNull($this->fixture->getErrors()); |
||
266 | |||
267 | /** @var Collection $mock */ |
||
268 | $mock = m::mock('phpDocumentor\Descriptor\Collection'); |
||
269 | $this->fixture->setErrors($mock); |
||
270 | |||
271 | $this->assertSame($mock, $this->fixture->getErrors()); |
||
272 | } |
||
273 | |||
274 | /** |
||
275 | * @covers phpDocumentor\Descriptor\DescriptorAbstract::__toString |
||
276 | */ |
||
277 | public function testToString() |
||
278 | { |
||
279 | $this->fixture->setFullyQualifiedStructuralElementName('fqn'); |
||
280 | $this->assertSame('fqn', (string) $this->fixture); |
||
281 | } |
||
282 | } |
||
283 |
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: