mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 10:07:12 +00:00
Merge pull request #66 from jaapio/feature/filterNullTags
Allow only tags in Docblock argument
This commit is contained in:
@@ -61,6 +61,7 @@ final class DocBlock
|
||||
Assert::string($summary);
|
||||
Assert::boolean($isTemplateStart);
|
||||
Assert::boolean($isTemplateEnd);
|
||||
Assert::allIsInstanceOf($tags, Tag::class);
|
||||
|
||||
$this->summary = $summary;
|
||||
$this->description = $description ?: new DocBlock\Description('');
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace phpDocumentor\Reflection;
|
||||
|
||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
|
||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||
use phpDocumentor\Reflection\DocBlock\TagFactory;
|
||||
use phpDocumentor\Reflection\Types\Context;
|
||||
use Webmozart\Assert\Assert;
|
||||
@@ -93,7 +94,9 @@ final class DocBlockFactory implements DocBlockFactoryInterface
|
||||
return new DocBlock(
|
||||
$summary,
|
||||
$description ? $this->descriptionFactory->create($description, $context) : null,
|
||||
$this->parseTagBlock($tags, $context),
|
||||
array_filter($this->parseTagBlock($tags, $context), function($tag) {
|
||||
return $tag instanceof Tag;
|
||||
}),
|
||||
$context,
|
||||
$location,
|
||||
$templateMarker === '#@+',
|
||||
|
||||
@@ -239,6 +239,7 @@ DOCBLOCK
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::create
|
||||
*
|
||||
* @uses phpDocumentor\Reflection\DocBlock\DescriptionFactory
|
||||
* @uses phpDocumentor\Reflection\DocBlock\Description
|
||||
* @uses phpDocumentor\Reflection\Types\Context
|
||||
@@ -246,11 +247,44 @@ DOCBLOCK
|
||||
*/
|
||||
public function testTagsWithContextNamespace()
|
||||
{
|
||||
$tagFactoryMock = m::mock(TagFactory::class);
|
||||
$tagFactoryMock = m::mock(TagFactory::class);
|
||||
$fixture = new DocBlockFactory(m::mock(DescriptionFactory::class), $tagFactoryMock);
|
||||
$context = new Context('MyNamespace');
|
||||
|
||||
$tagFactoryMock->shouldReceive('create')->with(m::any(), $context)->andReturn(new Param('param'));
|
||||
$docblock = $fixture->create('/** @param MyType $param */', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::create
|
||||
*
|
||||
* @uses phpDocumentor\Reflection\DocBlock\DescriptionFactory
|
||||
* @uses phpDocumentor\Reflection\DocBlock\Description
|
||||
*/
|
||||
public function testTagsAreFilteredForNullValues()
|
||||
{
|
||||
$tagString = <<<TAG
|
||||
@author Mike van Riel <[email protected]> This is with
|
||||
multiline description.
|
||||
TAG;
|
||||
|
||||
$tagFactory = m::mock(TagFactory::class);
|
||||
$tagFactory->shouldReceive('create')->with($tagString, m::any())->andReturn(null);
|
||||
|
||||
$fixture = new DocBlockFactory(new DescriptionFactory($tagFactory), $tagFactory);
|
||||
|
||||
$given = <<<DOCBLOCK
|
||||
/**
|
||||
* This is a summary.
|
||||
*
|
||||
* @author Mike van Riel <[email protected]> This is with
|
||||
* multiline description.
|
||||
*/
|
||||
DOCBLOCK;
|
||||
|
||||
$docblock = $fixture->create($given, new Context(''));
|
||||
|
||||
$this->assertEquals([], $docblock->getTags());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,24 @@ class DocBlockTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertSame($tags, $fixture->getTags());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::getTags
|
||||
*
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Description
|
||||
* @uses \phpDocumentor\Reflection\DocBlock\Tag
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testDocBlockAllowsOnlyTags()
|
||||
{
|
||||
$tags = [
|
||||
null
|
||||
];
|
||||
|
||||
$fixture = new DocBlock('', null, $tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::__construct
|
||||
* @covers ::getTagsByName
|
||||
|
||||
Reference in New Issue
Block a user