Completed
Pull Request — master (#223)
by Jaap
07:24
created

DocblockLexerTest::testLexer()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace phpDocumentor\Reflection;
6
7
use PHPUnit\Framework\TestCase;
8
9
final class DocblockLexerTest extends TestCase
10
{
11
    /**
12
     * @dataProvider docblockProvider
13
     */
14
    public function testLexer(string $input, array $expectedTokens) : void
15
    {
16
        $lexer = new DocBlockLexer();
17
18
        $lexer->setInput($input);
19
        $lexer->moveNext();
20
21
        $tokens = [];
22
        while (true) {
23
            if (!$lexer->lookahead) {
24
                break;
25
            }
26
27
            $lexer->moveNext();
28
            $tokens[] = $lexer->token['type'];
29
        }
30
31
        $this->assertSame($expectedTokens, $tokens);
32
    }
33
34
    public function docblockProvider()
35
    {
36
        return [
37
            'empty single line docbloc' => [
38
                <<<DOCBLOCK
39
/** */
40
DOCBLOCK
41
                ,
42
                [
43
                    DocBlockLexer::T_START,
44
                    DocBlockLexer::T_END
45
                ]
46
            ],
47
            'empty docbloc' => [
48
                <<<DOCBLOCK
49
/**
50
 */
51
DOCBLOCK
52
                ,
53
                [
54
                    DocBlockLexer::T_START,
55
                    DocBlockLexer::T_CRLF,
56
                    DocBlockLexer::T_END
57
                ]
58
            ],
59
            'docblock with summary' => [
60
                <<<DOCBLOCK
61
/**
62
 * My docblock summary.
63
 */
64
DOCBLOCK
65
                ,
66
                [
67
                    DocBlockLexer::T_START,
68
                    DocBlockLexer::T_CRLF,
69
                    DocBlockLexer::T_LINE_START,
70
                    DocBlockLexer::T_WHITESPACE,
71
                    DocBlockLexer::T_STRING,
72
                    DocBlockLexer::T_WHITESPACE,
73
                    DocBlockLexer::T_STRING,
74
                    DocBlockLexer::T_WHITESPACE,
75
                    DocBlockLexer::T_STRING,
76
                    DocBlockLexer::T_DOT,
77
                    DocBlockLexer::T_CRLF,
78
                    DocBlockLexer::T_END
79
                ]
80
            ],
81
            'docblock simple tag' => [
82
                <<<DOCBLOCK
83
/**
84
 * @var
85
 */
86
DOCBLOCK
87
                ,
88
                [
89
                    DocBlockLexer::T_START,
90
                    DocBlockLexer::T_CRLF,
91
                    DocBlockLexer::T_LINE_START,
92
                    DocBlockLexer::T_WHITESPACE,
93
                    DocBlockLexer::T_AT,
94
                    DocBlockLexer::T_STRING,
95
                    DocBlockLexer::T_CRLF,
96
                    DocBlockLexer::T_END
97
                ]
98
            ],
99
            'docblock specialized tags' => [
100
        <<<DOCBLOCK
101
/**
102
 * @var:unittest
103
*/
104
DOCBLOCK
105
        ,
106
        [
107
            DocBlockLexer::T_START,
108
            DocBlockLexer::T_CRLF,
109
            DocBlockLexer::T_LINE_START,
110
            DocBlockLexer::T_WHITESPACE,
111
            DocBlockLexer::T_AT,
112
            DocBlockLexer::T_STRING,
113
            DocBlockLexer::T_COLON,
114
            DocBlockLexer::T_STRING,
115
            DocBlockLexer::T_CRLF,
116
            DocBlockLexer::T_END
117
        ]
118
    ]
119
        ];
120
    }
121
}
122