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

DescriptionTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 5
dl 0
loc 105
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 4 1
A testDescriptionCanRenderUsingABodyWithPlaceholdersAndTags() 0 16 1
A testDescriptionCanBeCastToString() 0 10 1
A testDescriptionTagsGetter() 0 21 1
A testDescriptionMultipleTagsCanBeCastToString() 0 16 1
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\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
     * @covers ::__construct
36
     * @covers ::render
37
     * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic
38
     * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
39
     * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
40
     */
41
    public function testDescriptionCanRenderUsingABodyWithPlaceholdersAndTags(): void
42
    {
43
        $body = 'This is a %1$s body.';
44
        $expected = 'This is a {@internal significant} body.';
45
        $tags = [new Generic('internal', new Description('significant '))];
46
47
        $fixture = new Description($body, $tags);
48
49
        // without formatter (thus the PassthroughFormatter by default)
50
        $this->assertSame($expected, $fixture->render());
51
52
        // with a custom formatter
53
        $formatter = m::mock(PassthroughFormatter::class);
54
        $formatter->shouldReceive('format')->with($tags[0])->andReturn('@internal significant');
55
        $this->assertSame($expected, $fixture->render($formatter));
56
    }
57
58
    /**
59
     * @covers ::__construct
60
     * @covers ::render
61
     * @covers ::__toString
62
     * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic
63
     * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
64
     * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
65
     */
66
    public function testDescriptionCanBeCastToString(): void
67
    {
68
        $body = 'This is a %1$s body.';
69
        $expected = 'This is a {@internal significant} body.';
70
        $tags = [new Generic('internal', new Description('significant '))];
71
72
        $fixture = new Description($body, $tags);
73
74
        $this->assertSame($expected, (string) $fixture);
75
    }
76
77
    /**
78
     * @covers ::getTags
79
     * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic
80
     * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
81
     */
82
    public function testDescriptionTagsGetter(): void
83
    {
84
        $body = '@JoinTable(name="table", joinColumns=%1$s, inverseJoinColumns=%2$s)';
85
86
        $tag1 = new Generic('JoinColumn', new Description('(name="column_id", referencedColumnName="id")'));
87
        $tag2 = new Generic('JoinColumn', new Description('(name="column_id_2", referencedColumnName="id")'));
88
89
        $tags = [
90
            $tag1,
91
            $tag2,
92
        ];
93
94
        $fixture = new Description($body, $tags);
95
96
        $this->assertCount(2, $fixture->getTags());
97
98
        $actualTags = $fixture->getTags();
99
        $this->assertSame($tags, $actualTags);
100
        $this->assertSame($tag1, $actualTags[0]);
101
        $this->assertSame($tag2, $actualTags[1]);
102
    }
103
104
    /**
105
     * @covers ::__construct
106
     * @covers ::render
107
     * @covers ::__toString
108
     * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic
109
     * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
110
     * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
111
     */
112
    public function testDescriptionMultipleTagsCanBeCastToString(): void
113
    {
114
        $body = '@JoinTable(name="table", joinColumns=%1$s, inverseJoinColumns=%2$s)';
115
116
        $tag1 = new Generic('JoinColumn', new Description('(name="column_id", referencedColumnName="id")'));
117
        $tag2 = new Generic('JoinColumn', new Description('(name="column_id_2", referencedColumnName="id")'));
118
119
        $tags = [
120
            $tag1,
121
            $tag2,
122
        ];
123
124
        $fixture = new Description($body, $tags);
125
        $expected = '@JoinTable(name="table", joinColumns={@JoinColumn (name="column_id", referencedColumnName="id")}, inverseJoinColumns={@JoinColumn (name="column_id_2", referencedColumnName="id")})';
126
        $this->assertSame($expected, (string) $fixture);
127
    }
128
}
129