Skip to content

Commit bbe0f54

Browse files
committed
add more unit tests and fixed the output v2
1 parent be6ed8b commit bbe0f54

File tree

6 files changed

+39
-10
lines changed

6 files changed

+39
-10
lines changed

src/DocBlock/Tags/Param.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,11 @@ public function isReference() : bool
140140
*/
141141
public function __toString() : string
142142
{
143-
return ($this->type ? $this->type . ' ' : '')
143+
return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '')
144144
. ($this->isReference() ? '&' : '')
145145
. ($this->isVariadic() ? '...' : '')
146146
. ($this->variableName ? '$' . $this->variableName : '')
147-
. ($this->description ? ($this->variableName ? ' ' : '') . $this->description : '');
147+
. (('' . $this->description) ? ' ' . $this->description : '');
148148
}
149149

150150
private static function strStartsWithVariable(string $str) : bool

src/DocBlock/Tags/Property.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public function getVariableName() : ?string
9898
*/
9999
public function __toString() : string
100100
{
101-
return ($this->type ? $this->type . ' ' : '')
101+
return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '')
102102
. ($this->variableName ? '$' . $this->variableName : '')
103-
. ($this->description ? ($this->variableName ? ' ' : '') . $this->description : '');
103+
. (('' . $this->description) ? ' ' . $this->description : '');
104104
}
105105
}

src/DocBlock/Tags/PropertyRead.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public function getVariableName() : ?string
9898
*/
9999
public function __toString() : string
100100
{
101-
return ($this->type ? $this->type . ' ' : '')
101+
return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '')
102102
. ($this->variableName ? '$' . $this->variableName : '')
103-
. ($this->description ? ($this->variableName ? ' ' : '') . $this->description : '');
103+
. (('' . $this->description) ? ' ' . $this->description : '');
104104
}
105105
}

src/DocBlock/Tags/PropertyWrite.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ public function getVariableName() : ?string
9898
*/
9999
public function __toString() : string
100100
{
101-
return ($this->type ? $this->type . ' ' : '')
101+
return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '')
102102
. ($this->variableName ? '$' . $this->variableName : '')
103-
. ($this->description ? ($this->variableName ? ' ' : '') . $this->description : '');
103+
. (('' . $this->description) ? ' ' . $this->description : '');
104104
}
105105
}

src/DocBlock/Tags/Var_.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ public function getVariableName() : ?string
9999
*/
100100
public function __toString() : string
101101
{
102-
return ($this->type ? $this->type . ' ' : '')
102+
return ($this->type ? $this->type . ($this->variableName ? ' ' : '') : '')
103103
. ($this->variableName ? '$' . $this->variableName : '')
104-
. ($this->description ? ($this->variableName ? ' ' : '') . $this->description : '');
104+
. (('' . $this->description) ? ' ' . $this->description : '');
105105
}
106106
}

tests/unit/DocBlock/Tags/VarTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,35 @@ public function testFactoryMethodWithType() : void
237237
$this->assertSame('My Description', $fixture->getDescription() . '');
238238
}
239239

240+
/**
241+
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Param::<public>
242+
* @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
243+
* @uses \phpDocumentor\Reflection\DocBlock\Description
244+
* @uses \phpDocumentor\Reflection\Types\Context
245+
*
246+
* @covers ::create
247+
*/
248+
public function testFactoryMethodWithTypeWithoutComment() : void
249+
{
250+
$typeResolver = new TypeResolver();
251+
$fqsenResolver = new FqsenResolver();
252+
$tagFactory = new StandardTagFactory($fqsenResolver);
253+
$descriptionFactory = new DescriptionFactory($tagFactory);
254+
$context = new Context('');
255+
256+
$fixture = Var_::create(
257+
'int',
258+
$typeResolver,
259+
$descriptionFactory,
260+
$context
261+
);
262+
263+
$this->assertSame('int', (string) $fixture);
264+
$this->assertSame('', $fixture->getVariableName());
265+
$this->assertInstanceOf(Integer::class, $fixture->getType());
266+
$this->assertSame('', $fixture->getDescription() . '');
267+
}
268+
240269
/**
241270
* @uses \phpDocumentor\Reflection\DocBlock\Tags\Var_::<public>
242271
* @uses \phpDocumentor\Reflection\TypeResolver

0 commit comments

Comments
 (0)