Skip to content

Commit a6ffa93

Browse files
committed
Add example and functional test for reconstituting a DocBlock
1 parent 1b5279c commit a6ffa93

File tree

4 files changed

+62
-9
lines changed

4 files changed

+62
-9
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
require_once(__DIR__ . '/../vendor/autoload.php');
3+
4+
use phpDocumentor\Reflection\DocBlock\Serializer;
5+
use phpDocumentor\Reflection\DocBlockFactory;
6+
7+
$docComment = <<<DOCCOMMENT
8+
/**
9+
* This is an example of a summary.
10+
*
11+
* And here is an example of the description
12+
* of a DocBlock that can span multiple lines.
13+
*
14+
* @see \phpDocumentor\Reflection\DocBlock\StandardTagFactory
15+
*/
16+
DOCCOMMENT;
17+
18+
$factory = DocBlockFactory::createInstance();
19+
$docblock = $factory->create($docComment);
20+
21+
$serializer = new Serializer();
22+
$reconstitutedDocComment = $serializer->getDocComment($docblock);
23+

src/DocBlock/Tags/See.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,10 @@ public static function create(
5353
Assert::string($body);
5454
Assert::allNotNull([$resolver, $descriptionFactory]);
5555

56-
$parts = preg_split('/\s+/Su', $body, 2);
56+
$parts = preg_split('/\s+/Su', $body, 2);
57+
$description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null;
5758

58-
return new static(
59-
$resolver->resolve($parts[0], $context),
60-
$descriptionFactory->create(isset($parts[1]) ? $parts[1] : '', $context)
61-
);
59+
return new static($resolver->resolve($parts[0], $context), $description);
6260
}
6361

6462
/**
@@ -78,6 +76,6 @@ public function getReference()
7876
*/
7977
public function __toString()
8078
{
81-
return $this->refers . ' ' . $this->description->render();
79+
return $this->refers . ($this->description ? ' ' . $this->description->render() : '');
8280
}
8381
}

tests/integration/InterpretingDocBlocksTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
*/
2323
class InterpretingDocBlocksTest extends \PHPUnit_Framework_TestCase
2424
{
25-
/**
26-
* @link ../../examples/interpreting-a-simple-docblock.php
27-
*/
2825
public function testInterpretingASimpleDocBlock()
2926
{
3027
/**
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
/**
3+
* This file is part of phpDocumentor.
4+
*
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*
8+
* @copyright 2010-2015 Mike van Riel<[email protected]>
9+
* @license http://www.opensource.org/licenses/mit-license.php MIT
10+
* @link http://phpdoc.org
11+
*/
12+
13+
namespace phpDocumentor\Reflection;
14+
15+
use phpDocumentor\Reflection\DocBlock\Description;
16+
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
17+
use phpDocumentor\Reflection\DocBlock\Tag;
18+
use phpDocumentor\Reflection\DocBlock\Tags\See;
19+
20+
/**
21+
* @coversNothing
22+
*/
23+
class InterpretingDocBlocksTest extends \PHPUnit_Framework_TestCase
24+
{
25+
public function testInterpretingASimpleDocBlock()
26+
{
27+
/**
28+
* @var string $docComment
29+
* @var string $reconstitutedDocComment
30+
*/
31+
include(__DIR__ . '/../../examples/03-reconstituting-a-docblock.php');
32+
33+
$this->assertSame($docComment, $reconstitutedDocComment);
34+
}
35+
}

0 commit comments

Comments
 (0)