3 namespace Doctrine\Tests\Common\Annotations;
5 use Doctrine\Common\Annotations\DocLexer;
7 class DocLexerTest extends \PHPUnit_Framework_TestCase
9 public function testMarkerAnnotation()
11 $lexer = new DocLexer;
13 $lexer->setInput("@Name");
14 $this->assertNull($lexer->token);
15 $this->assertNull($lexer->lookahead);
17 $this->assertTrue($lexer->moveNext());
18 $this->assertNull($lexer->token);
19 $this->assertEquals('@', $lexer->lookahead['value']);
21 $this->assertTrue($lexer->moveNext());
22 $this->assertEquals('@', $lexer->token['value']);
23 $this->assertEquals('Name', $lexer->lookahead['value']);
25 $this->assertFalse($lexer->moveNext());
28 public function testScannerTokenizesDocBlockWhitConstants()
30 $lexer = new DocLexer();
31 $docblock = '@AnnotationWithConstants(PHP_EOL, ClassWithConstants::SOME_VALUE, \Doctrine\Tests\Common\Annotations\Fixtures\IntefaceWithConstants::SOME_VALUE)';
37 'type' => DocLexer::T_AT,
40 'value' => 'AnnotationWithConstants',
42 'type' => DocLexer::T_IDENTIFIER,
47 'type' => DocLexer::T_OPEN_PARENTHESIS,
52 'type' => DocLexer::T_IDENTIFIER,
57 'type' => DocLexer::T_COMMA,
60 'value' => 'ClassWithConstants::SOME_VALUE',
62 'type' => DocLexer::T_IDENTIFIER,
67 'type' => DocLexer::T_COMMA,
70 'value' => '\\Doctrine\\Tests\\Common\\Annotations\\Fixtures\\IntefaceWithConstants::SOME_VALUE',
72 'type' => DocLexer::T_IDENTIFIER,
77 'type' => DocLexer::T_CLOSE_PARENTHESIS,
82 $lexer->setInput($docblock);
84 foreach ($tokens as $expected) {
86 $lookahead = $lexer->lookahead;
87 $this->assertEquals($expected['value'], $lookahead['value']);
88 $this->assertEquals($expected['type'], $lookahead['type']);
89 $this->assertEquals($expected['position'], $lookahead['position']);
92 $this->assertFalse($lexer->moveNext());
96 public function testScannerTokenizesDocBlockWhitInvalidIdentifier()
98 $lexer = new DocLexer();
99 $docblock = '@Foo\3.42';
105 'type' => DocLexer::T_AT,
110 'type' => DocLexer::T_IDENTIFIER,
115 'type' => DocLexer::T_NAMESPACE_SEPARATOR,
120 'type' => DocLexer::T_FLOAT,
124 $lexer->setInput($docblock);
126 foreach ($tokens as $expected) {
128 $lookahead = $lexer->lookahead;
129 $this->assertEquals($expected['value'], $lookahead['value']);
130 $this->assertEquals($expected['type'], $lookahead['type']);
131 $this->assertEquals($expected['position'], $lookahead['position']);
134 $this->assertFalse($lexer->moveNext());