mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
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?).
This commit is contained in:
@@ -6,4 +6,9 @@
|
|||||||
<directory>./tests/</directory>
|
<directory>./tests/</directory>
|
||||||
</testsuite>
|
</testsuite>
|
||||||
</testsuites>
|
</testsuites>
|
||||||
|
<filter>
|
||||||
|
<whitelist>
|
||||||
|
<directory suffix=".php">./src/</directory>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
</phpunit>
|
</phpunit>
|
||||||
|
|||||||
@@ -61,7 +61,34 @@ class LongDescription implements \Reflector
|
|||||||
{
|
{
|
||||||
if (null === $this->parsedContents) {
|
if (null === $this->parsedContents) {
|
||||||
$this->parsedContents = preg_split(
|
$this->parsedContents = preg_split(
|
||||||
'/\{(\@.*?)\}/uS',
|
'/\{
|
||||||
|
# We want the whole tag line, but without the inline tag
|
||||||
|
# delimiters.
|
||||||
|
(\@
|
||||||
|
# The content should not be captured, or it will appear
|
||||||
|
# in the result separately.
|
||||||
|
(?:
|
||||||
|
# Match nested inline tags.
|
||||||
|
# Because we did not catch the tag delimiters
|
||||||
|
# earlier, we must be explicit with them here.
|
||||||
|
\{(?1)?\}
|
||||||
|
|
|
||||||
|
# "{@}" is not a valid inline tag. This ensures that
|
||||||
|
# having it occur inside an inline tag does not trip
|
||||||
|
# us up.
|
||||||
|
\{\@\}
|
||||||
|
|
|
||||||
|
# If we are not dealing with a nested inline tag,
|
||||||
|
# get the character, as long as it is not a closing
|
||||||
|
# tag delimiter.
|
||||||
|
# This is an alternative way of non-greedy matching.
|
||||||
|
[^\}]
|
||||||
|
)+ # We need to keep doing these checks for every
|
||||||
|
# character, since we never know where an inline tag
|
||||||
|
# is going to start at. The "+" ensures we are not
|
||||||
|
# treating "{@}" as a valid inline tag.
|
||||||
|
)
|
||||||
|
\}/xuS',
|
||||||
$this->contents,
|
$this->contents,
|
||||||
null,
|
null,
|
||||||
PREG_SPLIT_DELIM_CAPTURE
|
PREG_SPLIT_DELIM_CAPTURE
|
||||||
@@ -129,4 +156,4 @@ class LongDescription implements \Reflector
|
|||||||
{
|
{
|
||||||
return 'Not yet implemented';
|
return 'Not yet implemented';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,177 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* phpDocumentor Long Description Test
|
||||||
|
*
|
||||||
|
* PHP Version 5.3
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace phpDocumentor\Reflection\DocBlock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test class for phpDocumentor\Reflection\DocBlock\LongDescription
|
||||||
|
*
|
||||||
|
* @author Vasil Rangelov <[email protected]>
|
||||||
|
* @copyright 2010-2011 Mike van Riel / Naenius. (http://www.naenius.com)
|
||||||
|
* @license http://www.opensource.org/licenses/mit-license.php MIT
|
||||||
|
* @link http://phpdoc.org
|
||||||
|
*/
|
||||||
|
class LongDescriptionTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testConstruct()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
This is text for a description.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new LongDescription($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(1, $parsedContents);
|
||||||
|
$this->assertSame($fixture, $parsedContents[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInlineTagParsing()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
This is text for a {@link http://phpdoc.org/ description} that uses inline
|
||||||
|
tags.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new LongDescription($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(3, $parsedContents);
|
||||||
|
$this->assertSame('This is text for a ', $parsedContents[0]);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag\LinkTag',
|
||||||
|
$parsedContents[1]
|
||||||
|
);
|
||||||
|
$this->assertSame(
|
||||||
|
' that uses inline
|
||||||
|
tags.',
|
||||||
|
$parsedContents[2]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInlineTagAtStartParsing()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
{@link http://phpdoc.org/ This} is text for a description that uses inline
|
||||||
|
tags.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new LongDescription($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(3, $parsedContents);
|
||||||
|
|
||||||
|
$this->assertSame('', $parsedContents[0]);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag\LinkTag',
|
||||||
|
$parsedContents[1]
|
||||||
|
);
|
||||||
|
$this->assertSame(
|
||||||
|
' is text for a description that uses inline
|
||||||
|
tags.',
|
||||||
|
$parsedContents[2]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedInlineTagParsing()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
This is text for a description with {@internal inline tag with
|
||||||
|
{@link http://phpdoc.org another inline tag} in it}.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new LongDescription($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(3, $parsedContents);
|
||||||
|
|
||||||
|
$this->assertSame(
|
||||||
|
'This is text for a description with ',
|
||||||
|
$parsedContents[0]
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$parsedContents[1]
|
||||||
|
);
|
||||||
|
$this->assertSame('.', $parsedContents[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEmptyInlineTag()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
This is text for a description with an empty inline tag - {@}.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new LongDescription($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(1, $parsedContents);
|
||||||
|
$this->assertSame($fixture, $parsedContents[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedEmptyInlineTag()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
This is text for a description with an {@internal inline tag with an empty
|
||||||
|
inline tag - {@} in it}.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new LongDescription($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(3, $parsedContents);
|
||||||
|
$this->assertSame(
|
||||||
|
'This is text for a description with an ',
|
||||||
|
$parsedContents[0]
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$parsedContents[1]
|
||||||
|
);
|
||||||
|
$this->assertSame('.', $parsedContents[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInlineTagDelimiters()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
This is text for a description with {} that is not a tag.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new LongDescription($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(1, $parsedContents);
|
||||||
|
$this->assertSame($fixture, $parsedContents[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNestedInlineTagDelimiters()
|
||||||
|
{
|
||||||
|
$fixture = <<<LONGDESC
|
||||||
|
This is text for a description with {@internal inline tag with {} that is not an
|
||||||
|
inline tag}.
|
||||||
|
LONGDESC;
|
||||||
|
$object = new LongDescription($fixture);
|
||||||
|
$this->assertSame($fixture, $object->getContents());
|
||||||
|
|
||||||
|
$parsedContents = $object->getParsedContents();
|
||||||
|
$this->assertCount(3, $parsedContents);
|
||||||
|
$this->assertSame(
|
||||||
|
'This is text for a description with ',
|
||||||
|
$parsedContents[0]
|
||||||
|
);
|
||||||
|
$this->assertInstanceOf(
|
||||||
|
__NAMESPACE__ . '\Tag',
|
||||||
|
$parsedContents[1]
|
||||||
|
);
|
||||||
|
$this->assertSame('.', $parsedContents[2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,7 +32,7 @@ class CoversTagTest extends \PHPUnit_Framework_TestCase
|
|||||||
* @param string $exContent
|
* @param string $exContent
|
||||||
* @param string $exReference
|
* @param string $exReference
|
||||||
*
|
*
|
||||||
* @covers \phpDocumentor\Reflection\DocBlock\Tag\Covers::__construct
|
* @covers \phpDocumentor\Reflection\DocBlock\Tag\CoversTag::__construct
|
||||||
* @dataProvider provideDataForConstuctor
|
* @dataProvider provideDataForConstuctor
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
|||||||
Reference in New Issue
Block a user