Add example and functional test for reconstituting a DocBlock

This commit is contained in:
Mike van Riel
2015-06-27 16:47:47 +02:00
parent 1b5279c777
commit a6ffa93e28
4 changed files with 62 additions and 9 deletions
+23
View File
@@ -0,0 +1,23 @@
<?php
require_once(__DIR__ . '/../vendor/autoload.php');
use phpDocumentor\Reflection\DocBlock\Serializer;
use phpDocumentor\Reflection\DocBlockFactory;
$docComment = <<<DOCCOMMENT
/**
* This is an example of a summary.
*
* And here is an example of the description
* of a DocBlock that can span multiple lines.
*
* @see \phpDocumentor\Reflection\DocBlock\StandardTagFactory
*/
DOCCOMMENT;
$factory = DocBlockFactory::createInstance();
$docblock = $factory->create($docComment);
$serializer = new Serializer();
$reconstitutedDocComment = $serializer->getDocComment($docblock);
+3 -5
View File
@@ -54,11 +54,9 @@ class See extends BaseTag
Assert::allNotNull([$resolver, $descriptionFactory]); Assert::allNotNull([$resolver, $descriptionFactory]);
$parts = preg_split('/\s+/Su', $body, 2); $parts = preg_split('/\s+/Su', $body, 2);
$description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null;
return new static( return new static($resolver->resolve($parts[0], $context), $description);
$resolver->resolve($parts[0], $context),
$descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context)
);
} }
/** /**
@@ -78,6 +76,6 @@ class See extends BaseTag
*/ */
public function __toString() public function __toString()
{ {
return $this->refers . ' ' . $this->description->render(); return $this->refers . ($this->description ? ' ' . $this->description->render() : '');
} }
} }
@@ -22,9 +22,6 @@ use phpDocumentor\Reflection\DocBlock\Tags\See;
*/ */
class InterpretingDocBlocksTest extends \PHPUnit_Framework_TestCase class InterpretingDocBlocksTest extends \PHPUnit_Framework_TestCase
{ {
/**
* @link ../../examples/interpreting-a-simple-docblock.php
*/
public function testInterpretingASimpleDocBlock() public function testInterpretingASimpleDocBlock()
{ {
/** /**
@@ -0,0 +1,35 @@
<?php
/**
* This file is part of phpDocumentor.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright 2010-2015 Mike van Riel<[email protected]>
* @license http://www.opensource.org/licenses/mit-license.php MIT
* @link http://phpdoc.org
*/
namespace phpDocumentor\Reflection;
use phpDocumentor\Reflection\DocBlock\Description;
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
use phpDocumentor\Reflection\DocBlock\Tag;
use phpDocumentor\Reflection\DocBlock\Tags\See;
/**
* @coversNothing
*/
class InterpretingDocBlocksTest extends \PHPUnit_Framework_TestCase
{
public function testInterpretingASimpleDocBlock()
{
/**
* @var string $docComment
* @var string $reconstitutedDocComment
*/
include(__DIR__ . '/../../examples/03-reconstituting-a-docblock.php');
$this->assertSame($docComment, $reconstitutedDocComment);
}
}