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; |
15
|
|
|
|
16
|
|
|
use Mockery as m; |
17
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter; |
18
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Generic; |
19
|
|
|
use PHPUnit\Framework\TestCase; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Description |
23
|
|
|
*/ |
24
|
|
|
class DescriptionTest 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
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic |
36
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
37
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter |
38
|
|
|
* |
39
|
|
|
* @covers ::__construct |
40
|
|
|
* @covers ::render |
41
|
|
|
*/ |
42
|
|
|
public function testDescriptionCanRenderUsingABodyWithPlaceholdersAndTags() : void |
43
|
|
|
{ |
44
|
|
|
$body = 'This is a %1$s body.'; |
45
|
|
|
$expected = 'This is a {@internal significant} body.'; |
46
|
|
|
$tags = [new Generic('internal', new Description('significant '))]; |
47
|
|
|
|
48
|
|
|
$fixture = new Description($body, $tags); |
49
|
|
|
|
50
|
|
|
// without formatter (thus the PassthroughFormatter by default) |
51
|
|
|
$this->assertSame($expected, $fixture->render()); |
52
|
|
|
|
53
|
|
|
// with a custom formatter |
54
|
|
|
$formatter = m::mock(PassthroughFormatter::class); |
55
|
|
|
$formatter->shouldReceive('format')->with($tags[0])->andReturn('@internal significant'); |
56
|
|
|
$this->assertSame($expected, $fixture->render($formatter)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic |
61
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
62
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter |
63
|
|
|
* |
64
|
|
|
* @covers ::__construct |
65
|
|
|
* @covers ::render |
66
|
|
|
* @covers ::__toString |
67
|
|
|
*/ |
68
|
|
|
public function testDescriptionCanBeCastToString() : void |
69
|
|
|
{ |
70
|
|
|
$body = 'This is a %1$s body.'; |
71
|
|
|
$expected = 'This is a {@internal significant} body.'; |
72
|
|
|
$tags = [new Generic('internal', new Description('significant '))]; |
73
|
|
|
|
74
|
|
|
$fixture = new Description($body, $tags); |
75
|
|
|
|
76
|
|
|
$this->assertSame($expected, (string) $fixture); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic |
81
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
82
|
|
|
* |
83
|
|
|
* @covers ::getTags |
84
|
|
|
*/ |
85
|
|
|
public function testDescriptionTagsGetter() : void |
86
|
|
|
{ |
87
|
|
|
$body = '@JoinTable(name="table", joinColumns=%1$s, inverseJoinColumns=%2$s)'; |
88
|
|
|
|
89
|
|
|
$tag1 = new Generic('JoinColumn', new Description('(name="column_id", referencedColumnName="id")')); |
90
|
|
|
$tag2 = new Generic('JoinColumn', new Description('(name="column_id_2", referencedColumnName="id")')); |
91
|
|
|
|
92
|
|
|
$tags = [ |
93
|
|
|
$tag1, |
94
|
|
|
$tag2, |
95
|
|
|
]; |
96
|
|
|
|
97
|
|
|
$fixture = new Description($body, $tags); |
98
|
|
|
|
99
|
|
|
$this->assertCount(2, $fixture->getTags()); |
100
|
|
|
|
101
|
|
|
$actualTags = $fixture->getTags(); |
102
|
|
|
$this->assertSame($tags, $actualTags); |
103
|
|
|
$this->assertSame($tag1, $actualTags[0]); |
104
|
|
|
$this->assertSame($tag2, $actualTags[1]); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @covers ::getBodyTemplate |
109
|
|
|
*/ |
110
|
|
|
public function testDescriptionBodyTemplateGetter() : void |
111
|
|
|
{ |
112
|
|
|
$body = 'See https://github.com/phpDocumentor/ReflectionDocBlock/pull/171 for more information'; |
113
|
|
|
|
114
|
|
|
$fixture = new Description($body, []); |
115
|
|
|
|
116
|
|
|
$this->assertSame($body, $fixture->getBodyTemplate()); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic |
121
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
122
|
|
|
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter |
123
|
|
|
* |
124
|
|
|
* @covers ::__construct |
125
|
|
|
* @covers ::render |
126
|
|
|
* @covers ::__toString |
127
|
|
|
*/ |
128
|
|
|
public function testDescriptionMultipleTagsCanBeCastToString() : void |
129
|
|
|
{ |
130
|
|
|
$body = '@JoinTable(name="table", joinColumns=%1$s, inverseJoinColumns=%2$s)'; |
131
|
|
|
|
132
|
|
|
$tag1 = new Generic('JoinColumn', new Description('(name="column_id", referencedColumnName="id")')); |
133
|
|
|
$tag2 = new Generic('JoinColumn', new Description('(name="column_id_2", referencedColumnName="id")')); |
134
|
|
|
|
135
|
|
|
$tags = [ |
136
|
|
|
$tag1, |
137
|
|
|
$tag2, |
138
|
|
|
]; |
139
|
|
|
|
140
|
|
|
$fixture = new Description($body, $tags); |
141
|
|
|
$expected = '@JoinTable(name="table", joinColumns={@JoinColumn (name="column_id", referencedColumnName="id")}, ' |
142
|
|
|
. 'inverseJoinColumns={@JoinColumn (name="column_id_2", referencedColumnName="id")})'; |
143
|
|
|
$this->assertSame($expected, (string) $fixture); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
|