Skip to content

Commit 0722b31

Browse files
committed
"StandardTagFactory" -> add more tests
1 parent 2b63106 commit 0722b31

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

tests/unit/DocBlock/StandardTagFactoryTest.php

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,30 @@ public function testCreatingAGenericTag() : void
7878
$this->assertSame($expectedDescription, $tag->getDescription());
7979
}
8080

81+
/**
82+
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService
83+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic
84+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
85+
* @uses \phpDocumentor\Reflection\DocBlock\Description
86+
*
87+
* @covers ::__construct
88+
* @covers ::create
89+
*/
90+
public function testCreatingAGenericTagWithDescriptionText() : void
91+
{
92+
$expectedTagName = 'unknown-tag';
93+
$expectedDescriptionText = ' foo Bar 123 ';
94+
$context = new Context('');
95+
96+
$tagFactory = new StandardTagFactory(new FqsenResolver());
97+
$tagFactory->addService(new DescriptionFactory($tagFactory), DescriptionFactory::class);
98+
99+
$tag = $tagFactory->create('@' . $expectedTagName . $expectedDescriptionText, $context);
100+
101+
$this->assertInstanceOf(Generic::class, $tag);
102+
$this->assertSame('foo Bar 123', $tag . '');
103+
}
104+
81105
/**
82106
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService
83107
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Author
@@ -146,6 +170,90 @@ public function testPassingYourOwnSetOfTagHandlers() : void
146170
$this->assertSame('author', $tag->getName());
147171
}
148172

173+
/**
174+
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService
175+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Author
176+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
177+
*
178+
* @covers ::__construct
179+
* @covers ::create
180+
*/
181+
public function testPassingYourOwnSetOfTagHandlersWithGermanChars() : void
182+
{
183+
$typeResolver = new TypeResolver();
184+
$fqsenResolver = new FqsenResolver();
185+
$tagFactory = new StandardTagFactory($fqsenResolver);
186+
$descriptionFactory = new DescriptionFactory($tagFactory);
187+
$context = new Context('');
188+
189+
$tagFactory = new StandardTagFactory(
190+
$fqsenResolver,
191+
['my-täg' => Author::class]
192+
);
193+
194+
$tag = $tagFactory->create('@my-täg foo bar ', $context);
195+
196+
$this->assertInstanceOf(Author::class, $tag);
197+
$this->assertSame('author', $tag->getName());
198+
$this->assertSame('foo bar', $tag . '');
199+
}
200+
201+
/**
202+
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService
203+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Author
204+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
205+
*
206+
* @covers ::__construct
207+
* @covers ::create
208+
*/
209+
public function testPassingYourOwnSetOfTagHandlersWithoutComment() : void
210+
{
211+
$typeResolver = new TypeResolver();
212+
$fqsenResolver = new FqsenResolver();
213+
$tagFactory = new StandardTagFactory($fqsenResolver);
214+
$descriptionFactory = new DescriptionFactory($tagFactory);
215+
$context = new Context('');
216+
217+
$tagFactory = new StandardTagFactory(
218+
$fqsenResolver,
219+
['my-täg' => Author::class]
220+
);
221+
222+
$tag = $tagFactory->create('@my-täg', $context);
223+
224+
$this->assertInstanceOf(Author::class, $tag);
225+
$this->assertSame('author', $tag->getName());
226+
}
227+
228+
/**
229+
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService
230+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Author
231+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag
232+
*
233+
* @covers ::__construct
234+
* @covers ::create
235+
*/
236+
public function testPassingYourOwnSetOfTagHandlersWithEmptyComment() : void
237+
{
238+
$this->expectException('InvalidArgumentException');
239+
$this->expectExceptionMessage(
240+
'The tag "@my-täg " does not seem to be wellformed, please check it for errors'
241+
);
242+
243+
$typeResolver = new TypeResolver();
244+
$fqsenResolver = new FqsenResolver();
245+
$tagFactory = new StandardTagFactory($fqsenResolver);
246+
$descriptionFactory = new DescriptionFactory($tagFactory);
247+
$context = new Context('');
248+
249+
$tagFactory = new StandardTagFactory(
250+
$fqsenResolver,
251+
['my-täg' => Author::class]
252+
);
253+
254+
$tag = $tagFactory->create('@my-täg ', $context);
255+
}
256+
149257
/**
150258
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::__construct
151259
* @uses \phpDocumentor\Reflection\DocBlock\StandardTagFactory::addService

0 commit comments

Comments
 (0)