|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of phpDocumentor. |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* |
|
9
|
|
|
* @copyright 2010-2018 Mike van Riel<[email protected]> |
|
10
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
|
11
|
|
|
* @link http://phpdoc.org |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace phpDocumentor\Reflection\DocBlock; |
|
15
|
|
|
|
|
16
|
|
|
use Mockery as m; |
|
17
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Link; |
|
18
|
|
|
use phpDocumentor\Reflection\Types\Context; |
|
19
|
|
|
use PHPUnit\Framework\TestCase; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\DescriptionFactory |
|
23
|
|
|
* @covers ::<private> |
|
24
|
|
|
*/ |
|
25
|
|
|
class DescriptionFactoryTest extends TestCase |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* Call Mockery::close after each test. |
|
29
|
|
|
*/ |
|
30
|
|
|
public function tearDown(): void |
|
31
|
|
|
{ |
|
32
|
|
|
m::close(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @covers ::__construct |
|
37
|
|
|
* @covers ::create |
|
38
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Description |
|
39
|
|
|
* @dataProvider provideSimpleExampleDescriptions |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testDescriptionCanParseASimpleString($contents): void |
|
42
|
|
|
{ |
|
43
|
|
|
$tagFactory = m::mock(TagFactory::class); |
|
44
|
|
|
$tagFactory->shouldReceive('create')->never(); |
|
45
|
|
|
|
|
46
|
|
|
$factory = new DescriptionFactory($tagFactory); |
|
47
|
|
|
$description = $factory->create($contents, new Context('')); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertSame($contents, $description->render()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* @covers ::__construct |
|
54
|
|
|
* @covers ::create |
|
55
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Description |
|
56
|
|
|
* @dataProvider provideEscapeSequences |
|
57
|
|
|
*/ |
|
58
|
|
|
public function testEscapeSequences($contents, $expected): void |
|
59
|
|
|
{ |
|
60
|
|
|
$tagFactory = m::mock(TagFactory::class); |
|
61
|
|
|
$tagFactory->shouldReceive('create')->never(); |
|
62
|
|
|
|
|
63
|
|
|
$factory = new DescriptionFactory($tagFactory); |
|
64
|
|
|
$description = $factory->create($contents, new Context('')); |
|
65
|
|
|
|
|
66
|
|
|
$this->assertSame($expected, $description->render()); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @covers ::__construct |
|
71
|
|
|
* @covers ::create |
|
72
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Description |
|
73
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\Link |
|
74
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
|
75
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter |
|
76
|
|
|
* @uses phpDocumentor\Reflection\Types\Context |
|
77
|
|
|
*/ |
|
78
|
|
|
public function testDescriptionCanParseAStringWithInlineTag(): void |
|
79
|
|
|
{ |
|
80
|
|
|
$contents = 'This is text for a {@link http://phpdoc.org/ description} that uses an inline tag.'; |
|
81
|
|
|
$context = new Context(''); |
|
82
|
|
|
$tagFactory = m::mock(TagFactory::class); |
|
83
|
|
|
$tagFactory->shouldReceive('create') |
|
84
|
|
|
->once() |
|
85
|
|
|
->with('@link http://phpdoc.org/ description', $context) |
|
86
|
|
|
->andReturn(new Link('http://phpdoc.org/', new Description('description'))); |
|
87
|
|
|
|
|
88
|
|
|
$factory = new DescriptionFactory($tagFactory); |
|
89
|
|
|
$description = $factory->create($contents, $context); |
|
90
|
|
|
|
|
91
|
|
|
$this->assertSame($contents, $description->render()); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* @covers ::__construct |
|
96
|
|
|
* @covers ::create |
|
97
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Description |
|
98
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\Link |
|
99
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
|
100
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter |
|
101
|
|
|
* @uses phpDocumentor\Reflection\Types\Context |
|
102
|
|
|
*/ |
|
103
|
|
|
public function testDescriptionCanParseAStringStartingWithInlineTag(): void |
|
104
|
|
|
{ |
|
105
|
|
|
$contents = '{@link http://phpdoc.org/ This} is text for a description that starts with an inline tag.'; |
|
106
|
|
|
$context = new Context(''); |
|
107
|
|
|
$tagFactory = m::mock(TagFactory::class); |
|
108
|
|
|
$tagFactory->shouldReceive('create') |
|
109
|
|
|
->once() |
|
110
|
|
|
->with('@link http://phpdoc.org/ This', $context) |
|
111
|
|
|
->andReturn(new Link('http://phpdoc.org/', new Description('This'))); |
|
112
|
|
|
|
|
113
|
|
|
$factory = new DescriptionFactory($tagFactory); |
|
114
|
|
|
$description = $factory->create($contents, $context); |
|
115
|
|
|
|
|
116
|
|
|
$this->assertSame($contents, $description->render()); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* @covers ::__construct |
|
121
|
|
|
* @covers ::create |
|
122
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Description |
|
123
|
|
|
*/ |
|
124
|
|
|
public function testIfSuperfluousStartingSpacesAreRemoved(): void |
|
125
|
|
|
{ |
|
126
|
|
|
$factory = new DescriptionFactory(m::mock(TagFactory::class)); |
|
127
|
|
|
$descriptionText = <<<DESCRIPTION |
|
128
|
|
|
This is a multiline |
|
129
|
|
|
description that you commonly |
|
130
|
|
|
see with tags. |
|
131
|
|
|
|
|
132
|
|
|
It does have a multiline code sample |
|
133
|
|
|
that should align, no matter what |
|
134
|
|
|
|
|
135
|
|
|
All spaces superfluous spaces on the |
|
136
|
|
|
second and later lines should be |
|
137
|
|
|
removed but the code sample should |
|
138
|
|
|
still be indented. |
|
139
|
|
|
DESCRIPTION; |
|
140
|
|
|
|
|
141
|
|
|
$expectedDescription = <<<DESCRIPTION |
|
142
|
|
|
This is a multiline |
|
143
|
|
|
description that you commonly |
|
144
|
|
|
see with tags. |
|
145
|
|
|
|
|
146
|
|
|
It does have a multiline code sample |
|
147
|
|
|
that should align, no matter what |
|
148
|
|
|
|
|
149
|
|
|
All spaces superfluous spaces on the |
|
150
|
|
|
second and later lines should be |
|
151
|
|
|
removed but the code sample should |
|
152
|
|
|
still be indented. |
|
153
|
|
|
DESCRIPTION; |
|
154
|
|
|
|
|
155
|
|
|
$description = $factory->create($descriptionText, new Context('')); |
|
156
|
|
|
|
|
157
|
|
|
$this->assertSame($expectedDescription, $description->render()); |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
/** |
|
161
|
|
|
* Provides a series of example strings that the parser should correctly interpret and return. |
|
162
|
|
|
* |
|
163
|
|
|
* @return string[][] |
|
164
|
|
|
*/ |
|
165
|
|
|
public function provideSimpleExampleDescriptions() |
|
166
|
|
|
{ |
|
167
|
|
|
return [ |
|
168
|
|
|
['This is text for a description.'], |
|
169
|
|
|
['This is text for a description containing { that is literal.'], |
|
170
|
|
|
['This is text for a description containing } that is literal.'], |
|
171
|
|
|
['This is text for a description with {just a text} that is not a tag.'], |
|
172
|
|
|
]; |
|
173
|
|
|
} |
|
174
|
|
|
|
|
175
|
|
|
public function provideEscapeSequences() |
|
176
|
|
|
{ |
|
177
|
|
|
return [ |
|
178
|
|
|
['This is text for a description with a {@}.', 'This is text for a description with a @.'], |
|
179
|
|
|
['This is text for a description with a {}.', 'This is text for a description with a }.'], |
|
180
|
|
|
]; |
|
181
|
|
|
} |
|
182
|
|
|
} |
|
183
|
|
|
|