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-2015 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\Descriptor\ProjectDescriptor; |
||
18 | use phpDocumentor\Transformer\Router\Queue; |
||
19 | use phpDocumentor\Transformer\Router\Rule; |
||
20 | use phpDocumentor\Transformer\Template\Collection; |
||
21 | |||
22 | /** |
||
23 | * @coversDefaultClass \phpDocumentor\Compiler\Pass\ResolveInlineLinkAndSeeTags |
||
24 | * @covers ::__construct |
||
25 | * @covers ::<private> |
||
26 | */ |
||
27 | class ResolveInlineLinkAndSeeTagsTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
||
28 | { |
||
29 | /** @var Queue||m\MockInterface */ |
||
30 | private $router; |
||
31 | |||
32 | /** @var ResolveInlineLinkAndSeeTags */ |
||
33 | private $fixture; |
||
34 | |||
35 | /** |
||
36 | * Initializes the fixture and its dependencies. |
||
37 | */ |
||
38 | protected function setUp() |
||
39 | { |
||
40 | $this->router = m::mock('phpDocumentor\Transformer\Router\Queue'); |
||
41 | $this->fixture = new ResolveInlineLinkAndSeeTags($this->router); |
||
42 | } |
||
43 | |||
44 | /** |
||
45 | * @covers ::getDescription |
||
46 | */ |
||
47 | public function testDescriptionName() |
||
48 | { |
||
49 | $this->assertSame('Resolve @link and @see tags in descriptions', $this->fixture->getDescription()); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * @covers ::execute |
||
54 | */ |
||
55 | public function testReplaceDescriptionIfItContainsNoSeeOrLink() |
||
56 | { |
||
57 | $description = 'This is a description'; |
||
58 | |||
59 | $descriptor = $this->givenAChildDescriptorWithDescription($description); |
||
60 | $collection = $this->givenACollection($descriptor); |
||
61 | $this->thenDescriptionOfDescriptorIsChangedInto($descriptor, $description); |
||
62 | |||
63 | $project = $this->givenAProjectDescriptorWithChildDescriptors($collection); |
||
64 | |||
65 | $this->fixture->execute($project); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * @covers ::execute |
||
70 | */ |
||
71 | public function testReplaceDescriptionIfItContainsASeeButFileIsNotAvailable() |
||
72 | { |
||
73 | $description = 'Description with {@see ARandomDescriptor}'; |
||
74 | $expected = 'Description with \ARandomDescriptor'; |
||
75 | |||
76 | $descriptor = $this->givenAChildDescriptorWithDescription($description); |
||
77 | $collection = $this->givenACollection($descriptor); |
||
78 | $elementToLinkTo = $this->givenAnElementToLinkTo(); |
||
79 | |||
80 | $this->whenDescriptionContainsSeeOrLinkWithElement($descriptor, $elementToLinkTo); |
||
81 | |||
82 | $this->thenDescriptionOfDescriptorIsChangedInto($descriptor, $expected); |
||
83 | |||
84 | $project = $this->givenAProjectDescriptorWithChildDescriptors($collection); |
||
85 | |||
86 | $this->fixture->execute($project); |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * @covers ::execute |
||
91 | */ |
||
92 | public function testReplaceDescriptionIfItContainsASeeAndFileIsPresent() |
||
93 | { |
||
94 | $description = 'Description with {@see LinkDescriptor}'; |
||
95 | $expected = 'Description with [\phpDocumentor\LinkDescriptor](../classes/phpDocumentor.LinkDescriptor.html)'; |
||
96 | |||
97 | $descriptor = $this->givenAChildDescriptorWithDescription($description); |
||
98 | $collection = $this->givenACollection($descriptor); |
||
99 | $elementToLinkTo = $this->givenAnElementToLinkTo(); |
||
100 | |||
101 | $this->whenDescriptionContainsSeeOrLinkWithElement($descriptor, $elementToLinkTo); |
||
102 | |||
103 | $this->thenDescriptionOfDescriptorIsChangedInto($descriptor, $expected); |
||
104 | |||
105 | $project = $this->givenAProjectDescriptorWithChildDescriptors($collection); |
||
106 | |||
107 | $this->fixture->execute($project); |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * @covers ::execute |
||
112 | */ |
||
113 | public function testReplaceDescriptionIfItContainsALinkAndFileIsPresent() |
||
114 | { |
||
115 | $this->markTestSkipped('Needs rewrite'); |
||
116 | $description = 'Description with {@link LinkDescriptor}'; |
||
117 | $expected = |
||
118 | 'Description with [LinkDescriptor](../classes/phpDocumentor.LinkDescriptor.html)'; |
||
119 | |||
120 | $descriptor = $this->givenAChildDescriptorWithDescription($description); |
||
121 | $collection = $this->givenACollection($descriptor); |
||
122 | $elementToLinkTo = $this->givenAnElementToLinkTo(); |
||
123 | |||
124 | $this->whenDescriptionContainsSeeOrLinkWithElement($descriptor, $elementToLinkTo); |
||
125 | |||
126 | $this->thenDescriptionOfDescriptorIsChangedInto($descriptor, $expected); |
||
127 | |||
128 | $project = $this->givenAProjectDescriptorWithChildDescriptors($collection); |
||
129 | |||
130 | $this->fixture->execute($project); |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * @covers ::execute |
||
135 | */ |
||
136 | public function testReplaceDescriptionIfItContainsAUrl() |
||
137 | { |
||
138 | $this->markTestSkipped('Needs rewrite'); |
||
139 | $description = 'Description with {@see http://www.phpdoc.org}'; |
||
140 | $expected = 'Description with [http://www.phpdoc.org](http://www.phpdoc.org)'; |
||
141 | |||
142 | $descriptor = $this->givenAChildDescriptorWithDescription($description); |
||
143 | $collection = $this->givenACollection($descriptor); |
||
144 | |||
145 | $this->thenDescriptionOfDescriptorIsChangedInto($descriptor, $expected); |
||
146 | |||
147 | $project = $this->givenAProjectDescriptorWithChildDescriptors($collection); |
||
148 | |||
149 | $this->fixture->execute($project); |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * @covers ::execute |
||
154 | */ |
||
155 | public function testReplaceDescriptionIfItContainsAnotherTag() |
||
156 | { |
||
157 | $description = 'Description with {@author John Doe}'; |
||
158 | $expected = 'Description with {@author John Doe}'; |
||
159 | |||
160 | $descriptor = $this->givenAChildDescriptorWithDescription($description); |
||
161 | $collection = $this->givenACollection($descriptor); |
||
162 | |||
163 | $this->thenDescriptionOfDescriptorIsChangedInto($descriptor, $expected); |
||
164 | |||
165 | $project = $this->givenAProjectDescriptorWithChildDescriptors($collection); |
||
166 | |||
167 | $this->fixture->execute($project); |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * Returns a mocked Descriptor with its description set to the given value. |
||
172 | * |
||
173 | * @param string $description |
||
174 | * |
||
175 | * @return m\MockInterface |
||
176 | */ |
||
177 | private function givenAChildDescriptorWithDescription($description) |
||
178 | { |
||
179 | $descriptor = m::mock('phpDocumentor\Descriptor\DescriptorAbstract'); |
||
180 | $descriptor->shouldReceive('getDescription')->andReturn($description); |
||
181 | |||
182 | return $descriptor; |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * Returns a mocked Project Descriptor. |
||
187 | * |
||
188 | * @param Collection|m\MockInterface $descriptors |
||
189 | * |
||
190 | * @return m\MockInterface |
||
191 | */ |
||
192 | private function givenAProjectDescriptorWithChildDescriptors($descriptors) |
||
193 | { |
||
194 | $projectDescriptor = m::mock('phpDocumentor\Descriptor\ProjectDescriptor'); |
||
195 | $projectDescriptor->shouldReceive('getIndexes')->andReturn($descriptors); |
||
196 | |||
197 | return $projectDescriptor; |
||
198 | } |
||
199 | |||
200 | /** |
||
201 | * Returns the descriptor of the element that the link points to |
||
202 | * |
||
203 | * @return DescriptorAbstract|m\MockInterface |
||
204 | */ |
||
205 | private function givenAnElementToLinkTo() |
||
206 | { |
||
207 | $namespaceAliases = array('LinkDescriptor' => '\phpDocumentor\LinkDescriptor'); |
||
208 | $namespaceCollection = m::mock('phpDocumentor\Transformer\Template\Collection'); |
||
209 | $namespaceCollection->shouldReceive('getAll')->once()->andReturn($namespaceAliases); |
||
210 | |||
211 | $elementToLinkTo = m::mock('phpDocumentor\Descriptor\DescriptorAbstract'); |
||
212 | $elementToLinkTo->shouldReceive('getNamespaceAliases')->once()->andReturn($namespaceCollection); |
||
213 | |||
214 | return $elementToLinkTo; |
||
215 | } |
||
216 | |||
217 | /** |
||
218 | * Returns a collection with descriptor. This collection will be scanned to see if a link can be made to a file. |
||
219 | * |
||
220 | * @param DescriptorAbstract|m\MockInterface $descriptor |
||
221 | * |
||
222 | * @return Collection|m\MockInterface |
||
223 | */ |
||
224 | private function givenACollection($descriptor) |
||
225 | { |
||
226 | $collection = m::mock('phpDocumentor\Transformer\Template\Collection'); |
||
227 | |||
228 | $items = array('\phpDocumentor\LinkDescriptor' => $descriptor); |
||
229 | |||
230 | $collection->shouldReceive('get')->once()->andReturn($items); |
||
231 | |||
232 | return $collection; |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | * Verifies if the given descriptor's setDescription method is called with the given value. |
||
237 | * |
||
238 | * @param m\MockInterface $descriptor |
||
239 | * @param string $expected |
||
240 | * |
||
241 | * @return void |
||
242 | */ |
||
243 | public function thenDescriptionOfDescriptorIsChangedInto($descriptor, $expected) |
||
244 | { |
||
245 | $descriptor->shouldReceive('setDescription')->with($expected); |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * It resolves the element that is linked to |
||
250 | * |
||
251 | * @param DescriptorAbstract $descriptor |
||
252 | * @param DescriptorAbstract $elementToLinkTo |
||
253 | * |
||
254 | * @return DescriptorAbstract |
||
255 | */ |
||
256 | private function whenDescriptionContainsSeeOrLinkWithElement($descriptor, $elementToLinkTo) |
||
257 | { |
||
258 | $rule = m::mock('phpDocumentor\Transformer\Router\Rule'); |
||
259 | $rule->shouldReceive('generate')->andReturn('/classes/phpDocumentor.LinkDescriptor.html'); |
||
260 | $this->router->shouldReceive('match')->andReturn($rule); |
||
261 | $descriptor->shouldReceive('getFile')->andReturn($elementToLinkTo); |
||
0 ignored issues
–
show
|
|||
262 | $descriptor->shouldReceive('getNamespace'); |
||
0 ignored issues
–
show
The method
shouldReceive does not exist on object<phpDocumentor\Des...tor\DescriptorAbstract> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
263 | |||
264 | return $descriptor; |
||
265 | } |
||
266 | } |
||
267 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: