These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * This file is part of phpDocumentor. |
||
4 | * |
||
5 | * For the full copyright and license information, please view the LICENSE |
||
6 | * file that was distributed with this source code. |
||
7 | * |
||
8 | * @copyright 2010-2018 Mike van Riel<[email protected]> |
||
9 | * @license http://www.opensource.org/licenses/mit-license.php MIT |
||
10 | * @link http://phpdoc.org |
||
11 | */ |
||
12 | |||
13 | namespace phpDocumentor\Compiler\Pass; |
||
14 | |||
15 | use Mockery as m; |
||
16 | use phpDocumentor\Descriptor\DescriptorAbstract; |
||
17 | use phpDocumentor\Transformer\Router\Queue; |
||
18 | use phpDocumentor\Transformer\Template\Collection; |
||
19 | |||
20 | /** |
||
21 | * @coversDefaultClass \phpDocumentor\Compiler\Pass\ResolveInlineLinkAndSeeTags |
||
22 | * @covers ::__construct |
||
23 | * @covers ::<private> |
||
24 | */ |
||
25 | class ResolveInlineLinkAndSeeTagsTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
||
26 | { |
||
27 | /** @var Queue|m\MockInterface */ |
||
28 | private $router; |
||
29 | |||
30 | /** @var ResolveInlineLinkAndSeeTags */ |
||
31 | private $fixture; |
||
32 | |||
33 | /** |
||
34 | * Initializes the fixture and its dependencies. |
||
35 | */ |
||
36 | protected function setUp() |
||
37 | { |
||
38 | $this->router = m::mock('phpDocumentor\Transformer\Router\Queue'); |
||
39 | $this->fixture = new ResolveInlineLinkAndSeeTags($this->router); |
||
40 | } |
||
41 | |||
42 | /** |
||
43 | * @covers ::getDescription |
||
44 | */ |
||
45 | public function testDescriptionName() |
||
46 | { |
||
47 | $this->assertSame('Resolve @link and @see tags in descriptions', $this->fixture->getDescription()); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @covers ::execute |
||
52 | */ |
||
53 | public function testReplaceDescriptionIfItContainsNoSeeOrLink() |
||
54 | { |
||
55 | $description = 'This is a description'; |
||
56 | |||
57 | $descriptor = $this->givenAChildDescriptorWithDescription($description); |
||
58 | $collection = $this->givenACollection($descriptor); |
||
59 | $this->thenDescriptionOfDescriptorIsChangedInto($descriptor, $description); |
||
60 | |||
61 | $project = $this->givenAProjectDescriptorWithChildDescriptors($collection); |
||
62 | |||
63 | $this->fixture->execute($project); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * @covers ::execute |
||
68 | */ |
||
69 | public function testReplaceDescriptionIfItContainsASeeButFileIsNotAvailable() |
||
70 | { |
||
71 | $description = 'Description with {@see ARandomDescriptor}'; |
||
72 | $expected = 'Description with \ARandomDescriptor'; |
||
73 | |||
74 | $descriptor = $this->givenAChildDescriptorWithDescription($description); |
||
75 | $collection = $this->givenACollection($descriptor); |
||
76 | $elementToLinkTo = $this->givenAnElementToLinkTo(); |
||
77 | |||
78 | $this->whenDescriptionContainsSeeOrLinkWithElement($descriptor, $elementToLinkTo); |
||
79 | |||
80 | $this->thenDescriptionOfDescriptorIsChangedInto($descriptor, $expected); |
||
81 | |||
82 | $project = $this->givenAProjectDescriptorWithChildDescriptors($collection); |
||
83 | |||
84 | $this->fixture->execute($project); |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * @covers ::execute |
||
89 | */ |
||
90 | public function testReplaceDescriptionIfItContainsASeeAndFileIsPresent() |
||
91 | { |
||
92 | $description = 'Description with {@see LinkDescriptor}'; |
||
93 | $expected = 'Description with [\phpDocumentor\LinkDescriptor](../classes/phpDocumentor.LinkDescriptor.html)'; |
||
94 | |||
95 | $descriptor = $this->givenAChildDescriptorWithDescription($description); |
||
96 | $collection = $this->givenACollection($descriptor); |
||
97 | $elementToLinkTo = $this->givenAnElementToLinkTo(); |
||
98 | |||
99 | $this->whenDescriptionContainsSeeOrLinkWithElement($descriptor, $elementToLinkTo); |
||
100 | |||
101 | $this->thenDescriptionOfDescriptorIsChangedInto($descriptor, $expected); |
||
102 | |||
103 | $project = $this->givenAProjectDescriptorWithChildDescriptors($collection); |
||
104 | |||
105 | $this->fixture->execute($project); |
||
106 | } |
||
107 | |||
108 | /** |
||
109 | * @covers ::execute |
||
110 | */ |
||
111 | public function testReplaceDescriptionIfItContainsAnotherTag() |
||
112 | { |
||
113 | $description = 'Description with {@author John Doe}'; |
||
114 | $expected = 'Description with {@author John Doe}'; |
||
115 | |||
116 | $descriptor = $this->givenAChildDescriptorWithDescription($description); |
||
117 | $collection = $this->givenACollection($descriptor); |
||
118 | |||
119 | $this->thenDescriptionOfDescriptorIsChangedInto($descriptor, $expected); |
||
120 | |||
121 | $project = $this->givenAProjectDescriptorWithChildDescriptors($collection); |
||
122 | |||
123 | $this->fixture->execute($project); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Returns a mocked Descriptor with its description set to the given value. |
||
128 | * |
||
129 | * @param string $description |
||
130 | * |
||
131 | * @return m\MockInterface |
||
132 | */ |
||
133 | private function givenAChildDescriptorWithDescription($description) |
||
134 | { |
||
135 | $descriptor = m::mock('phpDocumentor\Descriptor\DescriptorAbstract'); |
||
136 | $descriptor->shouldReceive('getDescription')->andReturn($description); |
||
0 ignored issues
–
show
|
|||
137 | |||
138 | return $descriptor; |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Returns a mocked Project Descriptor. |
||
143 | * |
||
144 | * @param Collection|m\MockInterface $descriptors |
||
145 | * |
||
146 | * @return m\MockInterface |
||
147 | */ |
||
148 | private function givenAProjectDescriptorWithChildDescriptors($descriptors) |
||
149 | { |
||
150 | $projectDescriptor = m::mock('phpDocumentor\Descriptor\ProjectDescriptor'); |
||
151 | $projectDescriptor->shouldReceive('getIndexes')->andReturn($descriptors); |
||
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...
|
|||
152 | |||
153 | return $projectDescriptor; |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * Returns the descriptor of the element that the link points to |
||
158 | * |
||
159 | * @return DescriptorAbstract|m\MockInterface |
||
160 | */ |
||
161 | private function givenAnElementToLinkTo() |
||
162 | { |
||
163 | $namespaceAliases = ['LinkDescriptor' => '\phpDocumentor\LinkDescriptor']; |
||
164 | $namespaceCollection = m::mock('phpDocumentor\Transformer\Template\Collection'); |
||
165 | $namespaceCollection->shouldReceive('getAll')->once()->andReturn($namespaceAliases); |
||
166 | |||
167 | $elementToLinkTo = m::mock('phpDocumentor\Descriptor\DescriptorAbstract'); |
||
168 | $elementToLinkTo->shouldReceive('getNamespaceAliases')->once()->andReturn($namespaceCollection); |
||
169 | |||
170 | return $elementToLinkTo; |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * Returns a collection with descriptor. This collection will be scanned to see if a link can be made to a file. |
||
175 | * |
||
176 | * @param DescriptorAbstract|m\MockInterface $descriptor |
||
177 | * |
||
178 | * @return Collection|m\MockInterface |
||
179 | */ |
||
180 | private function givenACollection($descriptor) |
||
181 | { |
||
182 | $collection = m::mock('phpDocumentor\Transformer\Template\Collection'); |
||
183 | |||
184 | $items = ['\phpDocumentor\LinkDescriptor' => $descriptor]; |
||
185 | |||
186 | $collection->shouldReceive('get')->once()->andReturn($items); |
||
187 | |||
188 | return $collection; |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * Verifies if the given descriptor's setDescription method is called with the given value. |
||
193 | * |
||
194 | * @param m\MockInterface $descriptor |
||
195 | * @param string $expected |
||
196 | */ |
||
197 | public function thenDescriptionOfDescriptorIsChangedInto($descriptor, $expected) |
||
198 | { |
||
199 | $descriptor->shouldReceive('setDescription')->with($expected); |
||
200 | } |
||
201 | |||
202 | /** |
||
203 | * It resolves the element that is linked to |
||
204 | * |
||
205 | * @param m\MockInterface $descriptor |
||
206 | * @param DescriptorAbstract $elementToLinkTo |
||
207 | * |
||
208 | * @return DescriptorAbstract |
||
209 | */ |
||
210 | private function whenDescriptionContainsSeeOrLinkWithElement($descriptor, $elementToLinkTo) |
||
211 | { |
||
212 | $rule = m::mock('phpDocumentor\Transformer\Router\Rule'); |
||
213 | $rule->shouldReceive('generate')->andReturn('/classes/phpDocumentor.LinkDescriptor.html'); |
||
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...
|
|||
214 | $this->router->shouldReceive('match')->andReturn($rule); |
||
0 ignored issues
–
show
The method
shouldReceive does only exist in Mockery\MockInterface , but not in phpDocumentor\Transformer\Router\Queue .
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...
|
|||
215 | $descriptor->shouldReceive('getFile')->andReturn($elementToLinkTo); |
||
216 | $descriptor->shouldReceive('getNamespace'); |
||
217 | |||
218 | return $descriptor; |
||
219 | } |
||
220 | } |
||
221 |
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: