Merge pull request #66 from jaapio/feature/filterNullTags

Allow only tags in Docblock argument
This commit is contained in:
Mike van Riel
2015-10-26 15:52:52 +01:00
4 changed files with 58 additions and 2 deletions
+1
View File
@@ -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('');
+4 -1
View File
@@ -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 === '#@+',
+34
View File
@@ -239,6 +239,7 @@ DOCBLOCK
/**
* @covers ::__construct
* @covers ::create
*
* @uses phpDocumentor\Reflection\DocBlock\DescriptionFactory
* @uses phpDocumentor\Reflection\DocBlock\Description
* @uses phpDocumentor\Reflection\Types\Context
@@ -253,4 +254,37 @@ DOCBLOCK
$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());
}
}
+18
View File
@@ -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