diff --git a/src/DocBlock/Description.php b/src/DocBlock/Description.php index 44131f44..fcbaede7 100644 --- a/src/DocBlock/Description.php +++ b/src/DocBlock/Description.php @@ -94,7 +94,7 @@ public function getTags(): array public function render(?Formatter $formatter = null): string { if ($this->tags === []) { - return $this->bodyTemplate; + return vsprintf($this->bodyTemplate, []); } if ($formatter === null) { diff --git a/tests/unit/DocBlock/DescriptionTest.php b/tests/unit/DocBlock/DescriptionTest.php index b4ddb492..76e6049e 100644 --- a/tests/unit/DocBlock/DescriptionTest.php +++ b/tests/unit/DocBlock/DescriptionTest.php @@ -142,4 +142,31 @@ public function testDescriptionMultipleTagsCanBeCastToString(): void . 'inverseJoinColumns={@JoinColumn (name="column_id_2", referencedColumnName="id")})'; $this->assertSame($expected, (string) $fixture); } + + /** + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter + * + * @covers ::__construct + * @covers ::render + * @covers ::__toString + */ + public function testDescriptionWithEscapedCharactersAndNoTagsCanBeCastToString(): void + { + //% chars are escaped in \phpDocumentor\Reflection\DocBlock\DescriptionFactory::create + $body = <<<'EOT' + {%% for user in users %%} + {{ user.name }} + {%% endfor %%}'; + EOT; + + $expected = <<<'EOT' + {% for user in users %} + {{ user.name }} + {% endfor %}'; + EOT; + + $fixture = new Description($body, []); + + $this->assertSame($expected, (string) $fixture); + } }