Yaffs site version 1.1
[yaffs-website] / vendor / phpdocumentor / reflection-docblock / tests / phpDocumentor / Reflection / DocBlock / Tag / MethodTagTest.php
1 <?php
2 /**
3  * phpDocumentor Method Tag 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\DocBlock\Tag;
14
15 /**
16  * Test class for \phpDocumentor\Reflection\DocBlock\Tag\MethodTag
17  *
18  * @author    Mike van Riel <mike.vanriel@naenius.com>
19  * @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
20  * @license   http://www.opensource.org/licenses/mit-license.php MIT
21  * @link      http://phpdoc.org
22  */
23 class MethodTagTest extends \PHPUnit_Framework_TestCase
24 {
25     /**
26      * @param string $signature       The signature to test.
27      * @param bool   $valid           Whether the given signature is expected to
28      *     be valid.
29      * @param string $expected_name   The method name that is expected from this
30      *     signature.
31      * @param string $expected_return The return type that is expected from this
32      *     signature.
33      * @param bool   $paramCount      Number of parameters in the signature.
34      * @param string $description     The short description mentioned in the
35      *     signature.
36      * 
37      * @covers \phpDocumentor\Reflection\DocBlock\Tag\MethodTag
38      * @dataProvider getTestSignatures
39      *
40      * @return void
41      */
42     public function testConstruct(
43         $signature,
44         $valid,
45         $expected_name,
46         $expected_return,
47         $expected_isStatic,
48         $paramCount,
49         $description
50     ) {
51         ob_start();
52         $tag = new MethodTag('method', $signature);
53         $stdout = ob_get_clean();
54
55         $this->assertSame(
56             $valid,
57             empty($stdout),
58             'No error should have been output if the signature is valid'
59         );
60
61         if (!$valid) {
62             return;
63         }
64
65         $this->assertEquals($expected_name, $tag->getMethodName());
66         $this->assertEquals($expected_return, $tag->getType());
67         $this->assertEquals($description, $tag->getDescription());
68         $this->assertEquals($expected_isStatic, $tag->isStatic());
69         $this->assertCount($paramCount, $tag->getArguments());
70     }
71
72     public function getTestSignatures()
73     {
74         return array(
75             // TODO: Verify this case
76 //            array(
77 //                'foo',
78 //                false, 'foo', '', false, 0, ''
79 //            ),
80             array(
81                 'foo()',
82                 true, 'foo', 'void', false, 0, ''
83             ),
84             array(
85                 'foo() description',
86                 true, 'foo', 'void', false, 0, 'description'
87             ),
88             array(
89                 'int foo()',
90                 true, 'foo', 'int', false, 0, ''
91             ),
92             array(
93                 'int foo() description',
94                 true, 'foo', 'int', false, 0, 'description'
95             ),
96             array(
97                 'int foo($a, $b)',
98                 true, 'foo', 'int', false, 2, ''
99             ),
100             array(
101                 'int foo() foo(int $a, int $b)',
102                 true, 'foo', 'int', false, 2, ''
103             ),
104             array(
105                 'int foo(int $a, int $b)',
106                 true, 'foo', 'int', false, 2, ''
107             ),
108             array(
109                 'null|int foo(int $a, int $b)',
110                 true, 'foo', 'null|int', false, 2, ''
111             ),
112             array(
113                 'int foo(null|int $a, int $b)',
114                 true, 'foo', 'int', false, 2, ''
115             ),
116             array(
117                 '\Exception foo() foo(Exception $a, Exception $b)',
118                 true, 'foo', '\Exception', false, 2, ''
119             ),
120             array(
121                 'int foo() foo(Exception $a, Exception $b) description',
122                 true, 'foo', 'int', false, 2, 'description'
123             ),
124             array(
125                 'int foo() foo(\Exception $a, \Exception $b) description',
126                 true, 'foo', 'int', false, 2, 'description'
127             ),
128             array(
129                 'void()',
130                 true, 'void', 'void', false, 0, ''
131             ),
132             array(
133                 'static foo()',
134                 true, 'foo', 'static', false, 0, ''
135             ),
136             array(
137                 'static void foo()',
138                 true, 'foo', 'void', true, 0, ''
139             ),
140             array(
141                 'static static foo()',
142                 true, 'foo', 'static', true, 0, ''
143             )
144         );
145     }
146 }