Completed
Push — master ( 25ec30...cd3bee )
by Chuck
11s
created

InterpretingDocBlocksTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A tearDown() 0 4 1
B testInterpretingSummaryWithEllipsis() 0 24 1
B testInterpretingASimpleDocBlock() 0 24 1
B testInterpretingTags() 0 24 1
B testDescriptionsCanEscapeAtSignsAndClosingBraces() 0 31 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;
15
16
use Mockery as m;
17
use phpDocumentor\Reflection\DocBlock\Description;
18
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
19
use phpDocumentor\Reflection\DocBlock\Tag;
20
use phpDocumentor\Reflection\DocBlock\Tags\See;
21
use PHPUnit\Framework\TestCase;
22
23
/**
24
 * @coversNothing
25
 */
26
class InterpretingDocBlocksTest extends TestCase
27
{
28
    /**
29
     * Call Mockery::close after each test.
30
     */
31
    public function tearDown(): void
32
    {
33
        m::close();
34
    }
35
36
    public function testInterpretingSummaryWithEllipsis(): void
37
    {
38
        $docblock = <<<DOCBLOCK
39
/**
40
 * This is a short (...) description.
41
 *
42
 * This is a long description.
43
 *
44
 * @return void
45
 */
46
DOCBLOCK;
47
48
        $factory = DocBlockFactory::createInstance();
49
        $phpdoc = $factory->create($docblock);
50
51
        $summary = 'This is a short (...) description.';
52
        $description = 'This is a long description.';
53
54
        $this->assertInstanceOf(DocBlock::class, $phpdoc);
55
        $this->assertSame($summary, $phpdoc->getSummary());
56
        $this->assertSame($description, $phpdoc->getDescription()->render());
57
        $this->assertCount(1, $phpdoc->getTags());
58
        $this->assertTrue($phpdoc->hasTag('return'));
59
    }
60
61
    public function testInterpretingASimpleDocBlock(): void
62
    {
63
        /** @var DocBlock $docblock */
64
        $docblock;
65
        /** @var string $summary */
66
        $summary;
67
        /** @var Description $description */
68
        $description;
69
70
        include(__DIR__ . '/../../examples/01-interpreting-a-simple-docblock.php');
71
72
        $descriptionText = <<<DESCRIPTION
73
This is a Description. A Summary and Description are separated by either
74
two subsequent newlines (thus a whiteline in between as can be seen in this
75
example), or when the Summary ends with a dot (`.`) and some form of
76
whitespace.
77
DESCRIPTION;
78
79
        $this->assertInstanceOf(DocBlock::class, $docblock);
80
        $this->assertSame('This is an example of a summary.', $summary);
81
        $this->assertInstanceOf(Description::class, $description);
82
        $this->assertSame($descriptionText, $description->render());
83
        $this->assertEmpty($docblock->getTags());
84
    }
85
86
    public function testInterpretingTags(): void
87
    {
88
        /** @var DocBlock $docblock */
89
        $docblock;
90
        /** @var boolean $hasSeeTag */
91
        $hasSeeTag;
92
        /** @var Tag[] $tags */
93
        $tags;
94
        /** @var See[] $seeTags */
95
        $seeTags;
96
97
        include(__DIR__ . '/../../examples/02-interpreting-tags.php');
98
99
        $this->assertTrue($hasSeeTag);
100
        $this->assertCount(1, $tags);
101
        $this->assertCount(1, $seeTags);
102
103
        $this->assertInstanceOf(See::class, $tags[0]);
104
        $this->assertInstanceOf(See::class, $seeTags[0]);
105
106
        $seeTag = $seeTags[0];
107
        $this->assertSame('\\' . StandardTagFactory::class, (string) $seeTag->getReference());
108
        $this->assertSame('', (string) $seeTag->getDescription());
109
    }
110
111
    public function testDescriptionsCanEscapeAtSignsAndClosingBraces(): void
112
    {
113
        /** @var string $docComment */
114
        $docComment;
115
        /** @var DocBlock $docblock */
116
        $docblock;
117
        /** @var Description $description */
118
        $description;
119
        /** @var string $receivedDocComment */
120
        $receivedDocComment;
121
        /** @var string $foundDescription */
122
        $foundDescription;
123
124
        include(__DIR__ . '/../../examples/playing-with-descriptions/02-escaping.php');
125
126
        $this->assertSame(
127
            <<<'DESCRIPTION'
128
You can escape the @-sign by surrounding it with braces, for example: @. And escape a closing brace within an
129
inline tag by adding an opening brace in front of it like this: }.
130
131
Here are example texts where you can see how they could be used in a real life situation:
132
133
    This is a text with an {@internal inline tag where a closing brace (}) is shown}.
134
    Or an {@internal inline tag with a literal {@link} in it}.
135
136
Do note that an {@internal inline tag that has an opening brace ({) does not break out}.
137
DESCRIPTION
138
            ,
139
            $foundDescription
140
        );
141
    }
142
}
143