Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/DocBlock/StandardTagFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use phpDocumentor\Reflection\DocBlock\Tags\Author;
use phpDocumentor\Reflection\DocBlock\Tags\Covers;
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated;
use phpDocumentor\Reflection\DocBlock\Tags\Example;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\AbstractPHPStanFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\ExtendsFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Factory\Factory;
Expand Down Expand Up @@ -89,6 +90,7 @@ final class StandardTagFactory implements TagFactory
'author' => Author::class,
'covers' => Covers::class,
'deprecated' => Deprecated::class,
'example' => Example::class,
'link' => LinkTag::class,
'see' => SeeTag::class,
'since' => Since::class,
Expand Down
47 changes: 47 additions & 0 deletions tests/unit/DocBlock/StandardTagFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use phpDocumentor\Reflection\Assets\CustomTagFactory;
use phpDocumentor\Reflection\DocBlock\Tags\Author;
use phpDocumentor\Reflection\DocBlock\Tags\Deprecated;
use phpDocumentor\Reflection\DocBlock\Tags\Example;
use phpDocumentor\Reflection\DocBlock\Tags\Extends_;
use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
use phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter;
Expand Down Expand Up @@ -135,6 +136,52 @@ public function testCreatingASpecificTag(): void
$this->assertSame('author', $tag->getName());
}

/**
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Example
*
* @covers ::__construct
* @covers ::create
*/
public function testExampleTagIsRecognisedOutOfTheBox(): void
{
$context = new Context('');
$tagFactory = StandardTagFactory::createInstance(m::mock(FqsenResolver::class));

$tag = $tagFactory->create('@example "path/to/example.php" 3 10 Example description.', $context);

$this->assertInstanceOf(Example::class, $tag);
$this->assertSame('example', $tag->getName());
$this->assertSame('path/to/example.php', $tag->getFilePath());
$this->assertSame(3, $tag->getStartingLine());
$this->assertSame(10, $tag->getLineCount());
}

/**
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
* @uses \phpDocumentor\Reflection\DocBlock\Description
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Example
*
* @covers ::__construct
* @covers ::create
*/
public function testExampleTagIsRecognisedInInlineForm(): void
{
$context = new Context('');
$tagFactory = StandardTagFactory::createInstance(m::mock(FqsenResolver::class));

$tag = $tagFactory->create('@link https://phpdoc.org {@example "path/to/example.php"}', $context);

$description = $tag->getDescription();
$this->assertNotNull($description);
$inlineTags = $description->getTags();
$this->assertCount(1, $inlineTags);
$this->assertInstanceOf(Example::class, $inlineTags[0]);
$this->assertSame('path/to/example.php', $inlineTags[0]->getFilePath());
}

/**
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService
* @uses \phpDocumentor\Reflection\DocBlock\Tags\See
Expand Down