Completed
Pull Request — master (#145)
by Chuck
05:03
created

testWordwrapsAroundTheGivenAmountOfCharacters()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

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