Skip to content

Commit cff8a80

Browse files
committed
Add integration test and example on how to read tags
1 parent 97c3735 commit cff8a80

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

examples/02-interpreting-tags.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
require_once(__DIR__ . '/../vendor/autoload.php');
3+
4+
use phpDocumentor\Reflection\DocBlockFactory;
5+
6+
$docComment = <<<DOCCOMMENT
7+
/**
8+
* This is an example of a summary.
9+
*
10+
* @see \phpDocumentor\Reflection\DocBlock\StandardTagFactory
11+
*/
12+
DOCCOMMENT;
13+
14+
$factory = DocBlockFactory::createInstance();
15+
$docblock = $factory->create($docComment);
16+
17+
// You can check if a DocBlock has one or more see tags
18+
$hasSeeTag = $docblock->hasTag('see');
19+
20+
// Or we can get a complete list of all tags
21+
$tags = $docblock->getTags();
22+
23+
// But we can also grab all tags of a specific type, such as `see`
24+
$seeTags = $docblock->getTagsByName('see');

tests/integration/InterpretingDocBlocksTest.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
namespace phpDocumentor\Reflection;
1414

1515
use phpDocumentor\Reflection\DocBlock\Description;
16+
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
17+
use phpDocumentor\Reflection\DocBlock\Tag;
18+
use phpDocumentor\Reflection\DocBlock\Tags\See;
1619

1720
/**
1821
* @coversNothing
@@ -29,7 +32,7 @@ public function testInterpretingASimpleDocBlock()
2932
* @var string $summary
3033
* @var Description $description
3134
*/
32-
include(__DIR__ . '/../../examples/interpreting-a-simple-docblock.php');
35+
include(__DIR__ . '/../../examples/01-interpreting-a-simple-docblock.php');
3336

3437
$descriptionText = <<<DESCRIPTION
3538
This is a Description. A Summary and Description are separated by either
@@ -44,4 +47,26 @@ public function testInterpretingASimpleDocBlock()
4447
$this->assertSame($descriptionText, $description->render());
4548
$this->assertEmpty($docblock->getTags());
4649
}
50+
51+
public function testInterpretingTags()
52+
{
53+
/**
54+
* @var DocBlock $docblock
55+
* @var boolean $hasSeeTag
56+
* @var Tag[] $tags
57+
* @var See[] $seeTags
58+
*/
59+
include(__DIR__ . '/../../examples/02-interpreting-tags.php');
60+
61+
$this->assertTrue($hasSeeTag);
62+
$this->assertCount(1, $tags);
63+
$this->assertCount(1, $seeTags);
64+
65+
$this->assertInstanceOf(See::class, $tags[0]);
66+
$this->assertInstanceOf(See::class, $seeTags[0]);
67+
68+
$seeTag = $seeTags[0];
69+
$this->assertSame('\\' . StandardTagFactory::class, (string)$seeTag->getReference());
70+
$this->assertSame('', (string)$seeTag->getDescription());
71+
}
4772
}

0 commit comments

Comments
 (0)