From bbe0f54877d0db64ba59ae560222ea2300acc45e Mon Sep 17 00:00:00 2001 From: Lars Moelleken Date: Wed, 2 Sep 2020 22:55:00 +0200 Subject: [PATCH] add more unit tests and fixed the output v2 --- src/DocBlock/Tags/Param.php | 4 ++-- src/DocBlock/Tags/Property.php | 4 ++-- src/DocBlock/Tags/PropertyRead.php | 4 ++-- src/DocBlock/Tags/PropertyWrite.php | 4 ++-- src/DocBlock/Tags/Var_.php | 4 ++-- tests/unit/DocBlock/Tags/VarTest.php | 29 ++++++++++++++++++++++++++++ 6 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/DocBlock/Tags/Param.php b/src/DocBlock/Tags/Param.php index 650506f..3f272d0 100644 --- a/src/DocBlock/Tags/Param.php +++ b/src/DocBlock/Tags/Param.php @@ -140,11 +140,11 @@ final class Param extends TagWithType implements Factory\StaticMethod */ public function __toString() : string { - return ($this->type ? $this->type . ' ' : '') + return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '') . ($this->isReference() ? '&' : '') . ($this->isVariadic() ? '...' : '') . ($this->variableName ? '$' . $this->variableName : '') - . ($this->description ? ($this->variableName ? ' ' : '') . $this->description : ''); + . (('' . $this->description) ? ' ' . $this->description : ''); } private static function strStartsWithVariable(string $str) : bool diff --git a/src/DocBlock/Tags/Property.php b/src/DocBlock/Tags/Property.php index e358d98..866b919 100644 --- a/src/DocBlock/Tags/Property.php +++ b/src/DocBlock/Tags/Property.php @@ -98,8 +98,8 @@ final class Property extends TagWithType implements Factory\StaticMethod */ public function __toString() : string { - return ($this->type ? $this->type . ' ' : '') + return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '') . ($this->variableName ? '$' . $this->variableName : '') - . ($this->description ? ($this->variableName ? ' ' : '') . $this->description : ''); + . (('' . $this->description) ? ' ' . $this->description : ''); } } diff --git a/src/DocBlock/Tags/PropertyRead.php b/src/DocBlock/Tags/PropertyRead.php index 6118d32..9a10d6e 100644 --- a/src/DocBlock/Tags/PropertyRead.php +++ b/src/DocBlock/Tags/PropertyRead.php @@ -98,8 +98,8 @@ final class PropertyRead extends TagWithType implements Factory\StaticMethod */ public function __toString() : string { - return ($this->type ? $this->type . ' ' : '') + return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '') . ($this->variableName ? '$' . $this->variableName : '') - . ($this->description ? ($this->variableName ? ' ' : '') . $this->description : ''); + . (('' . $this->description) ? ' ' . $this->description : ''); } } diff --git a/src/DocBlock/Tags/PropertyWrite.php b/src/DocBlock/Tags/PropertyWrite.php index d1b5a4e..b4f6296 100644 --- a/src/DocBlock/Tags/PropertyWrite.php +++ b/src/DocBlock/Tags/PropertyWrite.php @@ -98,8 +98,8 @@ final class PropertyWrite extends TagWithType implements Factory\StaticMethod */ public function __toString() : string { - return ($this->type ? $this->type . ' ' : '') + return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '') . ($this->variableName ? '$' . $this->variableName : '') - . ($this->description ? ($this->variableName ? ' ' : '') . $this->description : ''); + . (('' . $this->description) ? ' ' . $this->description : ''); } } diff --git a/src/DocBlock/Tags/Var_.php b/src/DocBlock/Tags/Var_.php index f939a25..1683d10 100644 --- a/src/DocBlock/Tags/Var_.php +++ b/src/DocBlock/Tags/Var_.php @@ -99,8 +99,8 @@ final class Var_ extends TagWithType implements Factory\StaticMethod */ public function __toString() : string { - return ($this->type ? $this->type . ' ' : '') + return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '') . ($this->variableName ? '$' . $this->variableName : '') - . ($this->description ? ($this->variableName ? ' ' : '') . $this->description : ''); + . (('' . $this->description) ? ' ' . $this->description : ''); } } diff --git a/tests/unit/DocBlock/Tags/VarTest.php b/tests/unit/DocBlock/Tags/VarTest.php index 4a8235a..63d3b97 100644 --- a/tests/unit/DocBlock/Tags/VarTest.php +++ b/tests/unit/DocBlock/Tags/VarTest.php @@ -237,6 +237,35 @@ class VarTest extends TestCase $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