diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index d3419fe5..cf2f4dba 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -46,7 +46,7 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Quick check code coverage level - run: php tests/coverage-checker.php 89 + run: php tests/coverage-checker.php 91 phpunit: name: Unit tests for PHP version ${{ matrix.php-versions }} on ${{ matrix.operating-system }} diff --git a/src/DocBlock/Tags/Author.php b/src/DocBlock/Tags/Author.php index f3c49ad5..d1207571 100644 --- a/src/DocBlock/Tags/Author.php +++ b/src/DocBlock/Tags/Author.php @@ -71,7 +71,15 @@ public function getEmail() : string */ 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 582be6ce..9e52e5e4 100644 --- a/src/DocBlock/Tags/Covers.php +++ b/src/DocBlock/Tags/Covers.php @@ -49,7 +49,7 @@ public static function create( ?FqsenResolver $resolver = null, ?TypeContext $context = null ) : self { - Assert::notEmpty($body); + Assert::stringNotEmpty($body); Assert::notNull($descriptionFactory); Assert::notNull($resolver); @@ -87,6 +87,14 @@ public function getReference() : Fqsen */ 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 9b05d22e..68e8f036 100644 --- a/src/DocBlock/Tags/Deprecated.php +++ b/src/DocBlock/Tags/Deprecated.php @@ -95,6 +95,14 @@ public function getVersion() : ?string */ 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 3673ffb3..3face1ef 100644 --- a/src/DocBlock/Tags/Example.php +++ b/src/DocBlock/Tags/Example.php @@ -45,9 +45,14 @@ final class Example implements Tag, Factory\StaticMethod /** @var string|null */ private $content; - public function __construct(string $filePath, bool $isURI, int $startingLine, int $lineCount, ?string $content) - { - Assert::notEmpty($filePath); + public function __construct( + string $filePath, + bool $isURI, + int $startingLine, + int $lineCount, + ?string $content + ) { + Assert::stringNotEmpty($filePath); Assert::greaterThanEq($startingLine, 1); Assert::greaterThanEq($lineCount, 0); @@ -64,7 +69,7 @@ public function __construct(string $filePath, bool $isURI, int $startingLine, in public function getContent() : string { if ($this->content === null || $this->content === '') { - $filePath = '"' . $this->filePath . '"'; + $filePath = $this->filePath; if ($this->isURI) { $filePath = $this->isUriRelative($this->filePath) ? str_replace('%2F', '/', rawurlencode($this->filePath)) @@ -85,7 +90,7 @@ public function getDescription() : ?string public static function create(string $body) : ?Tag { // File component: File path in quotes or File URI / Source information - if (!preg_match('/^(?:\"([^\"]+)\"|(\S+))(?:\s+(.*))?$/sux', $body, $matches)) { + if (!preg_match('/^\s*(?:(\"[^\"]+\")|(\S+))(?:\s+(.*))?$/sux', $body, $matches)) { return null; } @@ -134,7 +139,7 @@ public static function create(string $body) : ?Tag */ public function getFilePath() : string { - return $this->filePath; + return trim($this->filePath, '"'); } /** @@ -142,7 +147,22 @@ public function getFilePath() : string */ public function __toString() : string { - return $this->filePath . ($this->content ? ' ' . $this->content : ''); + $filePath = (string) $this->filePath; + $isDefaultLine = $this->startingLine === 1 && $this->lineCount === 0; + $startingLine = !$isDefaultLine ? (string) $this->startingLine : ''; + $lineCount = !$isDefaultLine ? (string) $this->lineCount : ''; + $content = (string) $this->content; + + return $filePath + . ($startingLine !== '' + ? ($filePath !== '' ? ' ' : '') . $startingLine + : '') + . ($lineCount !== '' + ? ($filePath !== '' || $startingLine !== '' ? ' ' : '') . $lineCount + : '') + . ($content !== '' + ? ($filePath !== '' || $startingLine !== '' || $lineCount !== '' ? ' ' : '') . $content + : ''); } /** diff --git a/src/DocBlock/Tags/Generic.php b/src/DocBlock/Tags/Generic.php index 7509ff1a..a7b423f5 100644 --- a/src/DocBlock/Tags/Generic.php +++ b/src/DocBlock/Tags/Generic.php @@ -64,7 +64,13 @@ public static function create( */ 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 e912e481..226bbe0f 100644 --- a/src/DocBlock/Tags/Link.php +++ b/src/DocBlock/Tags/Link.php @@ -65,6 +65,14 @@ public function getLink() : string */ 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 834f1bde..08c0407e 100644 --- a/src/DocBlock/Tags/Method.php +++ b/src/DocBlock/Tags/Method.php @@ -213,11 +213,25 @@ public function __toString() : string $arguments[] = $argument['type'] . ' $' . $argument['name']; } - return trim(($this->isStatic() ? 'static ' : '') - . (string) $this->returnType . ' ' - . $this->methodName - . '(' . implode(', ', $arguments) . ')' - . ($this->description ? ' ' . $this->description->render() : '')); + $argumentStr = '(' . implode(', ', $arguments) . ')'; + + 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 392b4f9e..83419e9c 100644 --- a/src/DocBlock/Tags/Param.php +++ b/src/DocBlock/Tags/Param.php @@ -75,7 +75,7 @@ public static function create( $isReference = false; // if the first item that is encountered is not a variable; it is a type - if ($firstPart && $firstPart[0] !== '$') { + if ($firstPart && !self::strStartsWithVariable($firstPart)) { $type = $typeResolver->resolve($firstPart, $context); } else { // first part is not a type; we should prepend it to the parts array for further processing @@ -83,20 +83,11 @@ public static function create( } // if the next item starts with a $ or ...$ or &$ or &...$ it must be the variable name - if (isset($parts[0]) - && - ( - strpos($parts[0], '$') === 0 - || - strpos($parts[0], '...$') === 0 - || - strpos($parts[0], '&$') === 0 - || - strpos($parts[0], '&...$') === 0 - ) - ) { + if (isset($parts[0]) && self::strStartsWithVariable($parts[0])) { $variableName = array_shift($parts); - array_shift($parts); + if ($type) { + array_shift($parts); + } Assert::notNull($variableName); @@ -149,10 +140,33 @@ public function isReference() : bool */ public function __toString() : string { - return ($this->type ? $this->type . ' ' : '') - . ($this->isReference() ? '&' : '') - . ($this->isVariadic() ? '...' : '') - . ($this->variableName !== null ? '$' . $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; + } + + $type = (string) $this->type; + + return $type + . ($variableName !== '' ? ($type !== '' ? ' ' : '') . $variableName : '') + . ($description !== '' ? ($type !== '' || $variableName !== '' ? ' ' : '') . $description : ''); + } + + private static function strStartsWithVariable(string $str) : bool + { + return strpos($str, '$') === 0 + || + strpos($str, '...$') === 0 + || + strpos($str, '&$') === 0 + || + strpos($str, '&...$') === 0; } } diff --git a/src/DocBlock/Tags/Property.php b/src/DocBlock/Tags/Property.php index d8b83b6f..03897578 100644 --- a/src/DocBlock/Tags/Property.php +++ b/src/DocBlock/Tags/Property.php @@ -68,10 +68,12 @@ public static function create( array_unshift($parts, $firstPart); } - // if the next item starts with a $ or ...$ it must be the variable name + // if the next item starts with a $ it must be the variable name if (isset($parts[0]) && strpos($parts[0], '$') === 0) { $variableName = array_shift($parts); - array_shift($parts); + if ($type) { + array_shift($parts); + } Assert::notNull($variableName); @@ -96,8 +98,22 @@ public function getVariableName() : ?string */ public function __toString() : string { - return ($this->type ? $this->type . ' ' : '') - . ($this->variableName ? '$' . $this->variableName : '') - . ($this->description ? ' ' . $this->description : ''); + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + if ($this->variableName) { + $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 087803c3..7ff55d50 100644 --- a/src/DocBlock/Tags/PropertyRead.php +++ b/src/DocBlock/Tags/PropertyRead.php @@ -68,10 +68,12 @@ public static function create( array_unshift($parts, $firstPart); } - // if the next item starts with a $ or ...$ it must be the variable name + // if the next item starts with a $ it must be the variable name if (isset($parts[0]) && strpos($parts[0], '$') === 0) { $variableName = array_shift($parts); - array_shift($parts); + if ($type) { + array_shift($parts); + } Assert::notNull($variableName); @@ -96,8 +98,22 @@ public function getVariableName() : ?string */ public function __toString() : string { - return ($this->type ? $this->type . ' ' : '') - . ($this->variableName ? '$' . $this->variableName : '') - . ($this->description ? ' ' . $this->description : ''); + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + if ($this->variableName) { + $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 176b63d7..cc1e4b61 100644 --- a/src/DocBlock/Tags/PropertyWrite.php +++ b/src/DocBlock/Tags/PropertyWrite.php @@ -68,10 +68,12 @@ public static function create( array_unshift($parts, $firstPart); } - // if the next item starts with a $ or ...$ it must be the variable name + // if the next item starts with a $ it must be the variable name if (isset($parts[0]) && strpos($parts[0], '$') === 0) { $variableName = array_shift($parts); - array_shift($parts); + if ($type) { + array_shift($parts); + } Assert::notNull($variableName); @@ -96,8 +98,22 @@ public function getVariableName() : ?string */ public function __toString() : string { - return ($this->type ? $this->type . ' ' : '') - . ($this->variableName ? '$' . $this->variableName : '') - . ($this->description ? ' ' . $this->description : ''); + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + if ($this->variableName) { + $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 60ba8603..546a0eaa 100644 --- a/src/DocBlock/Tags/Return_.php +++ b/src/DocBlock/Tags/Return_.php @@ -51,6 +51,14 @@ public static function create( 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 2c77f867..73311df7 100644 --- a/src/DocBlock/Tags/See.php +++ b/src/DocBlock/Tags/See.php @@ -92,6 +92,14 @@ public function getReference() : Reference */ 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 dc126240..32de527b 100644 --- a/src/DocBlock/Tags/Since.php +++ b/src/DocBlock/Tags/Since.php @@ -89,6 +89,14 @@ public function getVersion() : ?string */ 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 6d3c6cb7..f0c31014 100644 --- a/src/DocBlock/Tags/Source.php +++ b/src/DocBlock/Tags/Source.php @@ -96,8 +96,22 @@ public function getLineCount() : ?int 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 || $startingLine === '0' ? ' ' : '') . $lineCount + : '') + . ($description !== '' + ? ($startingLine || $startingLine === '0' || $lineCount !== '' ? ' ' : '') . $description + : ''); } } diff --git a/src/DocBlock/Tags/Throws.php b/src/DocBlock/Tags/Throws.php index 13f07cec..d4dc9472 100644 --- a/src/DocBlock/Tags/Throws.php +++ b/src/DocBlock/Tags/Throws.php @@ -51,6 +51,14 @@ public static function create( 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 2f6e8f1c..4d52afcc 100644 --- a/src/DocBlock/Tags/Uses.php +++ b/src/DocBlock/Tags/Uses.php @@ -86,6 +86,14 @@ public function getReference() : Fqsen */ 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 ac1c4380..762c262f 100644 --- a/src/DocBlock/Tags/Var_.php +++ b/src/DocBlock/Tags/Var_.php @@ -69,10 +69,12 @@ public static function create( array_unshift($parts, $firstPart); } - // if the next item starts with a $ or ...$ it must be the variable name + // if the next item starts with a $ it must be the variable name if (isset($parts[0]) && strpos($parts[0], '$') === 0) { $variableName = array_shift($parts); - array_shift($parts); + if ($type) { + array_shift($parts); + } Assert::notNull($variableName); @@ -97,8 +99,22 @@ public function getVariableName() : ?string */ public function __toString() : string { - return ($this->type ? $this->type . ' ' : '') - . (empty($this->variableName) ? '' : '$' . $this->variableName) - . ($this->description ? ' ' . $this->description : ''); + if ($this->description) { + $description = $this->description->render(); + } else { + $description = ''; + } + + if ($this->variableName) { + $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 eaadf4d3..460c86d7 100644 --- a/src/DocBlock/Tags/Version.php +++ b/src/DocBlock/Tags/Version.php @@ -92,7 +92,14 @@ public function getVersion() : ?string */ 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 cc06727e..2a1c45e1 100644 --- a/tests/unit/DocBlock/Tags/AuthorTest.php +++ b/tests/unit/DocBlock/Tags/AuthorTest.php @@ -116,6 +116,23 @@ public function testStringRepresentationIsReturned() : void $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 f4319a91..93ece759 100644 --- a/tests/unit/DocBlock/Tags/CoversTest.php +++ b/tests/unit/DocBlock/Tags/CoversTest.php @@ -151,6 +151,40 @@ public function testFactoryMethod() : void $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 9df9a7f7..c5ef41a2 100644 --- a/tests/unit/DocBlock/Tags/DeprecatedTest.php +++ b/tests/unit/DocBlock/Tags/DeprecatedTest.php @@ -117,6 +117,37 @@ public function testStringRepresentationIsReturned() : void $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 1d6d159f..3bf7aa04 100644 --- a/tests/unit/DocBlock/Tags/ExampleTest.php +++ b/tests/unit/DocBlock/Tags/ExampleTest.php @@ -93,6 +93,52 @@ public function testLengthIsParsed() : void $this->assertEquals(5, $tag->getLineCount()); } + /** + * @covers ::create + * @covers ::__toString + */ + public function testStringRepresentationIsReturned() : void + { + $tag = Example::create('"example1.php" 10 5 test text'); + + $this->assertSame('"example1.php" 10 5 test text', (string) $tag); + + // --- + + $tag = Example::create('file://example1.php'); + + $this->assertSame('file://example1.php', (string) $tag); + + // --- + + $tag = Example::create('0 foo bar'); + + $this->assertSame('0 foo bar', (string) $tag); + + // --- + + $tag = Example::create('$redisCluster->pttl(\'key\');'); + + $this->assertSame('$redisCluster->pttl(\'key\');', (string) $tag); + + // --- + + $tag = Example::create(' "example1.php" 10 5 test text '); + + $this->assertSame('"example1.php" 10 5 test text', (string) $tag); + } + + /** + * @covers ::create + * @covers ::__toString + */ + public function testStringRepresentationIsReturnedWithoutDescription() : void + { + $tag = Example::create(''); + + $this->assertSame('', (string) $tag); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag * diff --git a/tests/unit/DocBlock/Tags/GenericTest.php b/tests/unit/DocBlock/Tags/GenericTest.php index a3c82488..14287dff 100644 --- a/tests/unit/DocBlock/Tags/GenericTest.php +++ b/tests/unit/DocBlock/Tags/GenericTest.php @@ -107,6 +107,26 @@ public function testStringRepresentationIsReturned() : void $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 00c8fe5c..6110189b 100644 --- a/tests/unit/DocBlock/Tags/LinkTest.php +++ b/tests/unit/DocBlock/Tags/LinkTest.php @@ -119,6 +119,25 @@ public function testStringRepresentationIsReturned() : void $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 8156d07e..a07c98a3 100644 --- a/tests/unit/DocBlock/Tags/MethodTest.php +++ b/tests/unit/DocBlock/Tags/MethodTest.php @@ -268,6 +268,36 @@ public function testStringRepresentationIsReturned() : void ); } + /** + * @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/ParamTest.php b/tests/unit/DocBlock/Tags/ParamTest.php index 246b57e5..99a84dab 100644 --- a/tests/unit/DocBlock/Tags/ParamTest.php +++ b/tests/unit/DocBlock/Tags/ParamTest.php @@ -16,8 +16,11 @@ use Mockery as m; use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\StandardTagFactory; +use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context; +use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; @@ -270,6 +273,128 @@ public function testFactoryMethodWithVariadicReference() : void $this->assertSame($description, $fixture->getDescription()); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithReferenceWithoutType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = Param::create( + '&$myParameter My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('&$myParameter My Description', (string) $fixture); + $this->assertSame('myParameter', $fixture->getVariableName()); + $this->assertNull($fixture->getType()); + $this->assertFalse($fixture->isVariadic()); + $this->assertTrue($fixture->isReference()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithVariadicReferenceWithoutType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = Param::create( + '&...$myParameter My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('&...$myParameter My Description', (string) $fixture); + $this->assertSame('myParameter', $fixture->getVariableName()); + $this->assertNull($fixture->getType()); + $this->assertTrue($fixture->isVariadic()); + $this->assertTrue($fixture->isReference()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithoutType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = Param::create( + '$myParameter My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('$myParameter My Description', (string) $fixture); + $this->assertSame('myParameter', $fixture->getVariableName()); + $this->assertNull($fixture->getType()); + $this->assertFalse($fixture->isVariadic()); + $this->assertFalse($fixture->isReference()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = Param::create( + 'int My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('int My Description', (string) $fixture); + $this->assertSame('', $fixture->getVariableName()); + $this->assertInstanceOf(Integer::class, $fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: * @uses \phpDocumentor\Reflection\TypeResolver diff --git a/tests/unit/DocBlock/Tags/PropertyReadTest.php b/tests/unit/DocBlock/Tags/PropertyReadTest.php index 901b0907..d2b2ee8c 100644 --- a/tests/unit/DocBlock/Tags/PropertyReadTest.php +++ b/tests/unit/DocBlock/Tags/PropertyReadTest.php @@ -16,8 +16,11 @@ use Mockery as m; use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\StandardTagFactory; +use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context; +use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; @@ -169,6 +172,64 @@ public function testFactoryMethod() : void $this->assertSame($description, $fixture->getDescription()); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithoutType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = PropertyRead::create( + '$myParameter My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('$myParameter My Description', (string) $fixture); + $this->assertSame('myParameter', $fixture->getVariableName()); + $this->assertNull($fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = PropertyRead::create( + 'int My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('int My Description', (string) $fixture); + $this->assertSame('', $fixture->getVariableName()); + $this->assertInstanceOf(Integer::class, $fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyRead:: * @uses \phpDocumentor\Reflection\TypeResolver diff --git a/tests/unit/DocBlock/Tags/PropertyTest.php b/tests/unit/DocBlock/Tags/PropertyTest.php index ec0e7fc3..bf5258b7 100644 --- a/tests/unit/DocBlock/Tags/PropertyTest.php +++ b/tests/unit/DocBlock/Tags/PropertyTest.php @@ -16,8 +16,11 @@ use Mockery as m; use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\StandardTagFactory; +use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context; +use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; @@ -164,6 +167,64 @@ public function testFactoryMethod() : void $this->assertSame($description, $fixture->getDescription()); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithoutType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = Property::create( + '$myParameter My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('$myParameter My Description', (string) $fixture); + $this->assertSame('myParameter', $fixture->getVariableName()); + $this->assertNull($fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = Property::create( + 'int My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('int My Description', (string) $fixture); + $this->assertSame('', $fixture->getVariableName()); + $this->assertInstanceOf(Integer::class, $fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Property:: * @uses \phpDocumentor\Reflection\TypeResolver diff --git a/tests/unit/DocBlock/Tags/PropertyWriteTest.php b/tests/unit/DocBlock/Tags/PropertyWriteTest.php index 1c6124c2..e25b360f 100644 --- a/tests/unit/DocBlock/Tags/PropertyWriteTest.php +++ b/tests/unit/DocBlock/Tags/PropertyWriteTest.php @@ -16,8 +16,11 @@ use Mockery as m; use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\StandardTagFactory; +use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context; +use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; @@ -169,6 +172,64 @@ public function testFactoryMethod() : void $this->assertSame($description, $fixture->getDescription()); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithoutType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = PropertyWrite::create( + '$myParameter My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('$myParameter My Description', (string) $fixture); + $this->assertSame('myParameter', $fixture->getVariableName()); + $this->assertNull($fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = PropertyWrite::create( + 'int My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('int My Description', (string) $fixture); + $this->assertSame('', $fixture->getVariableName()); + $this->assertInstanceOf(Integer::class, $fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\PropertyWrite:: * @uses \phpDocumentor\Reflection\TypeResolver diff --git a/tests/unit/DocBlock/Tags/ReturnTest.php b/tests/unit/DocBlock/Tags/ReturnTest.php index aad958ce..b93cc1a2 100644 --- a/tests/unit/DocBlock/Tags/ReturnTest.php +++ b/tests/unit/DocBlock/Tags/ReturnTest.php @@ -122,6 +122,25 @@ public function testStringRepresentationIsReturned() : void $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 c8e56424..dd7236db 100644 --- a/tests/unit/DocBlock/Tags/SeeTest.php +++ b/tests/unit/DocBlock/Tags/SeeTest.php @@ -135,6 +135,27 @@ public function testStringRepresentationIsReturned() : void $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 ff926d2c..2296ec67 100644 --- a/tests/unit/DocBlock/Tags/SinceTest.php +++ b/tests/unit/DocBlock/Tags/SinceTest.php @@ -119,6 +119,25 @@ public function testStringRepresentationIsReturned() : void $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 178d16e0..26cd46aa 100644 --- a/tests/unit/DocBlock/Tags/SourceTest.php +++ b/tests/unit/DocBlock/Tags/SourceTest.php @@ -137,6 +137,32 @@ public function testStringRepresentationIsReturned() : void $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 ab1f759a..ddead29f 100644 --- a/tests/unit/DocBlock/Tags/ThrowsTest.php +++ b/tests/unit/DocBlock/Tags/ThrowsTest.php @@ -120,6 +120,31 @@ public function testStringRepresentationIsReturned() : void $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 979a6751..f45d880f 100644 --- a/tests/unit/DocBlock/Tags/UsesTest.php +++ b/tests/unit/DocBlock/Tags/UsesTest.php @@ -121,6 +121,25 @@ public function testStringRepresentationIsReturned() : void $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 409263ed..176971d3 100644 --- a/tests/unit/DocBlock/Tags/VarTest.php +++ b/tests/unit/DocBlock/Tags/VarTest.php @@ -16,8 +16,11 @@ use Mockery as m; use phpDocumentor\Reflection\DocBlock\Description; use phpDocumentor\Reflection\DocBlock\DescriptionFactory; +use phpDocumentor\Reflection\DocBlock\StandardTagFactory; +use phpDocumentor\Reflection\FqsenResolver; use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context; +use phpDocumentor\Reflection\Types\Integer; use phpDocumentor\Reflection\Types\String_; use PHPUnit\Framework\TestCase; @@ -151,6 +154,32 @@ public function testStringRepresentationIsReturned() : void $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 @@ -176,6 +205,93 @@ public function testFactoryMethod() : void $this->assertSame($description, $fixture->getDescription()); } + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithoutType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = Var_::create( + '$myParameter My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('$myParameter My Description', (string) $fixture); + $this->assertSame('myParameter', $fixture->getVariableName()); + $this->assertNull($fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithType() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = Var_::create( + 'int My Description', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('int My Description', (string) $fixture); + $this->assertSame('', $fixture->getVariableName()); + $this->assertInstanceOf(Integer::class, $fixture->getType()); + $this->assertSame('My Description', $fixture->getDescription() . ''); + } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Param:: + * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory + * @uses \phpDocumentor\Reflection\DocBlock\Description + * @uses \phpDocumentor\Reflection\Types\Context + * + * @covers ::create + */ + public function testFactoryMethodWithTypeWithoutComment() : void + { + $typeResolver = new TypeResolver(); + $fqsenResolver = new FqsenResolver(); + $tagFactory = new StandardTagFactory($fqsenResolver); + $descriptionFactory = new DescriptionFactory($tagFactory); + $context = new Context(''); + + $fixture = Var_::create( + 'int', + $typeResolver, + $descriptionFactory, + $context + ); + + $this->assertSame('int', (string) $fixture); + $this->assertSame('', $fixture->getVariableName()); + $this->assertInstanceOf(Integer::class, $fixture->getType()); + $this->assertSame('', $fixture->getDescription() . ''); + } + /** * @uses \phpDocumentor\Reflection\DocBlock\Tags\Var_:: * @uses \phpDocumentor\Reflection\TypeResolver diff --git a/tests/unit/DocBlock/Tags/VersionTest.php b/tests/unit/DocBlock/Tags/VersionTest.php index 04ce027e..c3c025d1 100644 --- a/tests/unit/DocBlock/Tags/VersionTest.php +++ b/tests/unit/DocBlock/Tags/VersionTest.php @@ -119,6 +119,25 @@ public function testStringRepresentationIsReturned() : void $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