|
13 | 13 |
|
14 | 14 | namespace phpDocumentor\Reflection\DocBlock;
|
15 | 15 |
|
| 16 | +use InvalidArgumentException; |
16 | 17 | use Mockery as m;
|
17 | 18 | use phpDocumentor\Reflection\DocBlock\Tags\Author;
|
18 | 19 | use phpDocumentor\Reflection\DocBlock\Tags\Formatter;
|
@@ -341,4 +342,95 @@ public function testInvalidTagIsReturnedOnFailure() : void
|
341 | 342 |
|
342 | 343 | $this->assertInstanceOf(InvalidTag::class, $tag);
|
343 | 344 | }
|
| 345 | + |
| 346 | + /** |
| 347 | + * @dataProvider validTagProvider |
| 348 | + */ |
| 349 | + public function testValidFormattedTags(string $input, string $tagName, string $render) : void |
| 350 | + { |
| 351 | + $fqsenResolver = $this->prophesize(FqsenResolver::class); |
| 352 | + $tagFactory = new StandardTagFactory($fqsenResolver->reveal()); |
| 353 | + $tagFactory->registerTagHandler('tag', Generic::class); |
| 354 | + $tag = $tagFactory->create($input); |
| 355 | + |
| 356 | + self::assertSame($tagName, $tag->getName()); |
| 357 | + self::assertSame($render, $tag->render()); |
| 358 | + } |
| 359 | + |
| 360 | + /** |
| 361 | + * @return string[][] |
| 362 | + * |
| 363 | + * @phpstan-return array<string, array<int, string>> |
| 364 | + */ |
| 365 | + public function validTagProvider() : array |
| 366 | + { |
| 367 | + //rendered result is adding a space, because the tags are not rendered properly. |
| 368 | + return [ |
| 369 | + 'tag without body' => [ |
| 370 | + '@tag', |
| 371 | + 'tag', |
| 372 | + '@tag', |
| 373 | + ], |
| 374 | + 'tag specialization' => [ |
| 375 | + '@tag:some-spec body', |
| 376 | + 'tag:some-spec', |
| 377 | + '@tag:some-spec body', |
| 378 | + ], |
| 379 | + 'tag specialization followed by parenthesis' => [ |
| 380 | + '@tag:some-spec(body)', |
| 381 | + 'tag:some-spec', |
| 382 | + '@tag:some-spec (body)', |
| 383 | + ], |
| 384 | + 'tag with textual description' => [ |
| 385 | + '@tag some text', |
| 386 | + 'tag', |
| 387 | + '@tag some text', |
| 388 | + ], |
| 389 | + 'tag body starting with sqare brackets is allowed' => [ |
| 390 | + '@tag [is valid]', |
| 391 | + 'tag', |
| 392 | + '@tag [is valid]', |
| 393 | + ], |
| 394 | + 'tag body starting with curly brackets is allowed' => [ |
| 395 | + '@tag {is valid}', |
| 396 | + 'tag', |
| 397 | + '@tag {is valid}', |
| 398 | + ], |
| 399 | + 'tag name followed by curly brackets directly is allowed' => [ |
| 400 | + '@tag{is valid}', |
| 401 | + 'tag', |
| 402 | + '@tag {is valid}', |
| 403 | + ], |
| 404 | + 'parenthesis directly following a tag name is valid' => [ |
| 405 | + '@tag(is valid)', |
| 406 | + 'tag', |
| 407 | + '@tag (is valid)', |
| 408 | + ], |
| 409 | + ]; |
| 410 | + } |
| 411 | + |
| 412 | + /** |
| 413 | + * @dataProvider invalidTagProvider |
| 414 | + */ |
| 415 | + public function testInValidFormattedTags(string $input) : void |
| 416 | + { |
| 417 | + $this->expectException(InvalidArgumentException::class); |
| 418 | + $fqsenResolver = $this->prophesize(FqsenResolver::class); |
| 419 | + $tagFactory = new StandardTagFactory($fqsenResolver->reveal()); |
| 420 | + $tagFactory->registerTagHandler('tag', Generic::class); |
| 421 | + $tagFactory->create($input); |
| 422 | + } |
| 423 | + |
| 424 | + /** |
| 425 | + * @return string[][] |
| 426 | + * |
| 427 | + * @phpstan-return list<array<int, string>> |
| 428 | + */ |
| 429 | + public function invalidTagProvider() : array |
| 430 | + { |
| 431 | + return [ |
| 432 | + ['@tag[invalid]'], |
| 433 | + ['@tag@invalid'], |
| 434 | + ]; |
| 435 | + } |
344 | 436 | }
|
0 commit comments