Yaffs site version 1.1
[yaffs-website] / vendor / psy / psysh / test / Psy / Test / Util / DocblockTest.php
1 <?php
2
3 /*
4  * This file is part of Psy Shell.
5  *
6  * (c) 2012-2017 Justin Hileman
7  *
8  * For the full copyright and license information, please view the LICENSE
9  * file that was distributed with this source code.
10  */
11
12 namespace Psy\Test\Util;
13
14 use Psy\Util\Docblock;
15
16 class DocblockTest extends \PHPUnit_Framework_TestCase
17 {
18     /**
19      * @dataProvider comments
20      */
21     public function testDocblockParsing($comment, $body, $tags)
22     {
23         $reflector = $this
24             ->getMockBuilder('ReflectionClass')
25             ->disableOriginalConstructor()
26             ->getMock();
27
28         $reflector->expects($this->once())
29             ->method('getDocComment')
30             ->will($this->returnValue($comment));
31
32         $docblock = new Docblock($reflector);
33
34         $this->assertEquals($body, $docblock->desc);
35
36         foreach ($tags as $tag => $value) {
37             $this->assertTrue($docblock->hasTag($tag));
38             $this->assertEquals($value, $docblock->tag($tag));
39         }
40     }
41
42     public function comments()
43     {
44         return array(
45             array('', '', array()),
46             array(
47                 '/**
48                  * This is a docblock
49                  *
50                  * @throws \Exception with a description
51                  */',
52                 'This is a docblock',
53                 array(
54                     'throws' => array(array('type' => '\Exception', 'desc' => 'with a description')),
55                 ),
56             ),
57             array(
58                 '/**
59                  * This is a slightly longer docblock
60                  *
61                  * @param int         $foo Is a Foo
62                  * @param string      $bar With some sort of description
63                  * @param \ClassName $baz is cool too
64                  *
65                  * @return int At least it isn\'t a string
66                  */',
67                 'This is a slightly longer docblock',
68                 array(
69                     'param' => array(
70                         array('type' => 'int', 'desc' => 'Is a Foo', 'var' => '$foo'),
71                         array('type' => 'string', 'desc' => 'With some sort of description', 'var' => '$bar'),
72                         array('type' => '\ClassName', 'desc' => 'is cool too', 'var' => '$baz'),
73                     ),
74                     'return' => array(
75                         array('type' => 'int', 'desc' => 'At least it isn\'t a string'),
76                     ),
77                 ),
78             ),
79             array(
80                 '/**
81                  * This is a docblock!
82                  *
83                  * It spans lines, too!
84                  *
85                  * @tagname plus a description
86                  *
87                  * @return
88                  */',
89                 "This is a docblock!\n\nIt spans lines, too!",
90                 array(
91                     'tagname' => array('plus a description'),
92                 ),
93             ),
94         );
95     }
96 }