From 97863e0c448c91824bc8d924acd4bb9a6792a4f9 Mon Sep 17 00:00:00 2001 From: Lars Moelleken Date: Thu, 3 Sep 2020 00:33:09 +0200 Subject: [PATCH] add more unit tests and normalize the "__toString" methods --- src/DocBlock/Tags/Author.php | 10 +++++- src/DocBlock/Tags/Covers.php | 10 +++++- src/DocBlock/Tags/Deprecated.php | 10 +++++- src/DocBlock/Tags/Example.php | 5 ++- src/DocBlock/Tags/Generic.php | 8 ++++- src/DocBlock/Tags/Link.php | 10 +++++- src/DocBlock/Tags/Method.php | 23 +++++++++++--- src/DocBlock/Tags/Param.php | 22 ++++++++++--- src/DocBlock/Tags/Property.php | 20 ++++++++++-- src/DocBlock/Tags/PropertyRead.php | 20 ++++++++++-- src/DocBlock/Tags/PropertyWrite.php | 20 ++++++++++-- src/DocBlock/Tags/Return_.php | 10 +++++- src/DocBlock/Tags/See.php | 10 +++++- src/DocBlock/Tags/Since.php | 10 +++++- src/DocBlock/Tags/Source.php | 16 ++++++++-- src/DocBlock/Tags/Throws.php | 10 +++++- src/DocBlock/Tags/Uses.php | 10 +++++- src/DocBlock/Tags/Var_.php | 20 ++++++++++-- src/DocBlock/Tags/Version.php | 11 +++++-- tests/unit/DocBlock/Tags/AuthorTest.php | 17 +++++++++++ tests/unit/DocBlock/Tags/CoversTest.php | 34 +++++++++++++++++++++ tests/unit/DocBlock/Tags/DeprecatedTest.php | 31 +++++++++++++++++++ tests/unit/DocBlock/Tags/ExampleTest.php | 12 ++++---- tests/unit/DocBlock/Tags/GenericTest.php | 20 ++++++++++++ tests/unit/DocBlock/Tags/LinkTest.php | 19 ++++++++++++ tests/unit/DocBlock/Tags/MethodTest.php | 30 ++++++++++++++++++ tests/unit/DocBlock/Tags/ReturnTest.php | 19 ++++++++++++ tests/unit/DocBlock/Tags/SeeTest.php | 21 +++++++++++++ tests/unit/DocBlock/Tags/SinceTest.php | 19 ++++++++++++ tests/unit/DocBlock/Tags/SourceTest.php | 26 ++++++++++++++++ tests/unit/DocBlock/Tags/ThrowsTest.php | 25 +++++++++++++++ tests/unit/DocBlock/Tags/UsesTest.php | 19 ++++++++++++ tests/unit/DocBlock/Tags/VarTest.php | 26 ++++++++++++++++ tests/unit/DocBlock/Tags/VersionTest.php | 19 ++++++++++++ 34 files changed, 548 insertions(+), 44 deletions(-) diff --git a/src/DocBlock/Tags/Author.php b/src/DocBlock/Tags/Author.php index f3c49ad..d120757 100644 --- a/src/DocBlock/Tags/Author.php +++ b/src/DocBlock/Tags/Author.php @@ -71,7 +71,15 @@ final class Author extends BaseTag implements Factory\StaticMethod */ public function __toString() : string { - return $this->authorName . ($this->authorEmail !== '' ? ' <' . $this->authorEmail . '>' : ''); + if ($this->authorEmail) { + $authorEmail = '<' . $this->authorEmail . '>'; + } else { + $authorEmail = ''; + } + + $authorName = (string) $this->authorName; + + return $authorName . ($authorEmail !== '' ? ($authorName !== '' ? ' ' : '') . $authorEmail : ''); } /** diff --git a/src/DocBlock/Tags/Covers.php b/src/DocBlock/Tags/Covers.php index 820d595..0482353 100644 --- a/src/DocBlock/Tags/Covers.php +++ b/src/DocBlock/Tags/Covers.php @@ -72,6 +72,14 @@ final class Covers extends BaseTag implements Factory\StaticMethod */ public function __toString() : string { - return $this->refers . ($this->description ? ' ' . $this->description->render() : ''); + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $refers = (string) $this->refers; + + return $refers . ($description !== '' ? ($refers !== '' ? ' ' : '') . $description : ''); } } diff --git a/src/DocBlock/Tags/Deprecated.php b/src/DocBlock/Tags/Deprecated.php index 9b05d22..68e8f03 100644 --- a/src/DocBlock/Tags/Deprecated.php +++ b/src/DocBlock/Tags/Deprecated.php @@ -95,6 +95,14 @@ final class Deprecated extends BaseTag implements Factory\StaticMethod */ public function __toString() : string { - return ($this->version ?? '') . ($this->description ? ' ' . $this->description->render() : ''); + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $version = (string) $this->version; + + return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : ''); } } diff --git a/src/DocBlock/Tags/Example.php b/src/DocBlock/Tags/Example.php index 8ccb4fd..2853673 100644 --- a/src/DocBlock/Tags/Example.php +++ b/src/DocBlock/Tags/Example.php @@ -142,7 +142,10 @@ final class Example implements Tag, Factory\StaticMethod */ public function __toString() : string { - return $this->filePath . ($this->content ? ' ' . $this->content : ''); + $filePath = (string) $this->filePath; + $content = (string) $this->content; + + return $filePath . ($content !== '' ? ($filePath !== '' ? ' ' : '') . $content : ''); } /** diff --git a/src/DocBlock/Tags/Generic.php b/src/DocBlock/Tags/Generic.php index 7509ff1..a7b423f 100644 --- a/src/DocBlock/Tags/Generic.php +++ b/src/DocBlock/Tags/Generic.php @@ -64,7 +64,13 @@ final class Generic extends BaseTag implements Factory\StaticMethod */ public function __toString() : string { - return $this->description ? $this->description->render() : ''; + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + return $description; } /** diff --git a/src/DocBlock/Tags/Link.php b/src/DocBlock/Tags/Link.php index e912e48..226bbe0 100644 --- a/src/DocBlock/Tags/Link.php +++ b/src/DocBlock/Tags/Link.php @@ -65,6 +65,14 @@ final class Link extends BaseTag implements Factory\StaticMethod */ public function __toString() : string { - return $this->link . ($this->description ? ' ' . $this->description->render() : ''); + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $link = (string) $this->link; + + return $link . ($description !== '' ? ($link !== '' ? ' ' : '') . $description : ''); } } diff --git a/src/DocBlock/Tags/Method.php b/src/DocBlock/Tags/Method.php index 834f1bd..e568363 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -212,12 +212,25 @@ final class Method extends BaseTag implements Factory\StaticMethod foreach ($this->arguments as $argument) { $arguments[] = $argument['type'] . ' $' . $argument['name']; } + $argumentStr = '(' . implode(', ', $arguments) . ')'; - return trim(($this->isStatic() ? 'static ' : '') - . (string) $this->returnType . ' ' - . $this->methodName - . '(' . implode(', ', $arguments) . ')' - . ($this->description ? ' ' . $this->description->render() : '')); + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $static = $this->isStatic ? 'static' : ''; + + $returnType = (string) $this->returnType; + + $methodName = (string) $this->methodName; + + return $static + . ($returnType !== '' ? ($static !== '' ? ' ' : '') . $returnType : '') + . ($methodName !== '' ? ($static !== '' || $returnType !== '' ? ' ' : '') . $methodName : '') + . $argumentStr + . ($description !== '' ? ' ' . $description : ''); } /** diff --git a/src/DocBlock/Tags/Param.php b/src/DocBlock/Tags/Param.php index 3f272d0..9b5d8b7 100644 --- a/src/DocBlock/Tags/Param.php +++ b/src/DocBlock/Tags/Param.php @@ -140,11 +140,23 @@ final class Param extends TagWithType implements Factory\StaticMethod */ public function __toString() : string { - return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '') - . ($this->isReference() ? '&' : '') - . ($this->isVariadic() ? '...' : '') - . ($this->variableName ? '$' . $this->variableName : '') - . (('' . $this->description) ? ' ' . $this->description : ''); + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $variableName = ''; + if ($this->variableName) { + $variableName .= ($this->isReference ? '&' : '') . ($this->isVariadic ? '...' : ''); + $variableName .= ($this->variableName ? '$' . $this->variableName : ''); + } + + $type = (string) $this->type; + + return $type + . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); } private static function strStartsWithVariable(string $str) : bool diff --git a/src/DocBlock/Tags/Property.php b/src/DocBlock/Tags/Property.php index 866b919..b832156 100644 --- a/src/DocBlock/Tags/Property.php +++ b/src/DocBlock/Tags/Property.php @@ -98,8 +98,22 @@ final class Property extends TagWithType implements Factory\StaticMethod */ public function __toString() : string { - return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '') - . ($this->variableName ? '$' . $this->variableName : '') - . (('' . $this->description) ? ' ' . $this->description : ''); + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + if ($this->variableName) { + $variableName = ($this->variableName ? '$' . $this->variableName : ''); + } else { + $variableName = ''; + } + + $type = (string) $this->type; + + return $type + . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); } } diff --git a/src/DocBlock/Tags/PropertyRead.php b/src/DocBlock/Tags/PropertyRead.php index 9a10d6e..674a7b0 100644 --- a/src/DocBlock/Tags/PropertyRead.php +++ b/src/DocBlock/Tags/PropertyRead.php @@ -98,8 +98,22 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod */ public function __toString() : string { - return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '') - . ($this->variableName ? '$' . $this->variableName : '') - . (('' . $this->description) ? ' ' . $this->description : ''); + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + if ($this->variableName) { + $variableName = ($this->variableName ? '$' . $this->variableName : ''); + } else { + $variableName = ''; + } + + $type = (string) $this->type; + + return $type + . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); } } diff --git a/src/DocBlock/Tags/PropertyWrite.php b/src/DocBlock/Tags/PropertyWrite.php index b4f6296..4962461 100644 --- a/src/DocBlock/Tags/PropertyWrite.php +++ b/src/DocBlock/Tags/PropertyWrite.php @@ -98,8 +98,22 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod */ public function __toString() : string { - return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '') - . ($this->variableName ? '$' . $this->variableName : '') - . (('' . $this->description) ? ' ' . $this->description : ''); + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + if ($this->variableName) { + $variableName = ($this->variableName ? '$' . $this->variableName : ''); + } else { + $variableName = ''; + } + + $type = (string) $this->type; + + return $type + . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); } } diff --git a/src/DocBlock/Tags/Return_.php b/src/DocBlock/Tags/Return_.php index 60ba860..546a0ea 100644 --- a/src/DocBlock/Tags/Return_.php +++ b/src/DocBlock/Tags/Return_.php @@ -51,6 +51,14 @@ final class Return_ extends TagWithType implements Factory\StaticMethod public function __toString() : string { - return ($this->type ?: 'mixed') . ' ' . (string) $this->description; + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $type = $this->type ? '' . $this->type : 'mixed'; + + return $type . ($description !== '' ? ($type !== '' ? ' ' : '') . $description : ''); } } diff --git a/src/DocBlock/Tags/See.php b/src/DocBlock/Tags/See.php index e71401d..6d7b1b1 100644 --- a/src/DocBlock/Tags/See.php +++ b/src/DocBlock/Tags/See.php @@ -77,6 +77,14 @@ final class See extends BaseTag implements Factory\StaticMethod */ public function __toString() : string { - return $this->refers . ($this->description ? ' ' . $this->description->render() : ''); + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $refers = (string) $this->refers; + + return $refers . ($description !== '' ? ($refers !== '' ? ' ' : '') . $description : ''); } } diff --git a/src/DocBlock/Tags/Since.php b/src/DocBlock/Tags/Since.php index dc12624..32de527 100644 --- a/src/DocBlock/Tags/Since.php +++ b/src/DocBlock/Tags/Since.php @@ -89,6 +89,14 @@ final class Since extends BaseTag implements Factory\StaticMethod */ public function __toString() : string { - return (string) $this->version . ($this->description ? ' ' . (string) $this->description : ''); + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $version = (string) $this->version; + + return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : ''); } } diff --git a/src/DocBlock/Tags/Source.php b/src/DocBlock/Tags/Source.php index 6d3c6cb..78ea7fd 100644 --- a/src/DocBlock/Tags/Source.php +++ b/src/DocBlock/Tags/Source.php @@ -96,8 +96,18 @@ final class Source extends BaseTag implements Factory\StaticMethod public function __toString() : string { - return $this->startingLine - . ($this->lineCount !== null ? ' ' . $this->lineCount : '') - . ($this->description ? ' ' . (string) $this->description : ''); + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $startingLine = (string) $this->startingLine; + + $lineCount = $this->lineCount !== null ? '' . $this->lineCount : ''; + + return $startingLine + . ($lineCount !== '' ? ($startingLine !== '' ? ' ' : '') . $lineCount : '') + . ($description !== '' ? ($startingLine !== '' || $lineCount !== '' ? ' ' : '') . $description : ''); } } diff --git a/src/DocBlock/Tags/Throws.php b/src/DocBlock/Tags/Throws.php index 13f07ce..d4dc947 100644 --- a/src/DocBlock/Tags/Throws.php +++ b/src/DocBlock/Tags/Throws.php @@ -51,6 +51,14 @@ final class Throws extends TagWithType implements Factory\StaticMethod public function __toString() : string { - return (string) $this->type . ' ' . (string) $this->description; + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $type = (string) $this->type; + + return $type . ($description !== '' ? ($type !== '' ? ' ' : '') . $description : ''); } } diff --git a/src/DocBlock/Tags/Uses.php b/src/DocBlock/Tags/Uses.php index 57fb290..3ed83b6 100644 --- a/src/DocBlock/Tags/Uses.php +++ b/src/DocBlock/Tags/Uses.php @@ -71,6 +71,14 @@ final class Uses extends BaseTag implements Factory\StaticMethod */ public function __toString() : string { - return $this->refers . ' ' . (string) $this->description; + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $refers = (string) $this->refers; + + return $refers . ($description !== '' ? ($refers !== '' ? ' ' : '') . $description : ''); } } diff --git a/src/DocBlock/Tags/Var_.php b/src/DocBlock/Tags/Var_.php index 1683d10..90729a2 100644 --- a/src/DocBlock/Tags/Var_.php +++ b/src/DocBlock/Tags/Var_.php @@ -99,8 +99,22 @@ final class Var_ extends TagWithType implements Factory\StaticMethod */ public function __toString() : string { - return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '') - . ($this->variableName ? '$' . $this->variableName : '') - . (('' . $this->description) ? ' ' . $this->description : ''); + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + if ($this->variableName) { + $variableName = ($this->variableName ? '$' . $this->variableName : ''); + } else { + $variableName = ''; + } + + $type = (string) $this->type; + + return $type + . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); } } diff --git a/src/DocBlock/Tags/Version.php b/src/DocBlock/Tags/Version.php index eaadf4d..460c86d 100644 --- a/src/DocBlock/Tags/Version.php +++ b/src/DocBlock/Tags/Version.php @@ -92,7 +92,14 @@ final class Version extends BaseTag implements Factory\StaticMethod */ public function __toString() : string { - return ((string) $this->version) . - ($this->description instanceof Description ? ' ' . $this->description->render() : ''); + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + $version = (string) $this->version; + + return $version . ($description !== '' ? ($version !== '' ? ' ' : '') . $description : ''); } } diff --git a/tests/unit/DocBlock/Tags/AuthorTest.php b/tests/unit/DocBlock/Tags/AuthorTest.php index 59e4cda..8db3887 100644 --- a/tests/unit/DocBlock/Tags/AuthorTest.php +++ b/tests/unit/DocBlock/Tags/AuthorTest.php @@ -116,6 +116,23 @@ class AuthorTest extends TestCase $fixture = new Author('Mike van Riel', 'mike@phpdoc.org'); $this->assertSame('Mike van Riel ', (string) $fixture); + + // --- + + $fixture = new Author('0', 'zero@foo.bar'); + + $this->assertSame('0 ', (string) $fixture); + } + + /** + * @covers ::__construct + * @covers ::__toString + */ + public function testStringRepresentationIsReturnedWithoutName() : void + { + $fixture = new Author('', 'mike@phpdoc.org'); + + $this->assertSame('', (string) $fixture); } /** diff --git a/tests/unit/DocBlock/Tags/CoversTest.php b/tests/unit/DocBlock/Tags/CoversTest.php index f4319a9..93ece75 100644 --- a/tests/unit/DocBlock/Tags/CoversTest.php +++ b/tests/unit/DocBlock/Tags/CoversTest.php @@ -151,6 +151,40 @@ class CoversTest extends TestCase $this->assertSame($description, $fixture->getDescription()); } + /** + * @covers ::__construct + * @covers ::__toString + */ + public function testStringRepresentationIsReturnedWithoutDescription() : void + { + $fixture = new Covers(new Fqsen('\\')); + + $this->assertSame('\\', (string) $fixture); + + // --- + + $fixture = new Covers(new Fqsen('\DateTime')); + + $this->assertSame('\DateTime', (string) $fixture); + + // --- + + $fixture = new Covers(new Fqsen('\DateTime'), new Description('')); + + $this->assertSame('\DateTime', (string) $fixture); + } + + /** + * @covers ::__construct + * @covers ::__toString + */ + public function testStringRepresentationIsReturnedWithDescription() : void + { + $fixture = new Covers(new Fqsen('\DateTime'), new Description('My Description')); + + $this->assertSame('\DateTime My Description', (string) $fixture); + } + /** * @covers ::create */ diff --git a/tests/unit/DocBlock/Tags/DeprecatedTest.php b/tests/unit/DocBlock/Tags/DeprecatedTest.php index 9df9a7f..c5ef41a 100644 --- a/tests/unit/DocBlock/Tags/DeprecatedTest.php +++ b/tests/unit/DocBlock/Tags/DeprecatedTest.php @@ -117,6 +117,37 @@ class DeprecatedTest extends TestCase $fixture = new Deprecated('1.0', new Description('Description')); $this->assertSame('1.0 Description', (string) $fixture); + + // --- + + $fixture = new Deprecated(null, new Description('My Description')); + + $this->assertSame('My Description', (string) $fixture); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * + * @covers ::__construct + * @covers ::__toString + */ + public function testStringRepresentationIsReturnedWithoutDescription() : void + { + $fixture = new Deprecated(null, new Description('')); + + $this->assertSame('', (string) $fixture); + + // --- + + $fixture = new Deprecated('1.0', new Description('')); + + $this->assertSame('1.0', (string) $fixture); + + // --- + + $fixture = new Deprecated('1.0'); + + $this->assertSame('1.0', (string) $fixture); } /** diff --git a/tests/unit/DocBlock/Tags/ExampleTest.php b/tests/unit/DocBlock/Tags/ExampleTest.php index 77809d4..e6c123a 100644 --- a/tests/unit/DocBlock/Tags/ExampleTest.php +++ b/tests/unit/DocBlock/Tags/ExampleTest.php @@ -22,7 +22,7 @@ class ExampleTest extends TestCase } /** - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag * * @covers ::create * @covers ::__construct @@ -37,7 +37,7 @@ class ExampleTest extends TestCase } /** - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag * * @covers ::create * @covers ::__construct @@ -52,7 +52,7 @@ class ExampleTest extends TestCase } /** - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag * * @covers ::create * @covers ::__construct @@ -67,7 +67,7 @@ class ExampleTest extends TestCase } /** - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag * * @covers ::create * @covers ::__construct @@ -84,7 +84,7 @@ class ExampleTest extends TestCase } /** - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag * * @covers ::create * @covers ::__construct @@ -101,7 +101,7 @@ class ExampleTest extends TestCase } /** - * @uses phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag * * @covers ::create * @covers ::__construct diff --git a/tests/unit/DocBlock/Tags/GenericTest.php b/tests/unit/DocBlock/Tags/GenericTest.php index a3c8248..14287df 100644 --- a/tests/unit/DocBlock/Tags/GenericTest.php +++ b/tests/unit/DocBlock/Tags/GenericTest.php @@ -107,6 +107,26 @@ class GenericTest extends TestCase $this->assertSame('Description', (string) $fixture); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName + * + * @covers ::__construct + * @covers ::__toString + */ + public function testStringRepresentationIsReturnedWithoutDescription() : void + { + $fixture = new Generic('generic'); + + $this->assertSame('', (string) $fixture); + + // --- + + $fixture = new Generic('generic', new Description('')); + + $this->assertSame('', (string) $fixture); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory diff --git a/tests/unit/DocBlock/Tags/LinkTest.php b/tests/unit/DocBlock/Tags/LinkTest.php index 00c8fe5..6110189 100644 --- a/tests/unit/DocBlock/Tags/LinkTest.php +++ b/tests/unit/DocBlock/Tags/LinkTest.php @@ -119,6 +119,25 @@ class LinkTest extends TestCase $this->assertSame('http://this.is.my/link Description', (string) $fixture); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * + * @covers ::__construct + * @covers ::__toString + */ + public function testStringRepresentationIsReturnedWithoutDescription() : void + { + $fixture = new Link('http://this.is.my/link'); + + $this->assertSame('http://this.is.my/link', (string) $fixture); + + // --- + + $fixture = new Link('http://this.is.my/link', new Description('')); + + $this->assertSame('http://this.is.my/link', (string) $fixture); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Link:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory diff --git a/tests/unit/DocBlock/Tags/MethodTest.php b/tests/unit/DocBlock/Tags/MethodTest.php index 8156d07..3b5786e 100644 --- a/tests/unit/DocBlock/Tags/MethodTest.php +++ b/tests/unit/DocBlock/Tags/MethodTest.php @@ -268,6 +268,36 @@ class MethodTest extends TestCase ); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Method::isStatic + * + * @covers ::__construct + * @covers ::__toString + */ + public function testStringRepresentationIsReturnedWithoutDescription() : void + { + $fixture = new Method('myMethod', [], null, false, new Description('')); + + $this->assertSame( + 'void myMethod()', + (string) $fixture + ); + + // --- + + $arguments = [ + ['name' => 'argument1', 'type' => new String_()], + ['name' => 'argument2', 'type' => new Object_()], + ]; + $fixture = new Method('myMethod', $arguments, new Void_(), true); + + $this->assertSame( + 'static void myMethod(string $argument1, object $argument2)', + (string) $fixture + ); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Method:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory diff --git a/tests/unit/DocBlock/Tags/ReturnTest.php b/tests/unit/DocBlock/Tags/ReturnTest.php index aad958c..b93cc1a 100644 --- a/tests/unit/DocBlock/Tags/ReturnTest.php +++ b/tests/unit/DocBlock/Tags/ReturnTest.php @@ -122,6 +122,25 @@ class ReturnTest extends TestCase $this->assertSame('string Description', (string) $fixture); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * + * @covers ::__construct + * @covers ::__toString + */ + public function testStringRepresentationIsReturnedWithoutDescription() : void + { + $fixture = new Return_(new String_()); + + $this->assertSame('string', (string) $fixture); + + // --- + + $fixture = new Return_(new String_(), new Description('')); + + $this->assertSame('string', (string) $fixture); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Return_:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory diff --git a/tests/unit/DocBlock/Tags/SeeTest.php b/tests/unit/DocBlock/Tags/SeeTest.php index f9ed04c..891b870 100644 --- a/tests/unit/DocBlock/Tags/SeeTest.php +++ b/tests/unit/DocBlock/Tags/SeeTest.php @@ -135,6 +135,27 @@ class SeeTest extends TestCase $this->assertSame('\DateTime::format() Description', (string) $fixture); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen + * @uses \phpDocumentor\Reflection\Fqsen + * + * @covers ::__construct + * @covers ::__toString + */ + public function testStringRepresentationIsReturnedWithoutDescription() : void + { + $fixture = new See(new FqsenRef(new Fqsen('\DateTime::format()'))); + + $this->assertSame('\DateTime::format()', (string) $fixture); + + // --- + + $fixture = new See(new FqsenRef(new Fqsen('\DateTime::format()')), new Description('')); + + $this->assertSame('\DateTime::format()', (string) $fixture); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\See:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory diff --git a/tests/unit/DocBlock/Tags/SinceTest.php b/tests/unit/DocBlock/Tags/SinceTest.php index ff926d2..2296ec6 100644 --- a/tests/unit/DocBlock/Tags/SinceTest.php +++ b/tests/unit/DocBlock/Tags/SinceTest.php @@ -119,6 +119,25 @@ class SinceTest extends TestCase $this->assertSame('1.0 Description', (string) $fixture); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * + * @covers ::__construct + * @covers ::__toString + */ + public function testStringRepresentationIsReturnedWithoutDescription() : void + { + $fixture = new Since('1.0'); + + $this->assertSame('1.0', (string) $fixture); + + // --- + + $fixture = new Since('1.0', new Description('')); + + $this->assertSame('1.0', (string) $fixture); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Since:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory diff --git a/tests/unit/DocBlock/Tags/SourceTest.php b/tests/unit/DocBlock/Tags/SourceTest.php index 178d16e..26cd46a 100644 --- a/tests/unit/DocBlock/Tags/SourceTest.php +++ b/tests/unit/DocBlock/Tags/SourceTest.php @@ -137,6 +137,32 @@ class SourceTest extends TestCase $this->assertSame('1 10 Description', (string) $fixture); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\String_ + * + * @covers ::__construct + * @covers ::__toString + */ + public function testStringRepresentationIsReturnedWithoutDescription() : void + { + $fixture = new Source(1); + + $this->assertSame('1', (string) $fixture); + + // --- + + $fixture = new Source(1, 0); + + $this->assertSame('1 0', (string) $fixture); + + // --- + + $fixture = new Source(1, 10, new Description('')); + + $this->assertSame('1 10', (string) $fixture); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Source:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory diff --git a/tests/unit/DocBlock/Tags/ThrowsTest.php b/tests/unit/DocBlock/Tags/ThrowsTest.php index ab1f759..ddead29 100644 --- a/tests/unit/DocBlock/Tags/ThrowsTest.php +++ b/tests/unit/DocBlock/Tags/ThrowsTest.php @@ -120,6 +120,31 @@ class ThrowsTest extends TestCase $fixture = new Throws(new String_(), new Description('Description')); $this->assertSame('string Description', (string) $fixture); + + // --- + + $fixture = new Throws(new String_(), new Description('My Description')); + + $this->assertSame('string My Description', (string) $fixture); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * + * @covers ::__construct + * @covers ::__toString + */ + public function testStringRepresentationIsReturnedWithoutDescription() : void + { + $fixture = new Throws(new String_()); + + $this->assertSame('string', (string) $fixture); + + // --- + + $fixture = new Throws(new String_(), new Description('')); + + $this->assertSame('string', (string) $fixture); } /** diff --git a/tests/unit/DocBlock/Tags/UsesTest.php b/tests/unit/DocBlock/Tags/UsesTest.php index 979a675..f45d880 100644 --- a/tests/unit/DocBlock/Tags/UsesTest.php +++ b/tests/unit/DocBlock/Tags/UsesTest.php @@ -121,6 +121,25 @@ class UsesTest extends TestCase $this->assertSame('\DateTime Description', (string) $fixture); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * + * @covers ::__construct + * @covers ::__toString + */ + public function testStringRepresentationIsReturnedWithoutDescription() : void + { + $fixture = new Uses(new Fqsen('\DateTime')); + + $this->assertSame('\DateTime', (string) $fixture); + + // --- + + $fixture = new Uses(new Fqsen('\DateTime'), new Description('')); + + $this->assertSame('\DateTime', (string) $fixture); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Uses:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory diff --git a/tests/unit/DocBlock/Tags/VarTest.php b/tests/unit/DocBlock/Tags/VarTest.php index 63d3b97..176971d 100644 --- a/tests/unit/DocBlock/Tags/VarTest.php +++ b/tests/unit/DocBlock/Tags/VarTest.php @@ -154,6 +154,32 @@ class VarTest extends TestCase $this->assertSame('string $myVariable Description', (string) $fixture); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\String_ + * + * @covers ::__construct + * @covers ::__toString + */ + public function testStringRepresentationIsReturnedWithoutDescription() : void + { + $fixture = new Var_('myVariable'); + + $this->assertSame('$myVariable', (string) $fixture); + + // --- + + $fixture = new Var_('myVariable', new String_()); + + $this->assertSame('string $myVariable', (string) $fixture); + + // --- + + $fixture = new Var_('myVariable', new String_(), new Description('')); + + $this->assertSame('string $myVariable', (string) $fixture); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Var_:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory diff --git a/tests/unit/DocBlock/Tags/VersionTest.php b/tests/unit/DocBlock/Tags/VersionTest.php index 04ce027..c3c025d 100644 --- a/tests/unit/DocBlock/Tags/VersionTest.php +++ b/tests/unit/DocBlock/Tags/VersionTest.php @@ -119,6 +119,25 @@ class VersionTest extends TestCase $this->assertSame('1.0 Description', (string) $fixture); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Description + * + * @covers ::__construct + * @covers ::__toString + */ + public function testStringRepresentationIsReturnedWithoutDescription() : void + { + $fixture = new Version('1.0'); + + $this->assertSame('1.0', (string) $fixture); + + // --- + + $fixture = new Version('1.0', new Description('')); + + $this->assertSame('1.0', (string) $fixture); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Version:: * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory