From a6ffa93e286036cd639c710af1afa814ac86fe82 Mon Sep 17 00:00:00 2001 From: Mike van Riel Date: Sat, 27 Jun 2015 16:47:47 +0200 Subject: [PATCH] Add example and functional test for reconstituting a DocBlock --- examples/03-reconstituting-a-docblock.php | 23 ++++++++++++ src/DocBlock/Tags/See.php | 10 +++--- .../integration/InterpretingDocBlocksTest.php | 3 -- .../ReconstitutingADocBlockTest.php | 35 +++++++++++++++++++ 4 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 examples/03-reconstituting-a-docblock.php create mode 100644 tests/integration/ReconstitutingADocBlockTest.php diff --git a/examples/03-reconstituting-a-docblock.php b/examples/03-reconstituting-a-docblock.php new file mode 100644 index 0000000..70c2c66 --- /dev/null +++ b/examples/03-reconstituting-a-docblock.php @@ -0,0 +1,23 @@ +create($docComment); + +$serializer = new Serializer(); +$reconstitutedDocComment = $serializer->getDocComment($docblock); + diff --git a/src/DocBlock/Tags/See.php b/src/DocBlock/Tags/See.php index 5be006a..d3c446a 100644 --- a/src/DocBlock/Tags/See.php +++ b/src/DocBlock/Tags/See.php @@ -53,12 +53,10 @@ class See extends BaseTag Assert::string($body); 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( - $resolver->resolve($parts[0], $context), - $descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context) - ); + return new static($resolver->resolve($parts[0], $context), $description); } /** @@ -78,6 +76,6 @@ class See extends BaseTag */ public function __toString() { - return $this->refers . ' ' . $this->description->render(); + return $this->refers . ($this->description ? ' ' . $this->description->render() : ''); } } diff --git a/tests/integration/InterpretingDocBlocksTest.php b/tests/integration/InterpretingDocBlocksTest.php index dda3663..e9664f0 100644 --- a/tests/integration/InterpretingDocBlocksTest.php +++ b/tests/integration/InterpretingDocBlocksTest.php @@ -22,9 +22,6 @@ use phpDocumentor\Reflection\DocBlock\Tags\See; */ class InterpretingDocBlocksTest extends \PHPUnit_Framework_TestCase { - /** - * @link ../../examples/interpreting-a-simple-docblock.php - */ public function testInterpretingASimpleDocBlock() { /** diff --git a/tests/integration/ReconstitutingADocBlockTest.php b/tests/integration/ReconstitutingADocBlockTest.php new file mode 100644 index 0000000..3179645 --- /dev/null +++ b/tests/integration/ReconstitutingADocBlockTest.php @@ -0,0 +1,35 @@ + + * @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); + } +}