/** * Factory method for easy instantiation. * * @param string[] $additionalTags * * @return DocBlockFactory */ public static function createInstance(array $additionalTags = []) { $fqsenResolver = new FqsenResolver(); $tagFactory = new StandardTagFactory($fqsenResolver); $descriptionFactory = new DescriptionFactory($tagFactory); $tagFactory->addService($descriptionFactory); $tagFactory->addService(new TypeResolver($fqsenResolver)); foreach ($additionalTags as $tagName => $tagClassName) { $tagFactory->registerTagHandler($tagName, $tagClassName); } return new self($descriptionFactory, $tagFactory); }
/** * @covers ::registerTagHandler * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService * @expectedException \InvalidArgumentException */ public function testHandlerRegistrationFailsIfProvidedHandlerDoesNotImplementTheTagInterface() { $resolver = m::mock(FqsenResolver::class); $tagFactory = new StandardTagFactory($resolver); $tagFactory->registerTagHandler('my-tag', 'stdClass'); }
/** * @covers ::create * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct * @uses phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService * @uses phpDocumentor\Reflection\Docblock\Description * @uses phpDocumentor\Reflection\Docblock\Tags\Return_ * @uses phpDocumentor\Reflection\Docblock\Tags\BaseTag */ public function testReturntagIsMappedCorrectly() { $context = new Context(''); $descriptionFactory = m::mock(DescriptionFactory::class); $descriptionFactory->shouldReceive('create')->once()->with('', $context)->andReturn(new Description('')); $typeResolver = new TypeResolver(); $tagFactory = new StandardTagFactory(m::mock(FqsenResolver::class)); $tagFactory->addService($descriptionFactory, DescriptionFactory::class); $tagFactory->addService($typeResolver, TypeResolver::class); /** @var Return_ $tag */ $tag = $tagFactory->create('@return mixed', $context); $this->assertInstanceOf(Return_::class, $tag); $this->assertSame('return', $tag->getName()); }