Skip to content

Commit e0a5a75

Browse files
committed
Implemented nested inline tag parsing;
Added unit tests for LongDescription.php; Added the "src" folder as white listed for code coverage in the PHPUnit configuration; Fixed the @Covers annotation inside the CoversTagTest.php (isn't this ironic?).
1 parent 607aa79 commit e0a5a75

File tree

4 files changed

+212
-3
lines changed

4 files changed

+212
-3
lines changed

phpunit.xml.dist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,9 @@
66
<directory>./tests/</directory>
77
</testsuite>
88
</testsuites>
9+
<filter>
10+
<whitelist>
11+
<directory suffix=".php">./src/</directory>
12+
</whitelist>
13+
</filter>
914
</phpunit>

src/phpDocumentor/Reflection/DocBlock/LongDescription.php

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,34 @@ public function getParsedContents()
6161
{
6262
if (null === $this->parsedContents) {
6363
$this->parsedContents = preg_split(
64-
'/\{(\@.*?)\}/uS',
64+
'/\{
65+
# We want the whole tag line, but without the inline tag
66+
# delimiters.
67+
(\@
68+
# The content should not be captured, or it will appear
69+
# in the result separately.
70+
(?:
71+
# Match nested inline tags.
72+
# Because we did not catch the tag delimiters
73+
# earlier, we must be explicit with them here.
74+
\{(?1)?\}
75+
|
76+
# "{@}" is not a valid inline tag. This ensures that
77+
# having it occur inside an inline tag does not trip
78+
# us up.
79+
\{\@\}
80+
|
81+
# If we are not dealing with a nested inline tag,
82+
# get the character, as long as it is not a closing
83+
# tag delimiter.
84+
# This is an alternative way of non-greedy matching.
85+
[^\}]
86+
)+ # We need to keep doing these checks for every
87+
# character, since we never know where an inline tag
88+
# is going to start at. The "+" ensures we are not
89+
# treating "{@}" as a valid inline tag.
90+
)
91+
\}/xuS',
6592
$this->contents,
6693
null,
6794
PREG_SPLIT_DELIM_CAPTURE
@@ -129,4 +156,4 @@ public function __toString()
129156
{
130157
return 'Not yet implemented';
131158
}
132-
}
159+
}
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
<?php
2+
/**
3+
* phpDocumentor Long Description Test
4+
*
5+
* PHP Version 5.3
6+
*
7+
* @author Vasil Rangelov <[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;
14+
15+
/**
16+
* Test class for phpDocumentor\Reflection\DocBlock\LongDescription
17+
*
18+
* @author Vasil Rangelov <[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 LongDescriptionTest extends \PHPUnit_Framework_TestCase
24+
{
25+
public function testConstruct()
26+
{
27+
$fixture = <<<LONGDESC
28+
This is text for a description.
29+
LONGDESC;
30+
$object = new LongDescription($fixture);
31+
$this->assertSame($fixture, $object->getContents());
32+
33+
$parsedContents = $object->getParsedContents();
34+
$this->assertCount(1, $parsedContents);
35+
$this->assertSame($fixture, $parsedContents[0]);
36+
}
37+
38+
public function testInlineTagParsing()
39+
{
40+
$fixture = <<<LONGDESC
41+
This is text for a {@link http://phpdoc.org/ description} that uses inline
42+
tags.
43+
LONGDESC;
44+
$object = new LongDescription($fixture);
45+
$this->assertSame($fixture, $object->getContents());
46+
47+
$parsedContents = $object->getParsedContents();
48+
$this->assertCount(3, $parsedContents);
49+
$this->assertSame('This is text for a ', $parsedContents[0]);
50+
$this->assertInstanceOf(
51+
__NAMESPACE__ . '\Tag\LinkTag',
52+
$parsedContents[1]
53+
);
54+
$this->assertSame(
55+
' that uses inline
56+
tags.',
57+
$parsedContents[2]
58+
);
59+
}
60+
61+
public function testInlineTagAtStartParsing()
62+
{
63+
$fixture = <<<LONGDESC
64+
{@link http://phpdoc.org/ This} is text for a description that uses inline
65+
tags.
66+
LONGDESC;
67+
$object = new LongDescription($fixture);
68+
$this->assertSame($fixture, $object->getContents());
69+
70+
$parsedContents = $object->getParsedContents();
71+
$this->assertCount(3, $parsedContents);
72+
73+
$this->assertSame('', $parsedContents[0]);
74+
$this->assertInstanceOf(
75+
__NAMESPACE__ . '\Tag\LinkTag',
76+
$parsedContents[1]
77+
);
78+
$this->assertSame(
79+
' is text for a description that uses inline
80+
tags.',
81+
$parsedContents[2]
82+
);
83+
}
84+
85+
public function testNestedInlineTagParsing()
86+
{
87+
$fixture = <<<LONGDESC
88+
This is text for a description with {@internal inline tag with
89+
{@link http://phpdoc.org another inline tag} in it}.
90+
LONGDESC;
91+
$object = new LongDescription($fixture);
92+
$this->assertSame($fixture, $object->getContents());
93+
94+
$parsedContents = $object->getParsedContents();
95+
$this->assertCount(3, $parsedContents);
96+
97+
$this->assertSame(
98+
'This is text for a description with ',
99+
$parsedContents[0]
100+
);
101+
$this->assertInstanceOf(
102+
__NAMESPACE__ . '\Tag',
103+
$parsedContents[1]
104+
);
105+
$this->assertSame('.', $parsedContents[2]);
106+
}
107+
108+
public function testEmptyInlineTag()
109+
{
110+
$fixture = <<<LONGDESC
111+
This is text for a description with an empty inline tag - {@}.
112+
LONGDESC;
113+
$object = new LongDescription($fixture);
114+
$this->assertSame($fixture, $object->getContents());
115+
116+
$parsedContents = $object->getParsedContents();
117+
$this->assertCount(1, $parsedContents);
118+
$this->assertSame($fixture, $parsedContents[0]);
119+
}
120+
121+
public function testNestedEmptyInlineTag()
122+
{
123+
$fixture = <<<LONGDESC
124+
This is text for a description with an {@internal inline tag with an empty
125+
inline tag - {@} in it}.
126+
LONGDESC;
127+
$object = new LongDescription($fixture);
128+
$this->assertSame($fixture, $object->getContents());
129+
130+
$parsedContents = $object->getParsedContents();
131+
$this->assertCount(3, $parsedContents);
132+
$this->assertSame(
133+
'This is text for a description with an ',
134+
$parsedContents[0]
135+
);
136+
$this->assertInstanceOf(
137+
__NAMESPACE__ . '\Tag',
138+
$parsedContents[1]
139+
);
140+
$this->assertSame('.', $parsedContents[2]);
141+
}
142+
143+
public function testInlineTagDelimiters()
144+
{
145+
$fixture = <<<LONGDESC
146+
This is text for a description with {} that is not a tag.
147+
LONGDESC;
148+
$object = new LongDescription($fixture);
149+
$this->assertSame($fixture, $object->getContents());
150+
151+
$parsedContents = $object->getParsedContents();
152+
$this->assertCount(1, $parsedContents);
153+
$this->assertSame($fixture, $parsedContents[0]);
154+
}
155+
156+
public function testNestedInlineTagDelimiters()
157+
{
158+
$fixture = <<<LONGDESC
159+
This is text for a description with {@internal inline tag with {} that is not an
160+
inline tag}.
161+
LONGDESC;
162+
$object = new LongDescription($fixture);
163+
$this->assertSame($fixture, $object->getContents());
164+
165+
$parsedContents = $object->getParsedContents();
166+
$this->assertCount(3, $parsedContents);
167+
$this->assertSame(
168+
'This is text for a description with ',
169+
$parsedContents[0]
170+
);
171+
$this->assertInstanceOf(
172+
__NAMESPACE__ . '\Tag',
173+
$parsedContents[1]
174+
);
175+
$this->assertSame('.', $parsedContents[2]);
176+
}
177+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class CoversTagTest extends \PHPUnit_Framework_TestCase
3232
* @param string $exContent
3333
* @param string $exReference
3434
*
35-
* @covers \phpDocumentor\Reflection\DocBlock\Tag\Covers::__construct
35+
* @covers \phpDocumentor\Reflection\DocBlock\Tag\CoversTag::__construct
3636
* @dataProvider provideDataForConstuctor
3737
*
3838
* @return void

0 commit comments

Comments
 (0)