mirror of
https://github.com/barryvdh/ReflectionDocBlock.git
synced 2026-08-18 01:57:13 +00:00
pass context to tag factory for correct type resolving
This commit is contained in:
@@ -93,7 +93,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
|
|||||||
return new DocBlock(
|
return new DocBlock(
|
||||||
$summary,
|
$summary,
|
||||||
$description ? $this->descriptionFactory->create($description, $context) : null,
|
$description ? $this->descriptionFactory->create($description, $context) : null,
|
||||||
$this->parseTagBlock($tags),
|
$this->parseTagBlock($tags, $context),
|
||||||
$context,
|
$context,
|
||||||
$location,
|
$location,
|
||||||
$templateMarker === '#@+',
|
$templateMarker === '#@+',
|
||||||
@@ -213,10 +213,11 @@ final class DocBlockFactory implements DocBlockFactoryInterface
|
|||||||
* Creates the tag objects.
|
* Creates the tag objects.
|
||||||
*
|
*
|
||||||
* @param string $tags Tag block to parse.
|
* @param string $tags Tag block to parse.
|
||||||
|
* @param Context $context Context of the parsed Tag
|
||||||
*
|
*
|
||||||
* @return DocBlock\Tag[]
|
* @return DocBlock\Tag[]
|
||||||
*/
|
*/
|
||||||
private function parseTagBlock($tags)
|
private function parseTagBlock($tags, Context $context)
|
||||||
{
|
{
|
||||||
$tags = $this->filterTagBlock($tags);
|
$tags = $this->filterTagBlock($tags);
|
||||||
if (!$tags) {
|
if (!$tags) {
|
||||||
@@ -225,7 +226,7 @@ final class DocBlockFactory implements DocBlockFactoryInterface
|
|||||||
|
|
||||||
$result = $this->splitTagBlockIntoTagLines($tags);
|
$result = $this->splitTagBlockIntoTagLines($tags);
|
||||||
foreach ($result as $key => $tagLine) {
|
foreach ($result as $key => $tagLine) {
|
||||||
$result[$key] = $this->tagFactory->create(trim($tagLine));
|
$result[$key] = $this->tagFactory->create(trim($tagLine), $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ use phpDocumentor\Reflection\DocBlock\Description;
|
|||||||
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
|
||||||
use phpDocumentor\Reflection\DocBlock\Tag;
|
use phpDocumentor\Reflection\DocBlock\Tag;
|
||||||
use phpDocumentor\Reflection\DocBlock\TagFactory;
|
use phpDocumentor\Reflection\DocBlock\TagFactory;
|
||||||
|
use phpDocumentor\Reflection\DocBlock\Tags\Param;
|
||||||
use phpDocumentor\Reflection\Types\Context;
|
use phpDocumentor\Reflection\Types\Context;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -166,7 +167,7 @@ TAG;
|
|||||||
|
|
||||||
$tag = m::mock(Tag::class);
|
$tag = m::mock(Tag::class);
|
||||||
$tagFactory = m::mock(TagFactory::class);
|
$tagFactory = m::mock(TagFactory::class);
|
||||||
$tagFactory->shouldReceive('create')->with($tagString)->andReturn($tag);
|
$tagFactory->shouldReceive('create')->with($tagString, m::type(Context::class))->andReturn($tag);
|
||||||
|
|
||||||
$fixture = new DocBlockFactory(new DescriptionFactory($tagFactory), $tagFactory);
|
$fixture = new DocBlockFactory(new DescriptionFactory($tagFactory), $tagFactory);
|
||||||
|
|
||||||
@@ -234,4 +235,22 @@ DOCBLOCK
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers ::__construct
|
||||||
|
* @covers ::create
|
||||||
|
* @uses phpDocumentor\Reflection\DocBlock\DescriptionFactory
|
||||||
|
* @uses phpDocumentor\Reflection\DocBlock\Description
|
||||||
|
* @uses phpDocumentor\Reflection\Types\Context
|
||||||
|
* @uses phpDocumentor\Reflection\DocBlock\Tags\Param
|
||||||
|
*/
|
||||||
|
public function testTagsWithContextNamespace()
|
||||||
|
{
|
||||||
|
$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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user