Completed
Pull Request — master (#134)
by Tomáš
01:18
created

InterpretingDocBlocksTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 83
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of phpDocumentor.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2010-2015 Mike van Riel<[email protected]>
9
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 * @link      http://phpdoc.org
11
 */
12
13
namespace phpDocumentor\Reflection;
14
15
use Mockery as m;
16
use phpDocumentor\Reflection\DocBlock\Description;
17
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
18
use phpDocumentor\Reflection\DocBlock\Tag;
19
use phpDocumentor\Reflection\DocBlock\Tags\See;
20
use PHPUnit\Framework\TestCase;
21
22
/**
23
 * @coversNothing
24
 */
25
class InterpretingDocBlocksTest extends TestCase
26
{
27
    /**
28
     * Call Mockery::close after each test.
29
     */
30
    public function tearDown()
31
    {
32
        m::close();
33
    }
34
35
    public function testInterpretingASimpleDocBlock()
36
    {
37
        /**
38
         * @var DocBlock    $docblock
39
         * @var string      $summary
40
         * @var Description $description
41
         */
42
        include(__DIR__ . '/../../examples/01-interpreting-a-simple-docblock.php');
43
44
        $descriptionText = <<<DESCRIPTION
45
This is a Description. A Summary and Description are separated by either
46
two subsequent newlines (thus a whiteline in between as can be seen in this
47
example), or when the Summary ends with a dot (`.`) and some form of
48
whitespace.
49
DESCRIPTION;
50
51
        $this->assertInstanceOf(DocBlock::class, $docblock);
52
        $this->assertSame('This is an example of a summary.', $summary);
53
        $this->assertInstanceOf(Description::class, $description);
54
        $this->assertSame($descriptionText, $description->render());
55
        $this->assertEmpty($docblock->getTags());
56
    }
57
58
    public function testInterpretingTags()
59
    {
60
        /**
61
         * @var DocBlock $docblock
62
         * @var boolean  $hasSeeTag
63
         * @var Tag[]    $tags
64
         * @var See[]    $seeTags
65
         */
66
        include(__DIR__ . '/../../examples/02-interpreting-tags.php');
67
68
        $this->assertTrue($hasSeeTag);
69
        $this->assertCount(1, $tags);
70
        $this->assertCount(1, $seeTags);
71
72
        $this->assertInstanceOf(See::class, $tags[0]);
73
        $this->assertInstanceOf(See::class, $seeTags[0]);
74
75
        $seeTag = $seeTags[0];
76
        $this->assertSame('\\' . StandardTagFactory::class, (string)$seeTag->getReference());
77
        $this->assertSame('', (string)$seeTag->getDescription());
78
    }
79
80
    public function testDescriptionsCanEscapeAtSignsAndClosingBraces()
81
    {
82
        /**
83
         * @var string      $docComment
84
         * @var DocBlock    $docblock
85
         * @var Description $description
86
         * @var string      $receivedDocComment
87
         * @var string      $foundDescription
88
         */
89
90
        include(__DIR__ . '/../../examples/playing-with-descriptions/02-escaping.php');
91
        $this->assertSame(
92
            <<<'DESCRIPTION'
93
You can escape the @-sign by surrounding it with braces, for example: @. And escape a closing brace within an
94
inline tag by adding an opening brace in front of it like this: }.
95
96
Here are example texts where you can see how they could be used in a real life situation:
97
98
    This is a text with an {@internal inline tag where a closing brace (}) is shown}.
99
    Or an {@internal inline tag with a literal {@link} in it}.
100
101
Do note that an {@internal inline tag that has an opening brace ({) does not break out}.
102
DESCRIPTION
103
            ,
104
            $foundDescription
105
        );
106
    }
107
}
108