Skip to content

Commit 066a402

Browse files
committed
Register @example tag handler out of the box
The Example tag handler exists and is fully functional, but was never wired into the default tag handler map of StandardTagFactory. As a result, `@example` and `{@example ...}` were always parsed as a Generic tag, which broke downstream tooling (phpDocumentor rendered the tag as a literal string instead of resolving the referenced file). Fixes #412
1 parent 7bae675 commit 066a402

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

src/DocBlock/StandardTagFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use phpDocumentor\Reflection\DocBlock\Tags\Author;
1818
use phpDocumentor\Reflection\DocBlock\Tags\Covers;
1919
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated;
20+
use phpDocumentor\Reflection\DocBlock\Tags\Example;
2021
use phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractPHPStanFactory;
2122
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ExtendsFactory;
2223
use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory;
@@ -89,6 +90,7 @@ final class StandardTagFactory implements TagFactory
8990
'author' => Author::class,
9091
'covers' => Covers::class,
9192
'deprecated' => Deprecated::class,
93+
'example' => Example::class,
9294
'link' => LinkTag::class,
9395
'see' => SeeTag::class,
9496
'since' => Since::class,

tests/unit/DocBlock/StandardTagFactoryTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use phpDocumentor\Reflection\Assets\CustomTagFactory;
2323
use phpDocumentor\Reflection\DocBlock\Tags\Author;
2424
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated;
25+
use phpDocumentor\Reflection\DocBlock\Tags\Example;
2526
use phpDocumentor\Reflection\DocBlock\Tags\Extends_;
2627
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
2728
use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter;
@@ -135,6 +136,27 @@ public function testCreatingASpecificTag(): void
135136
$this->assertSame('author', $tag->getName());
136137
}
137138

139+
/**
140+
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService
141+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Example
142+
*
143+
* @covers ::__construct
144+
* @covers ::create
145+
*/
146+
public function testExampleTagIsRecognisedOutOfTheBox(): void
147+
{
148+
$context = new Context('');
149+
$tagFactory = StandardTagFactory::createInstance(m::mock(FqsenResolver::class));
150+
151+
$tag = $tagFactory->create('@example "path/to/example.php" 3 10 Example description.', $context);
152+
153+
$this->assertInstanceOf(Example::class, $tag);
154+
$this->assertSame('example', $tag->getName());
155+
$this->assertSame('path/to/example.php', $tag->getFilePath());
156+
$this->assertSame(3, $tag->getStartingLine());
157+
$this->assertSame(10, $tag->getLineCount());
158+
}
159+
138160
/**
139161
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService
140162
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See

0 commit comments

Comments
 (0)