mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
Allow only tags in Docblock argument
The array of tags in the docblock constructor should only contain tags. Some of the factory methods of the tags are returning a null when the tag could not be created. This causes issues during parsing. By filtering these null values in the factory this use is resolved.
This commit is contained in:
@@ -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