Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / common / tests / Doctrine / Tests / Common / Annotations / DocLexerTest.php
1 <?php
2
3 namespace Doctrine\Tests\Common\Annotations;
4
5 use Doctrine\Common\Annotations\DocLexer;
6
7 class DocLexerTest extends \PHPUnit_Framework_TestCase
8 {
9     public function testMarkerAnnotation()
10     {
11         $lexer = new DocLexer;
12
13         $lexer->setInput("@Name");
14         $this->assertNull($lexer->token);
15         $this->assertNull($lexer->lookahead);
16
17         $this->assertTrue($lexer->moveNext());
18         $this->assertNull($lexer->token);
19         $this->assertEquals('@', $lexer->lookahead['value']);
20
21         $this->assertTrue($lexer->moveNext());
22         $this->assertEquals('@', $lexer->token['value']);
23         $this->assertEquals('Name', $lexer->lookahead['value']);
24
25         $this->assertFalse($lexer->moveNext());
26     }
27
28     public function testScannerTokenizesDocBlockWhitConstants()
29     {
30         $lexer      = new DocLexer();
31         $docblock   = '@AnnotationWithConstants(PHP_EOL, ClassWithConstants::SOME_VALUE, \Doctrine\Tests\Common\Annotations\Fixtures\IntefaceWithConstants::SOME_VALUE)';
32
33         $tokens = array (
34             array(
35                 'value'     => '@',
36                 'position'  => 0,
37                 'type'      => DocLexer::T_AT,
38             ),
39             array(
40                 'value'     => 'AnnotationWithConstants',
41                 'position'  => 1,
42                 'type'      => DocLexer::T_IDENTIFIER,
43             ),
44             array(
45                 'value'     => '(',
46                 'position'  => 24,
47                 'type'      => DocLexer::T_OPEN_PARENTHESIS,
48             ),
49             array(
50                 'value'     => 'PHP_EOL',
51                 'position'  => 25,
52                 'type'      => DocLexer::T_IDENTIFIER,
53             ),
54             array(
55                 'value'     => ',',
56                 'position'  => 32,
57                 'type'      => DocLexer::T_COMMA,
58             ),
59             array(
60                 'value'     => 'ClassWithConstants::SOME_VALUE',
61                 'position'  => 34,
62                 'type'      => DocLexer::T_IDENTIFIER,
63             ),
64             array(
65                 'value'     => ',',
66                 'position'  => 64,
67                 'type'      => DocLexer::T_COMMA,
68             ),
69             array(
70                 'value'     => '\\Doctrine\\Tests\\Common\\Annotations\\Fixtures\\IntefaceWithConstants::SOME_VALUE',
71                 'position'  => 66,
72                 'type'      => DocLexer::T_IDENTIFIER,
73             ),
74             array(
75                 'value'     => ')',
76                 'position'  => 143,
77                 'type'      => DocLexer::T_CLOSE_PARENTHESIS,
78             )
79
80         );
81
82         $lexer->setInput($docblock);
83
84         foreach ($tokens as $expected) {
85             $lexer->moveNext();
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']);
90         }
91
92         $this->assertFalse($lexer->moveNext());
93     }
94
95
96     public function testScannerTokenizesDocBlockWhitInvalidIdentifier()
97     {
98         $lexer      = new DocLexer();
99         $docblock   = '@Foo\3.42';
100
101         $tokens = array (
102             array(
103                 'value'     => '@',
104                 'position'  => 0,
105                 'type'      => DocLexer::T_AT,
106             ),
107             array(
108                 'value'     => 'Foo',
109                 'position'  => 1,
110                 'type'      => DocLexer::T_IDENTIFIER,
111             ),
112             array(
113                 'value'     => '\\',
114                 'position'  => 4,
115                 'type'      => DocLexer::T_NAMESPACE_SEPARATOR,
116             ),
117             array(
118                 'value'     => 3.42,
119                 'position'  => 5,
120                 'type'      => DocLexer::T_FLOAT,
121             )
122         );
123
124         $lexer->setInput($docblock);
125
126         foreach ($tokens as $expected) {
127             $lexer->moveNext();
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']);
132         }
133
134         $this->assertFalse($lexer->moveNext());
135     }
136
137 }