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\Reflection\DocBlock; |
14
|
|
|
|
15
|
|
|
use Mockery as m; |
16
|
|
|
use phpDocumentor\Reflection\DocBlock; |
17
|
|
|
use PHPUnit\Framework\TestCase; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Serializer |
21
|
|
|
* @covers ::<private> |
22
|
|
|
*/ |
23
|
|
|
class SerializerTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Call Mockery::close after each test. |
27
|
|
|
*/ |
28
|
|
|
public function tearDown() |
29
|
|
|
{ |
30
|
|
|
m::close(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @covers ::__construct |
35
|
|
|
* @covers ::getDocComment |
36
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Description |
37
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter |
38
|
|
|
* @uses phpDocumentor\Reflection\DocBlock |
39
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
40
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\Generic |
41
|
|
|
*/ |
42
|
|
|
public function testReconstructsADocCommentFromADocBlock() |
43
|
|
|
{ |
44
|
|
|
$expected = <<<'DOCCOMMENT' |
45
|
|
|
/** |
46
|
|
|
* This is a summary |
47
|
|
|
* |
48
|
|
|
* This is a description |
49
|
|
|
* |
50
|
|
|
* @unknown-tag Test description for the unknown tag |
51
|
|
|
*/ |
52
|
|
|
DOCCOMMENT; |
53
|
|
|
|
54
|
|
|
$fixture = new Serializer(); |
55
|
|
|
|
56
|
|
|
$docBlock = new DocBlock( |
57
|
|
|
'This is a summary', |
58
|
|
|
new Description('This is a description'), |
59
|
|
|
[ |
60
|
|
|
new DocBlock\Tags\Generic('unknown-tag', new Description('Test description for the unknown tag')) |
61
|
|
|
] |
62
|
|
|
); |
63
|
|
|
|
64
|
|
|
$this->assertSame($expected, $fixture->getDocComment($docBlock)); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @covers ::__construct |
69
|
|
|
* @covers ::getDocComment |
70
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Description |
71
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter |
72
|
|
|
* @uses phpDocumentor\Reflection\DocBlock |
73
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
74
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\Generic |
75
|
|
|
*/ |
76
|
|
|
public function testAddPrefixToDocBlock() |
77
|
|
|
{ |
78
|
|
|
$expected = <<<'DOCCOMMENT' |
79
|
|
|
aa/** |
80
|
|
|
aa * This is a summary |
81
|
|
|
aa * |
82
|
|
|
aa * This is a description |
83
|
|
|
aa * |
84
|
|
|
aa * @unknown-tag Test description for the unknown tag |
85
|
|
|
aa */ |
86
|
|
|
DOCCOMMENT; |
87
|
|
|
|
88
|
|
|
$fixture = new Serializer(2, 'a'); |
89
|
|
|
|
90
|
|
|
$docBlock = new DocBlock( |
91
|
|
|
'This is a summary', |
92
|
|
|
new Description('This is a description'), |
93
|
|
|
[ |
94
|
|
|
new DocBlock\Tags\Generic('unknown-tag', new Description('Test description for the unknown tag')) |
95
|
|
|
] |
96
|
|
|
); |
97
|
|
|
|
98
|
|
|
$this->assertSame($expected, $fixture->getDocComment($docBlock)); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @covers ::__construct |
103
|
|
|
* @covers ::getDocComment |
104
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Description |
105
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter |
106
|
|
|
* @uses phpDocumentor\Reflection\DocBlock |
107
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
108
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\Generic |
109
|
|
|
*/ |
110
|
|
|
public function testAddPrefixToDocBlockExceptFirstLine() |
111
|
|
|
{ |
112
|
|
|
$expected = <<<'DOCCOMMENT' |
113
|
|
|
/** |
114
|
|
|
aa * This is a summary |
115
|
|
|
aa * |
116
|
|
|
aa * This is a description |
117
|
|
|
aa * |
118
|
|
|
aa * @unknown-tag Test description for the unknown tag |
119
|
|
|
aa */ |
120
|
|
|
DOCCOMMENT; |
121
|
|
|
|
122
|
|
|
$fixture = new Serializer(2, 'a', false); |
123
|
|
|
|
124
|
|
|
$docBlock = new DocBlock( |
125
|
|
|
'This is a summary', |
126
|
|
|
new Description('This is a description'), |
127
|
|
|
[ |
128
|
|
|
new DocBlock\Tags\Generic('unknown-tag', new Description('Test description for the unknown tag')) |
129
|
|
|
] |
130
|
|
|
); |
131
|
|
|
|
132
|
|
|
$this->assertSame($expected, $fixture->getDocComment($docBlock)); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @covers ::__construct |
137
|
|
|
* @covers ::getDocComment |
138
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Description |
139
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter |
140
|
|
|
* @uses phpDocumentor\Reflection\DocBlock |
141
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
142
|
|
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\Generic |
143
|
|
|
*/ |
144
|
|
|
public function testWordwrapsAroundTheGivenAmountOfCharacters() |
145
|
|
|
{ |
146
|
|
|
$expected = <<<'DOCCOMMENT' |
147
|
|
|
/** |
148
|
|
|
* This is a |
149
|
|
|
* summary |
150
|
|
|
* |
151
|
|
|
* This is a |
152
|
|
|
* description |
153
|
|
|
* |
154
|
|
|
* @unknown-tag |
155
|
|
|
* Test |
156
|
|
|
* description |
157
|
|
|
* for the |
158
|
|
|
* unknown tag |
159
|
|
|
*/ |
160
|
|
|
DOCCOMMENT; |
161
|
|
|
|
162
|
|
|
$fixture = new Serializer(0, '', true, 15); |
163
|
|
|
|
164
|
|
|
$docBlock = new DocBlock( |
165
|
|
|
'This is a summary', |
166
|
|
|
new Description('This is a description'), |
167
|
|
|
[ |
168
|
|
|
new DocBlock\Tags\Generic('unknown-tag', new Description('Test description for the unknown tag')) |
169
|
|
|
] |
170
|
|
|
); |
171
|
|
|
|
172
|
|
|
$this->assertSame($expected, $fixture->getDocComment($docBlock)); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* @covers ::__construct |
177
|
|
|
* @expectedException \InvalidArgumentException |
178
|
|
|
*/ |
179
|
|
|
public function testInitializationFailsIfIndentIsNotAnInteger() |
180
|
|
|
{ |
181
|
|
|
new Serializer([]); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
/** |
185
|
|
|
* @covers ::__construct |
186
|
|
|
* @expectedException \InvalidArgumentException |
187
|
|
|
*/ |
188
|
|
|
public function testInitializationFailsIfIndentStringIsNotAString() |
189
|
|
|
{ |
190
|
|
|
new Serializer(0, []); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* @covers ::__construct |
195
|
|
|
* @expectedException \InvalidArgumentException |
196
|
|
|
*/ |
197
|
|
|
public function testInitializationFailsIfIndentFirstLineIsNotABoolean() |
198
|
|
|
{ |
199
|
|
|
new Serializer(0, '', []); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @covers ::__construct |
204
|
|
|
* @expectedException \InvalidArgumentException |
205
|
|
|
*/ |
206
|
|
|
public function testInitializationFailsIfLineLengthIsNotNullNorAnInteger() |
207
|
|
|
{ |
208
|
|
|
new Serializer(0, '', false, []); |
209
|
|
|
} |
210
|
|
|
} |
211
|
|
|
|