Skip to content

Commit 1f637ff

Browse files
committed
Merge pull request #61 from jaapio/hotfix/PassContextToFactory
pass context to tag factory for correct type resolving
2 parents 0cc2b07 + ff18c82 commit 1f637ff

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/DocBlockFactory.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public function create($docblock, Types\Context $context = null, Location $locat
9393
return new DocBlock(
9494
$summary,
9595
$description ? $this->descriptionFactory->create($description, $context) : null,
96-
$this->parseTagBlock($tags),
96+
$this->parseTagBlock($tags, $context),
9797
$context,
9898
$location,
9999
$templateMarker === '#@+',
@@ -213,10 +213,11 @@ private function splitDocBlock($comment)
213213
* Creates the tag objects.
214214
*
215215
* @param string $tags Tag block to parse.
216+
* @param Context $context Context of the parsed Tag
216217
*
217218
* @return DocBlock\Tag[]
218219
*/
219-
private function parseTagBlock($tags)
220+
private function parseTagBlock($tags, Context $context)
220221
{
221222
$tags = $this->filterTagBlock($tags);
222223
if (!$tags) {
@@ -225,7 +226,7 @@ private function parseTagBlock($tags)
225226

226227
$result = $this->splitTagBlockIntoTagLines($tags);
227228
foreach ($result as $key => $tagLine) {
228-
$result[$key] = $this->tagFactory->create(trim($tagLine));
229+
$result[$key] = $this->tagFactory->create(trim($tagLine), $context);
229230
}
230231

231232
return $result;

tests/unit/DocBlockFactoryTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
1818
use phpDocumentor\Reflection\DocBlock\Tag;
1919
use phpDocumentor\Reflection\DocBlock\TagFactory;
20+
use phpDocumentor\Reflection\DocBlock\Tags\Param;
2021
use phpDocumentor\Reflection\Types\Context;
2122

2223
/**
@@ -166,7 +167,7 @@ public function testTagsAreInterpretedUsingFactory()
166167

167168
$tag = m::mock(Tag::class);
168169
$tagFactory = m::mock(TagFactory::class);
169-
$tagFactory->shouldReceive('create')->with($tagString)->andReturn($tag);
170+
$tagFactory->shouldReceive('create')->with($tagString, m::type(Context::class))->andReturn($tag);
170171

171172
$fixture = new DocBlockFactory(new DescriptionFactory($tagFactory), $tagFactory);
172173

@@ -234,4 +235,22 @@ public function provideSummaryAndDescriptions()
234235
],
235236
];
236237
}
238+
239+
/**
240+
* @covers ::__construct
241+
* @covers ::create
242+
* @uses phpDocumentor\Reflection\DocBlock\DescriptionFactory
243+
* @uses phpDocumentor\Reflection\DocBlock\Description
244+
* @uses phpDocumentor\Reflection\Types\Context
245+
* @uses phpDocumentor\Reflection\DocBlock\Tags\Param
246+
*/
247+
public function testTagsWithContextNamespace()
248+
{
249+
$tagFactoryMock = m::mock(TagFactory::class);
250+
$fixture = new DocBlockFactory(m::mock(DescriptionFactory::class), $tagFactoryMock);
251+
$context = new Context('MyNamespace');
252+
253+
$tagFactoryMock->shouldReceive('create')->with(m::any(), $context)->andReturn(new Param('param'));
254+
$docblock = $fixture->create('/** @param MyType $param */', $context);
255+
}
237256
}

0 commit comments

Comments
 (0)