Yaffs site version 1.1
[yaffs-website] / vendor / phpdocumentor / reflection-docblock / tests / phpDocumentor / Reflection / DocBlock / TagTest.php
1 <?php
2 /**
3  * phpDocumentor Var Tag Test
4  * 
5  * PHP version 5.3
6  *
7  * @author    Daniel O'Connor <daniel.oconnor@gmail.com>
8  * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
9  * @license   http://www.opensource.org/licenses/mit-license.php MIT
10  * @link      http://phpdoc.org
11  */
12
13 namespace phpDocumentor\Reflection\DocBlock;
14
15 use phpDocumentor\Reflection\DocBlock;
16 use phpDocumentor\Reflection\DocBlock\Context;
17
18 /**
19  * Test class for \phpDocumentor\Reflection\DocBlock\Tag\VarTag
20  *
21  * @author    Daniel O'Connor <daniel.oconnor@gmail.com>
22  * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
23  * @license   http://www.opensource.org/licenses/mit-license.php MIT
24  * @link      http://phpdoc.org
25  */
26 class TagTest extends \PHPUnit_Framework_TestCase
27 {
28     
29     /**
30      * @expectedException \InvalidArgumentException
31      * 
32      * @return void
33      */
34     public function testInvalidTagLine()
35     {
36         Tag::createInstance('Invalid tag line');
37     }
38
39     /**
40      * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
41      * 
42      * @return void
43      */
44     public function testTagHandlerUnregistration()
45     {
46         $currentHandler = __NAMESPACE__ . '\Tag\VarTag';
47         $tagPreUnreg = Tag::createInstance('@var mixed');
48         $this->assertInstanceOf(
49             $currentHandler,
50             $tagPreUnreg
51         );
52         $this->assertInstanceOf(
53             __NAMESPACE__ . '\Tag',
54             $tagPreUnreg
55         );
56
57         Tag::registerTagHandler('var', null);
58
59         $tagPostUnreg = Tag::createInstance('@var mixed');
60         $this->assertNotInstanceOf(
61             $currentHandler,
62             $tagPostUnreg
63         );
64         $this->assertInstanceOf(
65             __NAMESPACE__ . '\Tag',
66             $tagPostUnreg
67         );
68
69         Tag::registerTagHandler('var', $currentHandler);
70     }
71
72     /**
73      * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
74      * 
75      * @return void
76      */
77     public function testTagHandlerCorrectRegistration()
78     {
79         if (0 == ini_get('allow_url_include')) {
80             $this->markTestSkipped('"data" URIs for includes are required.');
81         }
82         $currentHandler = __NAMESPACE__ . '\Tag\VarTag';
83         $tagPreReg = Tag::createInstance('@var mixed');
84         $this->assertInstanceOf(
85             $currentHandler,
86             $tagPreReg
87         );
88         $this->assertInstanceOf(
89             __NAMESPACE__ . '\Tag',
90             $tagPreReg
91         );
92
93         include 'data:text/plain;base64,'. base64_encode(
94 <<<TAG_HANDLER
95 <?php
96     class MyTagHandler extends \phpDocumentor\Reflection\DocBlock\Tag {}
97 TAG_HANDLER
98         );
99
100         $this->assertTrue(Tag::registerTagHandler('var', '\MyTagHandler'));
101
102         $tagPostReg = Tag::createInstance('@var mixed');
103         $this->assertNotInstanceOf(
104             $currentHandler,
105             $tagPostReg
106         );
107         $this->assertInstanceOf(
108             __NAMESPACE__ . '\Tag',
109             $tagPostReg
110         );
111         $this->assertInstanceOf(
112             '\MyTagHandler',
113             $tagPostReg
114         );
115
116         $this->assertTrue(Tag::registerTagHandler('var', $currentHandler));
117     }
118     
119     /**
120      * @depends testTagHandlerCorrectRegistration
121      * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
122      * @covers \phpDocumentor\Reflection\DocBlock\Tag::createInstance
123      * 
124      * @return void
125      */
126     public function testNamespacedTagHandlerCorrectRegistration()
127     {
128         $tagPreReg = Tag::createInstance('@T something');
129         $this->assertInstanceOf(
130             __NAMESPACE__ . '\Tag',
131             $tagPreReg
132         );
133         $this->assertNotInstanceOf(
134             '\MyTagHandler',
135             $tagPreReg
136         );
137
138         $this->assertTrue(
139             Tag::registerTagHandler('\MyNamespace\MyTag', '\MyTagHandler')
140         );
141
142         $tagPostReg = Tag::createInstance(
143             '@T something',
144             new DocBlock(
145                 '',
146                 new Context('', array('T' => '\MyNamespace\MyTag'))
147             )
148         );
149         $this->assertInstanceOf(
150             __NAMESPACE__ . '\Tag',
151             $tagPostReg
152         );
153         $this->assertInstanceOf(
154             '\MyTagHandler',
155             $tagPostReg
156         );
157
158         $this->assertTrue(
159             Tag::registerTagHandler('\MyNamespace\MyTag', null)
160         );
161     }
162     
163     /**
164      * @depends testTagHandlerCorrectRegistration
165      * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
166      * @covers \phpDocumentor\Reflection\DocBlock\Tag::createInstance
167      * 
168      * @return void
169      */
170     public function testNamespacedTagHandlerIncorrectRegistration()
171     {
172         $tagPreReg = Tag::createInstance('@T something');
173         $this->assertInstanceOf(
174             __NAMESPACE__ . '\Tag',
175             $tagPreReg
176         );
177         $this->assertNotInstanceOf(
178             '\MyTagHandler',
179             $tagPreReg
180         );
181
182         $this->assertFalse(
183             Tag::registerTagHandler('MyNamespace\MyTag', '\MyTagHandler')
184         );
185
186         $tagPostReg = Tag::createInstance(
187             '@T something',
188             new DocBlock(
189                 '',
190                 new Context('', array('T' => '\MyNamespace\MyTag'))
191             )
192         );
193         $this->assertInstanceOf(
194             __NAMESPACE__ . '\Tag',
195             $tagPostReg
196         );
197         $this->assertNotInstanceOf(
198             '\MyTagHandler',
199             $tagPostReg
200         );
201     }
202
203     /**
204      * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
205      * 
206      * @return void
207      */
208     public function testNonExistentTagHandlerRegistration()
209     {
210         $currentHandler = __NAMESPACE__ . '\Tag\VarTag';
211         $tagPreReg = Tag::createInstance('@var mixed');
212         $this->assertInstanceOf(
213             $currentHandler,
214             $tagPreReg
215         );
216         $this->assertInstanceOf(
217             __NAMESPACE__ . '\Tag',
218             $tagPreReg
219         );
220
221         $this->assertFalse(Tag::registerTagHandler('var', 'Non existent'));
222
223         $tagPostReg = Tag::createInstance('@var mixed');
224         $this->assertInstanceOf(
225             $currentHandler,
226             $tagPostReg
227         );
228         $this->assertInstanceOf(
229             __NAMESPACE__ . '\Tag',
230             $tagPostReg
231         );
232     }
233
234     /**
235      * @covers \phpDocumentor\Reflection\DocBlock\Tag::registerTagHandler
236      * 
237      * @return void
238      */
239     public function testIncompatibleTagHandlerRegistration()
240     {
241         $currentHandler = __NAMESPACE__ . '\Tag\VarTag';
242         $tagPreReg = Tag::createInstance('@var mixed');
243         $this->assertInstanceOf(
244             $currentHandler,
245             $tagPreReg
246         );
247         $this->assertInstanceOf(
248             __NAMESPACE__ . '\Tag',
249             $tagPreReg
250         );
251
252         $this->assertFalse(
253             Tag::registerTagHandler('var', __NAMESPACE__ . '\TagTest')
254         );
255
256         $tagPostReg = Tag::createInstance('@var mixed');
257         $this->assertInstanceOf(
258             $currentHandler,
259             $tagPostReg
260         );
261         $this->assertInstanceOf(
262             __NAMESPACE__ . '\Tag',
263             $tagPostReg
264         );
265     }
266
267     /**
268      * Test that the \phpDocumentor\Reflection\DocBlock\Tag\VarTag can
269      * understand the @var doc block.
270      *
271      * @param string $type
272      * @param string $content
273      * @param string $exDescription
274      *
275      * @covers \phpDocumentor\Reflection\DocBlock\Tag
276      * @dataProvider provideDataForConstuctor
277      *
278      * @return void
279      */
280     public function testConstructorParesInputsIntoCorrectFields(
281         $type,
282         $content,
283         $exDescription
284     ) {
285         $tag = new Tag($type, $content);
286
287         $this->assertEquals($type, $tag->getName());
288         $this->assertEquals($content, $tag->getContent());
289         $this->assertEquals($exDescription, $tag->getDescription());
290     }
291
292     /**
293      * Data provider for testConstructorParesInputsIntoCorrectFields
294      *
295      * @return array
296      */
297     public function provideDataForConstuctor()
298     {
299         // $type, $content, $exDescription
300         return array(
301             array(
302                 'unknown',
303                 'some content',
304                 'some content',
305             ),
306             array(
307                 'unknown',
308                 '',
309                 '',
310             )
311         );
312     }
313 }