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

testInterpretingSummaryWithEllipsis()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
cc 1
eloc 13
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;
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
        /**
64
         * @var DocBlock    $docblock
65
         * @var string      $summary
66
         * @var Description $description
67
         */
68
        include(__DIR__ . '/../../examples/01-interpreting-a-simple-docblock.php');
69
70
        $descriptionText = <<<DESCRIPTION
71
This is a Description. A Summary and Description are separated by either
72
two subsequent newlines (thus a whiteline in between as can be seen in this
73
example), or when the Summary ends with a dot (`.`) and some form of
74
whitespace.
75
DESCRIPTION;
76
77
        $this->assertInstanceOf(DocBlock::class, $docblock);
78
        $this->assertSame('This is an example of a summary.', $summary);
79
        $this->assertInstanceOf(Description::class, $description);
80
        $this->assertSame($descriptionText, $description->render());
81
        $this->assertEmpty($docblock->getTags());
82
    }
83
84
    public function testInterpretingTags(): void
85
    {
86
        /**
87
         * @var DocBlock $docblock
88
         * @var boolean  $hasSeeTag
89
         * @var Tag[]    $tags
90
         * @var See[]    $seeTags
91
         */
92
        include(__DIR__ . '/../../examples/02-interpreting-tags.php');
93
94
        $this->assertTrue($hasSeeTag);
95
        $this->assertCount(1, $tags);
96
        $this->assertCount(1, $seeTags);
97
98
        $this->assertInstanceOf(See::class, $tags[0]);
99
        $this->assertInstanceOf(See::class, $seeTags[0]);
100
101
        $seeTag = $seeTags[0];
102
        $this->assertSame('\\' . StandardTagFactory::class, (string) $seeTag->getReference());
103
        $this->assertSame('', (string) $seeTag->getDescription());
104
    }
105
106
    public function testDescriptionsCanEscapeAtSignsAndClosingBraces(): void
107
    {
108
        /**
109
         * @var string      $docComment
110
         * @var DocBlock    $docblock
111
         * @var Description $description
112
         * @var string      $receivedDocComment
113
         * @var string      $foundDescription
114
         */
115
116
        include(__DIR__ . '/../../examples/playing-with-descriptions/02-escaping.php');
117
        $this->assertSame(
118
            <<<'DESCRIPTION'
119
You can escape the @-sign by surrounding it with braces, for example: @. And escape a closing brace within an
120
inline tag by adding an opening brace in front of it like this: }.
121
122
Here are example texts where you can see how they could be used in a real life situation:
123
124
    This is a text with an {@internal inline tag where a closing brace (}) is shown}.
125
    Or an {@internal inline tag with a literal {@link} in it}.
126
127
Do note that an {@internal inline tag that has an opening brace ({) does not break out}.
128
DESCRIPTION
129
            ,
130
            $foundDescription
131
        );
132
    }
133
}
134