Skip to content

Commit 04936a7

Browse files
committed
@return now trims the content before splitting it;
Removed ThrowTag.php (unnecessary, given the map, which aliases "throw" to ThrowsTag.php); Added tests for ThrowsTag, along with a few other minor test additions and fixes;
1 parent ae82b84 commit 04936a7

File tree

7 files changed

+187
-56
lines changed

7 files changed

+187
-56
lines changed

src/phpDocumentor/Reflection/DocBlock/Tag/ReturnTag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __construct($type, $content)
3737
$this->tag = $type;
3838
$this->content = $content;
3939

40-
$content = preg_split('/[\ \t]+/u', $content, 2);
40+
$content = preg_split('/[\ \t]+/u', trim($content), 2);
4141

4242
// any output is considered a type
4343
$this->type = array_shift($content);

src/phpDocumentor/Reflection/DocBlock/Tag/ThrowTag.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

tests/phpDocumentor/Reflection/DocBlock/Tag/ParamTagTest.php

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,22 +68,52 @@ public function provideDataForConstructor()
6868
array('param', 'int', 'int', array('int'), '', ''),
6969
array('param', '$bob', '', array(), '$bob', ''),
7070
array(
71-
'param', 'int Number of bobs', 'int', array('int'), '',
71+
'param',
72+
'int Number of bobs',
73+
'int',
74+
array('int'),
75+
'',
7276
'Number of bobs'
7377
),
74-
array('param', 'int $bob', 'int', array('int'), '$bob', ''),
7578
array(
76-
'param', 'int $bob Number of bobs', 'int', array('int'), '$bob',
79+
'param',
80+
'int $bob',
81+
'int',
82+
array('int'),
83+
'$bob',
84+
''
85+
),
86+
array(
87+
'param',
88+
'int $bob Number of bobs',
89+
'int',
90+
array('int'),
91+
'$bob',
7792
'Number of bobs'
7893
),
79-
array('param', "int Description \n on multiple lines", 'int',
80-
array('int'), '', "Description \n on multiple lines"
94+
array(
95+
'param',
96+
"int Description \n on multiple lines",
97+
'int',
98+
array('int'),
99+
'',
100+
"Description \n on multiple lines"
81101
),
82-
array('param', "int \n\$bob Variable name on a new line", 'int',
83-
array('int'), '$bob', "Variable name on a new line"
102+
array(
103+
'param',
104+
"int \n\$bob Variable name on a new line",
105+
'int',
106+
array('int'),
107+
'$bob',
108+
"Variable name on a new line"
84109
),
85-
array('param', "\nint \$bob Type on a new line", 'int',
86-
array('int'), '$bob', "Type on a new line"
110+
array(
111+
'param',
112+
"\nint \$bob Type on a new line",
113+
'int',
114+
array('int'),
115+
'$bob',
116+
"Type on a new line"
87117
)
88118
);
89119
}

tests/phpDocumentor/Reflection/DocBlock/Tag/ReturnTagTest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ class ReturnTagTest extends \PHPUnit_Framework_TestCase
2626
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag can
2727
* understand the @return DocBlock.
2828
*
29+
* @param string $type
2930
* @param string $content
3031
* @param string $extractedType
3132
* @param string $extractedTypes
3233
* @param string $extractedDescription
3334
*
3435
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::__construct
35-
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::getType
36-
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ParamTag::getTypes
36+
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::getType
37+
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag::getTypes
3738
*
3839
* @dataProvider provideDataForConstructor
3940
*
@@ -71,6 +72,27 @@ public function provideDataForConstructor()
7172
array('int'),
7273
'Number of Bobs'
7374
),
75+
array(
76+
'return',
77+
'int|double Number of Bobs',
78+
'int|double',
79+
array('int', 'double'),
80+
'Number of Bobs'
81+
),
82+
array(
83+
'return',
84+
"int Number of \n Bobs",
85+
'int',
86+
array('int'),
87+
"Number of \n Bobs"
88+
),
89+
array(
90+
'return',
91+
" int Number of Bobs",
92+
'int',
93+
array('int'),
94+
"Number of Bobs"
95+
)
7496
);
7597
}
7698
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?php
2+
/**
3+
* phpDocumentor Return tag test.
4+
*
5+
* PHP version 5.3
6+
*
7+
* @author Mike van Riel <[email protected]>
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\ReturnTag.
17+
*
18+
* @author Mike van Riel <[email protected]>
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 ThrowsTagTest extends \PHPUnit_Framework_TestCase
24+
{
25+
/**
26+
* Test that the \phpDocumentor\Reflection\DocBlock\Tag\ReturnTag can
27+
* understand the @return DocBlock.
28+
*
29+
* @param string $type
30+
* @param string $content
31+
* @param string $extractedType
32+
* @param string $extractedTypes
33+
* @param string $extractedDescription
34+
*
35+
* @covers \phpDocumentor\Reflection\DocBlock\Tag\ThrowsTag
36+
*
37+
* @dataProvider provideDataForConstructor
38+
*
39+
* @return void
40+
*/
41+
public function testConstructorParsesInputsIntoCorrectFields(
42+
$type,
43+
$content,
44+
$extractedType,
45+
$extractedTypes,
46+
$extractedDescription
47+
) {
48+
$tag = new ThrowsTag($type, $content);
49+
50+
$this->assertEquals($type, $tag->getName());
51+
$this->assertEquals($extractedType, $tag->getType());
52+
$this->assertEquals($extractedTypes, $tag->getTypes());
53+
$this->assertEquals($extractedDescription, $tag->getDescription());
54+
}
55+
56+
/**
57+
* Data provider for testConstructorParsesInputsIntoCorrectFields()
58+
*
59+
* @return array
60+
*/
61+
public function provideDataForConstructor()
62+
{
63+
return array(
64+
array('throws', '', '', array(), ''),
65+
array('throws', 'int', 'int', array('int'), ''),
66+
array(
67+
'throws',
68+
'int Number of Bobs',
69+
'int',
70+
array('int'),
71+
'Number of Bobs'
72+
),
73+
array(
74+
'throws',
75+
'int|double Number of Bobs',
76+
'int|double',
77+
array('int', 'double'),
78+
'Number of Bobs'
79+
),
80+
array(
81+
'throws',
82+
"int Number of \n Bobs",
83+
'int',
84+
array('int'),
85+
"Number of \n Bobs"
86+
),
87+
array(
88+
'throws',
89+
" int Number of Bobs",
90+
'int',
91+
array('int'),
92+
"Number of Bobs"
93+
)
94+
);
95+
}
96+
}

tests/phpDocumentor/Reflection/DocBlock/Tag/UsesTagTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class UsesTagTest extends \PHPUnit_Framework_TestCase
3131
* @param string $exContent
3232
* @param string $exReference
3333
*
34-
* @covers \phpDocumentor\Reflection\DocBlock\Tag\UsesTag::__construct
34+
* @covers \phpDocumentor\Reflection\DocBlock\Tag\UsesTag
3535
* @dataProvider provideDataForConstuctor
3636
*
3737
* @return void

tests/phpDocumentor/Reflection/DocBlockTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,32 @@ public function testDotSeperation()
149149
);
150150
}
151151

152+
/**
153+
* @covers \phpDocumentor\Reflection\DocBlock::parseTags
154+
* @expectedException \LogicException
155+
*
156+
* @return void
157+
*/
158+
public function testInvalidTagBlock()
159+
{
160+
if (0 == ini_get('allow_url_include')) {
161+
$this->markTestSkipped('"data" URIs for includes are required.');
162+
}
163+
164+
require 'data:text/plain;base64,'. base64_encode(
165+
<<<'TAG_HANDLER'
166+
<?php
167+
class MyReflectionDocBlock extends \phpDocumentor\Reflection\DocBlock {
168+
protected function splitDocBlock($comment) {
169+
return array('', '', 'Invalid tag block');
170+
}
171+
}
172+
TAG_HANDLER
173+
);
174+
new \MyReflectionDocBlock('');
175+
176+
}
177+
152178
public function testTagCaseSensitivity()
153179
{
154180
$fixture = <<<DOCBLOCK

0 commit comments

Comments
 (0)