1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This file is part of phpDocumentor. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @link http://phpdoc.org |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace phpDocumentor\Reflection\DocBlock\Tags; |
15
|
|
|
|
16
|
|
|
use Mockery as m; |
17
|
|
|
use phpDocumentor\Reflection\DocBlock\Description; |
18
|
|
|
use phpDocumentor\Reflection\DocBlock\DescriptionFactory; |
19
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen as FqsenRef; |
20
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Url as UrlRef; |
21
|
|
|
use phpDocumentor\Reflection\Fqsen; |
22
|
|
|
use phpDocumentor\Reflection\FqsenResolver; |
23
|
|
|
use phpDocumentor\Reflection\Types\Context; |
24
|
|
|
use PHPUnit\Framework\TestCase; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\See |
28
|
|
|
* @covers ::<private> |
29
|
|
|
*/ |
30
|
|
|
class SeeTest extends TestCase |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* Call Mockery::close after each test. |
34
|
|
|
*/ |
35
|
|
|
public function tearDown() : void |
36
|
|
|
{ |
37
|
|
|
m::close(); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See::__construct |
42
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
43
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen |
44
|
|
|
* @uses \phpDocumentor\Reflection\Fqsen |
45
|
|
|
* |
46
|
|
|
* @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName |
47
|
|
|
*/ |
48
|
|
|
public function testIfCorrectTagNameIsReturned() : void |
49
|
|
|
{ |
50
|
|
|
$fixture = new See(new FqsenRef(new Fqsen('\DateTime')), new Description('Description')); |
51
|
|
|
|
52
|
|
|
$this->assertSame('see', $fixture->getName()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See::__construct |
57
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See::__toString |
58
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter |
59
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
60
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen |
61
|
|
|
* |
62
|
|
|
* @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render |
63
|
|
|
* @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName |
64
|
|
|
*/ |
65
|
|
|
public function testIfTagCanBeRenderedUsingDefaultFormatter() : void |
66
|
|
|
{ |
67
|
|
|
$fixture = new See(new FqsenRef(new Fqsen('\DateTime')), new Description('Description')); |
68
|
|
|
|
69
|
|
|
$this->assertSame('@see \DateTime Description', $fixture->render()); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See::__construct |
74
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
75
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen |
76
|
|
|
* @uses \phpDocumentor\Reflection\Fqsen |
77
|
|
|
* |
78
|
|
|
* @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render |
79
|
|
|
*/ |
80
|
|
|
public function testIfTagCanBeRenderedUsingSpecificFormatter() : void |
81
|
|
|
{ |
82
|
|
|
$fixture = new See(new FqsenRef(new Fqsen('\DateTime')), new Description('Description')); |
83
|
|
|
|
84
|
|
|
$formatter = m::mock(Formatter::class); |
85
|
|
|
$formatter->shouldReceive('format')->with($fixture)->andReturn('Rendered output'); |
86
|
|
|
|
87
|
|
|
$this->assertSame('Rendered output', $fixture->render($formatter)); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen |
92
|
|
|
* @uses \phpDocumentor\Reflection\Fqsen |
93
|
|
|
* |
94
|
|
|
* @covers ::__construct |
95
|
|
|
* @covers ::getReference |
96
|
|
|
*/ |
97
|
|
|
public function testHasReferenceToFqsen() : void |
98
|
|
|
{ |
99
|
|
|
$expected = new FqsenRef(new Fqsen('\DateTime')); |
100
|
|
|
|
101
|
|
|
$fixture = new See($expected); |
102
|
|
|
|
103
|
|
|
$this->assertSame($expected, $fixture->getReference()); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
108
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen |
109
|
|
|
* @uses \phpDocumentor\Reflection\Fqsen |
110
|
|
|
* |
111
|
|
|
* @covers ::__construct |
112
|
|
|
* @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription |
113
|
|
|
*/ |
114
|
|
|
public function testHasDescription() : void |
115
|
|
|
{ |
116
|
|
|
$expected = new Description('Description'); |
117
|
|
|
|
118
|
|
|
$fixture = new See(new FqsenRef(new Fqsen('\DateTime')), $expected); |
119
|
|
|
|
120
|
|
|
$this->assertSame($expected, $fixture->getDescription()); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
125
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen |
126
|
|
|
* @uses \phpDocumentor\Reflection\Fqsen |
127
|
|
|
* |
128
|
|
|
* @covers ::__construct |
129
|
|
|
* @covers ::__toString |
130
|
|
|
*/ |
131
|
|
|
public function testStringRepresentationIsReturned() : void |
132
|
|
|
{ |
133
|
|
|
$fixture = new See(new FqsenRef(new Fqsen('\DateTime::format()')), new Description('Description')); |
134
|
|
|
|
135
|
|
|
$this->assertSame('\DateTime::format() Description', (string) $fixture); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See::<public> |
140
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory |
141
|
|
|
* @uses \phpDocumentor\Reflection\FqsenResolver |
142
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
143
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen |
144
|
|
|
* @uses \phpDocumentor\Reflection\Fqsen |
145
|
|
|
* @uses \phpDocumentor\Reflection\Types\Context |
146
|
|
|
* |
147
|
|
|
* @covers ::create |
148
|
|
|
*/ |
149
|
|
|
public function testFactoryMethod() : void |
150
|
|
|
{ |
151
|
|
|
$descriptionFactory = m::mock(DescriptionFactory::class); |
152
|
|
|
$resolver = m::mock(FqsenResolver::class); |
153
|
|
|
$context = new Context(''); |
154
|
|
|
|
155
|
|
|
$fqsen = new Fqsen('\DateTime'); |
156
|
|
|
$description = new Description('My Description'); |
157
|
|
|
|
158
|
|
|
$descriptionFactory |
159
|
|
|
->shouldReceive('create')->with('My Description', $context)->andReturn($description); |
160
|
|
|
$resolver->shouldReceive('resolve')->with('DateTime', $context)->andReturn($fqsen); |
161
|
|
|
|
162
|
|
|
$fixture = See::create('DateTime My Description', $resolver, $descriptionFactory, $context); |
163
|
|
|
|
164
|
|
|
$this->assertSame('\DateTime My Description', (string) $fixture); |
165
|
|
|
$this->assertInstanceOf(FqsenRef::class, $fixture->getReference()); |
166
|
|
|
$this->assertSame((string) $fqsen, (string) $fixture->getReference()); |
167
|
|
|
$this->assertSame($description, $fixture->getDescription()); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See::<public> |
172
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory |
173
|
|
|
* @uses \phpDocumentor\Reflection\FqsenResolver |
174
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
175
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen |
176
|
|
|
* @uses \phpDocumentor\Reflection\Fqsen |
177
|
|
|
* @uses \phpDocumentor\Reflection\Types\Context |
178
|
|
|
* |
179
|
|
|
* @covers ::create |
180
|
|
|
*/ |
181
|
|
|
public function testFactoryMethodWithNonClassFQSEN() : void |
182
|
|
|
{ |
183
|
|
|
$descriptionFactory = m::mock(DescriptionFactory::class); |
184
|
|
|
$resolver = m::mock(FqsenResolver::class); |
185
|
|
|
$context = new Context(''); |
186
|
|
|
|
187
|
|
|
$fqsen = new Fqsen('\DateTime'); |
188
|
|
|
$description = new Description('My Description'); |
189
|
|
|
|
190
|
|
|
$descriptionFactory |
191
|
|
|
->shouldReceive('create')->with('My Description', $context)->andReturn($description); |
192
|
|
|
$resolver->shouldReceive('resolve')->with('DateTime', $context)->andReturn($fqsen); |
193
|
|
|
|
194
|
|
|
$fixture = See::create('DateTime::createFromFormat() My Description', $resolver, $descriptionFactory, $context); |
195
|
|
|
|
196
|
|
|
$this->assertSame('\DateTime::createFromFormat() My Description', (string) $fixture); |
197
|
|
|
$this->assertInstanceOf(FqsenRef::class, $fixture->getReference()); |
198
|
|
|
$this->assertSame('\DateTime::createFromFormat()', (string) $fixture->getReference()); |
199
|
|
|
$this->assertSame($description, $fixture->getDescription()); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See::<public> |
204
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory |
205
|
|
|
* @uses \phpDocumentor\Reflection\FqsenResolver |
206
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Description |
207
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Url |
208
|
|
|
* @uses \phpDocumentor\Reflection\Types\Context |
209
|
|
|
* |
210
|
|
|
* @covers ::create |
211
|
|
|
*/ |
212
|
|
|
public function testFactoryMethodWithUrl() : void |
213
|
|
|
{ |
214
|
|
|
$descriptionFactory = m::mock(DescriptionFactory::class); |
215
|
|
|
$resolver = m::mock(FqsenResolver::class); |
216
|
|
|
$context = new Context(''); |
217
|
|
|
|
218
|
|
|
$description = new Description('My Description'); |
219
|
|
|
|
220
|
|
|
$descriptionFactory |
221
|
|
|
->shouldReceive('create')->with('My Description', $context)->andReturn($description); |
222
|
|
|
|
223
|
|
|
$resolver->shouldNotReceive('resolve'); |
224
|
|
|
|
225
|
|
|
$fixture = See::create('https://test.org My Description', $resolver, $descriptionFactory, $context); |
226
|
|
|
|
227
|
|
|
$this->assertSame('https://test.org My Description', (string) $fixture); |
228
|
|
|
$this->assertInstanceOf(UrlRef::class, $fixture->getReference()); |
229
|
|
|
$this->assertSame('https://test.org', (string) $fixture->getReference()); |
230
|
|
|
$this->assertSame($description, $fixture->getDescription()); |
231
|
|
|
} |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* @covers ::create |
235
|
|
|
*/ |
236
|
|
|
public function testFactoryMethodFailsIfBodyIsNotEmpty() : void |
237
|
|
|
{ |
238
|
|
|
$this->expectException('InvalidArgumentException'); |
239
|
|
|
$this->assertNull(See::create('')); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
/** |
243
|
|
|
* @covers ::create |
244
|
|
|
*/ |
245
|
|
|
public function testFactoryMethodFailsIfResolverIsNull() : void |
246
|
|
|
{ |
247
|
|
|
$this->expectException('InvalidArgumentException'); |
248
|
|
|
See::create('body'); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* @covers ::create |
253
|
|
|
*/ |
254
|
|
|
public function testFactoryMethodFailsIfDescriptionFactoryIsNull() : void |
255
|
|
|
{ |
256
|
|
|
$this->expectException('InvalidArgumentException'); |
257
|
|
|
See::create('body', new FqsenResolver()); |
258
|
|
|
} |
259
|
|
|
} |
260
|
|
|
|