From 54e10d44fc1a84e2598d26f70d4f6f1f233e228a Mon Sep 17 00:00:00 2001 From: Jaapio Date: Mon, 4 Nov 2024 22:26:31 +0100 Subject: [PATCH] Add tests for new tags --- src/DocBlock/Tags/Template.php | 2 +- .../integration/InterpretingDocBlocksTest.php | 32 ++++++++++++++++ tests/unit/DocBlock/Tags/ExtendsTest.php | 30 +++++++++++++++ tests/unit/DocBlock/Tags/ImplementsTest.php | 30 +++++++++++++++ .../DocBlock/Tags/TemplateExtendsTest.php | 30 +++++++++++++++ .../DocBlock/Tags/TemplateImplementsTest.php | 30 +++++++++++++++ tests/unit/DocBlock/Tags/TemplateTest.php | 38 +++++++++++++++++++ 7 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 tests/unit/DocBlock/Tags/ExtendsTest.php create mode 100644 tests/unit/DocBlock/Tags/ImplementsTest.php create mode 100644 tests/unit/DocBlock/Tags/TemplateExtendsTest.php create mode 100644 tests/unit/DocBlock/Tags/TemplateImplementsTest.php create mode 100644 tests/unit/DocBlock/Tags/TemplateTest.php diff --git a/src/DocBlock/Tags/Template.php b/src/DocBlock/Tags/Template.php index e6d9a7e..cfd6b69 100644 --- a/src/DocBlock/Tags/Template.php +++ b/src/DocBlock/Tags/Template.php @@ -21,7 +21,7 @@ use phpDocumentor\Reflection\Type; /** * Reflection class for a {@}template tag in a Docblock. */ -final class Template extends TagWithType +final class Template extends BaseTag { /** @var non-empty-string */ private string $templateName; diff --git a/tests/integration/InterpretingDocBlocksTest.php b/tests/integration/InterpretingDocBlocksTest.php index c901f5c..5c24076 100644 --- a/tests/integration/InterpretingDocBlocksTest.php +++ b/tests/integration/InterpretingDocBlocksTest.php @@ -25,6 +25,7 @@ use phpDocumentor\Reflection\DocBlock\Tags\Param; use phpDocumentor\Reflection\DocBlock\Tags\Return_; use phpDocumentor\Reflection\DocBlock\Tags\See; use phpDocumentor\Reflection\DocBlock\Tags\Since; +use phpDocumentor\Reflection\DocBlock\Tags\Template; use phpDocumentor\Reflection\PseudoTypes\ConstExpression; use phpDocumentor\Reflection\Types\Array_; use phpDocumentor\Reflection\Types\Compound; @@ -431,4 +432,35 @@ identifier has already been registered.', $docblock ); } + + public function testProcessTemplateTag(): void + { + $docComment = <<create($docComment); + + self::assertEquals( + [ + new Template( + 'T', + new Object_(new Fqsen('\\Type')), + new Mixed_(), + new Description('this is a description') + ), + new Template( + 'TDefault', + new Object_(new Fqsen('\\Type')), + new Object_(new Fqsen('\\String_')), + new Description('this is a description') + ), + ], + $docblock->getTags() + ); + } } diff --git a/tests/unit/DocBlock/Tags/ExtendsTest.php b/tests/unit/DocBlock/Tags/ExtendsTest.php new file mode 100644 index 0000000..a04f4a8 --- /dev/null +++ b/tests/unit/DocBlock/Tags/ExtendsTest.php @@ -0,0 +1,30 @@ +assertSame('extends', $fixture->getName()); + $this->assertSame($type, $fixture->getType()); + } + + public function testRendersCorrectly(): void + { + $type = new Object_(new Fqsen('\\Type')); + $fixture = new Extends_($type); + $this->assertSame('@extends \\Type', $fixture->render()); + } +} diff --git a/tests/unit/DocBlock/Tags/ImplementsTest.php b/tests/unit/DocBlock/Tags/ImplementsTest.php new file mode 100644 index 0000000..ff24b8f --- /dev/null +++ b/tests/unit/DocBlock/Tags/ImplementsTest.php @@ -0,0 +1,30 @@ +assertSame('implements', $fixture->getName()); + $this->assertSame($type, $fixture->getType()); + } + + public function testRendersCorrectly(): void + { + $type = new Object_(new Fqsen('\\Type')); + $fixture = new Implements_($type); + $this->assertSame('@implements \\Type', $fixture->render()); + } +} diff --git a/tests/unit/DocBlock/Tags/TemplateExtendsTest.php b/tests/unit/DocBlock/Tags/TemplateExtendsTest.php new file mode 100644 index 0000000..90a2d6b --- /dev/null +++ b/tests/unit/DocBlock/Tags/TemplateExtendsTest.php @@ -0,0 +1,30 @@ +assertSame('template-extends', $fixture->getName()); + $this->assertSame($type, $fixture->getType()); + } + + public function testRendersCorrectly(): void + { + $type = new Object_(new Fqsen('\\Type')); + $fixture = new TemplateExtends($type); + $this->assertSame('@template-extends \\Type', $fixture->render()); + } +} diff --git a/tests/unit/DocBlock/Tags/TemplateImplementsTest.php b/tests/unit/DocBlock/Tags/TemplateImplementsTest.php new file mode 100644 index 0000000..2e1f319 --- /dev/null +++ b/tests/unit/DocBlock/Tags/TemplateImplementsTest.php @@ -0,0 +1,30 @@ +assertSame('template-implements', $fixture->getName()); + $this->assertSame($type, $fixture->getType()); + } + + public function testRendersCorrectly(): void + { + $type = new Object_(new Fqsen('\\Type')); + $fixture = new TemplateImplements($type); + $this->assertSame('@template-implements \\Type', $fixture->render()); + } +} diff --git a/tests/unit/DocBlock/Tags/TemplateTest.php b/tests/unit/DocBlock/Tags/TemplateTest.php new file mode 100644 index 0000000..7154053 --- /dev/null +++ b/tests/unit/DocBlock/Tags/TemplateTest.php @@ -0,0 +1,38 @@ + + */ +final class TemplateTest extends TestCase +{ + /** + * @covers ::__construct + * @covers ::getTemplateName + * @covers ::getBound + * @covers ::getDefault + */ + public function testTemplateCreatedCorrectly(): void + { + $fixture = new Template('myTemplate', new String_(), new Mixed_(), new Description('')); + $this->assertSame('template', $fixture->getName()); + $this->assertSame('myTemplate', $fixture->getTemplateName()); + $this->assertEquals(new String_(), $fixture->getBound()); + $this->assertEquals(new Mixed_(), $fixture->getDefault()); + } + + public function testRendersCorrectly(): void + { + $fixture = new Template('myTemplate', new String_(), null, new Description('')); + $this->assertSame('@template myTemplate of string', $fixture->render()); + } +}