Yaffs site version 1.1
[yaffs-website] / vendor / phpdocumentor / reflection-docblock / tests / phpDocumentor / Reflection / DocBlockTest.php
1 <?php
2 /**
3  * phpDocumentor DocBlock Test
4  *
5  * PHP Version 5.3
6  *
7  * @author    Mike van Riel <mike.vanriel@naenius.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;
14
15 use phpDocumentor\Reflection\DocBlock\Context;
16 use phpDocumentor\Reflection\DocBlock\Location;
17 use phpDocumentor\Reflection\DocBlock\Tag\ReturnTag;
18
19 /**
20  * Test class for phpDocumentor\Reflection\DocBlock
21  *
22  * @author    Mike van Riel <mike.vanriel@naenius.com>
23  * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
24  * @license   http://www.opensource.org/licenses/mit-license.php MIT
25  * @link      http://phpdoc.org
26  */
27 class DocBlockTest extends \PHPUnit_Framework_TestCase
28 {
29     /**
30      * @covers \phpDocumentor\Reflection\DocBlock
31      * 
32      * @return void
33      */
34     public function testConstruct()
35     {
36         $fixture = <<<DOCBLOCK
37 /**
38  * This is a short description
39  *
40  * This is a long description
41  *
42  * @see \MyClass
43  * @return void
44  */
45 DOCBLOCK;
46         $object = new DocBlock(
47             $fixture,
48             new Context('\MyNamespace', array('PHPDoc' => '\phpDocumentor')),
49             new Location(2)
50         );
51         $this->assertEquals(
52             'This is a short description',
53             $object->getShortDescription()
54         );
55         $this->assertEquals(
56             'This is a long description',
57             $object->getLongDescription()->getContents()
58         );
59         $this->assertCount(2, $object->getTags());
60         $this->assertTrue($object->hasTag('see'));
61         $this->assertTrue($object->hasTag('return'));
62         $this->assertFalse($object->hasTag('category'));
63         
64         $this->assertSame('MyNamespace', $object->getContext()->getNamespace());
65         $this->assertSame(
66             array('PHPDoc' => '\phpDocumentor'),
67             $object->getContext()->getNamespaceAliases()
68         );
69         $this->assertSame(2, $object->getLocation()->getLineNumber());
70     }
71
72     /**
73      * @covers \phpDocumentor\Reflection\DocBlock::splitDocBlock
74      *
75      * @return void
76      */
77     public function testConstructWithTagsOnly()
78     {
79         $fixture = <<<DOCBLOCK
80 /**
81  * @see \MyClass
82  * @return void
83  */
84 DOCBLOCK;
85         $object = new DocBlock($fixture);
86         $this->assertEquals('', $object->getShortDescription());
87         $this->assertEquals('', $object->getLongDescription()->getContents());
88         $this->assertCount(2, $object->getTags());
89         $this->assertTrue($object->hasTag('see'));
90         $this->assertTrue($object->hasTag('return'));
91         $this->assertFalse($object->hasTag('category'));
92     }
93
94     /**
95      * @covers \phpDocumentor\Reflection\DocBlock::isTemplateStart
96      */
97     public function testIfStartOfTemplateIsDiscovered()
98     {
99         $fixture = <<<DOCBLOCK
100 /**#@+
101  * @see \MyClass
102  * @return void
103  */
104 DOCBLOCK;
105         $object = new DocBlock($fixture);
106         $this->assertEquals('', $object->getShortDescription());
107         $this->assertEquals('', $object->getLongDescription()->getContents());
108         $this->assertCount(2, $object->getTags());
109         $this->assertTrue($object->hasTag('see'));
110         $this->assertTrue($object->hasTag('return'));
111         $this->assertFalse($object->hasTag('category'));
112         $this->assertTrue($object->isTemplateStart());
113     }
114
115     /**
116      * @covers \phpDocumentor\Reflection\DocBlock::isTemplateEnd
117      */
118     public function testIfEndOfTemplateIsDiscovered()
119     {
120         $fixture = <<<DOCBLOCK
121 /**#@-*/
122 DOCBLOCK;
123         $object = new DocBlock($fixture);
124         $this->assertEquals('', $object->getShortDescription());
125         $this->assertEquals('', $object->getLongDescription()->getContents());
126         $this->assertTrue($object->isTemplateEnd());
127     }
128
129     /**
130      * @covers \phpDocumentor\Reflection\DocBlock::cleanInput
131      * 
132      * @return void
133      */
134     public function testConstructOneLiner()
135     {
136         $fixture = '/** Short description and nothing more. */';
137         $object = new DocBlock($fixture);
138         $this->assertEquals(
139             'Short description and nothing more.',
140             $object->getShortDescription()
141         );
142         $this->assertEquals('', $object->getLongDescription()->getContents());
143         $this->assertCount(0, $object->getTags());
144     }
145
146     /**
147      * @covers \phpDocumentor\Reflection\DocBlock::__construct
148      * 
149      * @return void
150      */
151     public function testConstructFromReflector()
152     {
153         $object = new DocBlock(new \ReflectionClass($this));
154         $this->assertEquals(
155             'Test class for phpDocumentor\Reflection\DocBlock',
156             $object->getShortDescription()
157         );
158         $this->assertEquals('', $object->getLongDescription()->getContents());
159         $this->assertCount(4, $object->getTags());
160         $this->assertTrue($object->hasTag('author'));
161         $this->assertTrue($object->hasTag('copyright'));
162         $this->assertTrue($object->hasTag('license'));
163         $this->assertTrue($object->hasTag('link'));
164         $this->assertFalse($object->hasTag('category'));
165     }
166
167     /**
168      * @expectedException \InvalidArgumentException
169      * 
170      * @return void
171      */
172     public function testExceptionOnInvalidObject()
173     {
174         new DocBlock($this);
175     }
176
177     public function testDotSeperation()
178     {
179         $fixture = <<<DOCBLOCK
180 /**
181  * This is a short description.
182  * This is a long description.
183  * This is a continuation of the long description.
184  */
185 DOCBLOCK;
186         $object = new DocBlock($fixture);
187         $this->assertEquals(
188             'This is a short description.',
189             $object->getShortDescription()
190         );
191         $this->assertEquals(
192             "This is a long description.\nThis is a continuation of the long "
193             ."description.",
194             $object->getLongDescription()->getContents()
195         );
196     }
197
198     /**
199      * @covers \phpDocumentor\Reflection\DocBlock::parseTags
200      * @expectedException \LogicException
201      * 
202      * @return void
203      */
204     public function testInvalidTagBlock()
205     {
206         if (0 == ini_get('allow_url_include')) {
207             $this->markTestSkipped('"data" URIs for includes are required.');
208         }
209
210         include 'data:text/plain;base64,'. base64_encode(
211             <<<DOCBLOCK_EXTENSION
212 <?php
213 class MyReflectionDocBlock extends \phpDocumentor\Reflection\DocBlock {
214     protected function splitDocBlock(\$comment) {
215         return array('', '', 'Invalid tag block');
216     }
217 }
218 DOCBLOCK_EXTENSION
219         );
220         new \MyReflectionDocBlock('');
221         
222     }
223
224     public function testTagCaseSensitivity()
225     {
226         $fixture = <<<DOCBLOCK
227 /**
228  * This is a short description.
229  *
230  * This is a long description.
231  *
232  * @method null something()
233  * @Method({"GET", "POST"})
234  */
235 DOCBLOCK;
236         $object = new DocBlock($fixture);
237         $this->assertEquals(
238             'This is a short description.',
239             $object->getShortDescription()
240         );
241         $this->assertEquals(
242             'This is a long description.',
243             $object->getLongDescription()->getContents()
244         );
245         $tags = $object->getTags();
246         $this->assertCount(2, $tags);
247         $this->assertTrue($object->hasTag('method'));
248         $this->assertTrue($object->hasTag('Method'));
249         $this->assertInstanceOf(
250             __NAMESPACE__ . '\DocBlock\Tag\MethodTag',
251             $tags[0]
252         );
253         $this->assertInstanceOf(
254             __NAMESPACE__ . '\DocBlock\Tag',
255             $tags[1]
256         );
257         $this->assertNotInstanceOf(
258             __NAMESPACE__ . '\DocBlock\Tag\MethodTag',
259             $tags[1]
260         );
261     }
262
263     /**
264      * @depends testConstructFromReflector
265      * @covers \phpDocumentor\Reflection\DocBlock::getTagsByName
266      * 
267      * @return void
268      */
269     public function testGetTagsByNameZeroAndOneMatch()
270     {
271         $object = new DocBlock(new \ReflectionClass($this));
272         $this->assertEmpty($object->getTagsByName('category'));
273         $this->assertCount(1, $object->getTagsByName('author'));
274     }
275
276     /**
277      * @depends testConstructWithTagsOnly
278      * @covers \phpDocumentor\Reflection\DocBlock::parseTags
279      * 
280      * @return void
281      */
282     public function testParseMultilineTag()
283     {
284         $fixture = <<<DOCBLOCK
285 /**
286  * @return void Content on
287  *     multiple lines.
288  */
289 DOCBLOCK;
290         $object = new DocBlock($fixture);
291         $this->assertCount(1, $object->getTags());
292     }
293
294     /**
295      * @depends testConstructWithTagsOnly
296      * @covers \phpDocumentor\Reflection\DocBlock::parseTags
297      * 
298      * @return void
299      */
300     public function testParseMultilineTagWithLineBreaks()
301     {
302         $fixture = <<<DOCBLOCK
303 /**
304  * @return void Content on
305  *     multiple lines.
306  *
307  *     One more, after the break.
308  */
309 DOCBLOCK;
310         $object = new DocBlock($fixture);
311         $this->assertCount(1, $tags = $object->getTags());
312             /** @var ReturnTag $tag */
313             $tag = reset($tags);
314             $this->assertEquals("Content on\n    multiple lines.\n\n    One more, after the break.", $tag->getDescription());
315     }
316
317     /**
318      * @depends testConstructWithTagsOnly
319      * @covers \phpDocumentor\Reflection\DocBlock::getTagsByName
320      * 
321      * @return void
322      */
323     public function testGetTagsByNameMultipleMatch()
324     {
325         $fixture = <<<DOCBLOCK
326 /**
327  * @param string
328  * @param int
329  * @return void
330  */
331 DOCBLOCK;
332         $object = new DocBlock($fixture);
333         $this->assertEmpty($object->getTagsByName('category'));
334         $this->assertCount(1, $object->getTagsByName('return'));
335         $this->assertCount(2, $object->getTagsByName('param'));
336     }
337 }