From 899b4091990bc44873614b8b774d658511c566b0 Mon Sep 17 00:00:00 2001 From: Bozhidar Hristov Date: Mon, 11 Sep 2017 16:57:54 +0300 Subject: [PATCH] Add tests for `phpDocumentor\Reflection\DocBlock::getTags` --- tests/unit/DocBlock/DescriptionTest.php | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/tests/unit/DocBlock/DescriptionTest.php b/tests/unit/DocBlock/DescriptionTest.php index 9d9a4e9..d3ed94f 100644 --- a/tests/unit/DocBlock/DescriptionTest.php +++ b/tests/unit/DocBlock/DescriptionTest.php @@ -64,6 +64,58 @@ class DescriptionTest extends \PHPUnit_Framework_TestCase $this->assertSame($expected, (string)$fixture); } + /** + * @covers ::getTags + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag + */ + public function testDescriptionTagsGetter() + { + $body = '@JoinTable(name="table", joinColumns=%1$s, inverseJoinColumns=%2$s)'; + + $tag1 = new Generic('JoinColumn', new Description('(name="column_id", referencedColumnName="id")')); + $tag2 = new Generic('JoinColumn', new Description('(name="column_id_2", referencedColumnName="id")')); + + $tags = [ + $tag1, + $tag2, + ]; + + $fixture = new Description($body, $tags); + + $this->assertEquals(2, count($fixture->getTags())); + + $actualTags = $fixture->getTags(); + $this->assertSame($tags, $actualTags); + $this->assertSame($tag1, $actualTags[0]); + $this->assertSame($tag2, $actualTags[1]); + } + + /** + * @covers ::__construct + * @covers ::render + * @covers ::__toString + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic + * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag + * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter + */ + public function testDescriptionMultipleTagsCanBeCastToString() + { + $body = '@JoinTable(name="table", joinColumns=%1$s, inverseJoinColumns=%2$s)'; + + $tag1 = new Generic('JoinColumn', new Description('(name="column_id", referencedColumnName="id")')); + $tag2 = new Generic('JoinColumn', new Description('(name="column_id_2", referencedColumnName="id")')); + + $tags = [ + $tag1, + $tag2, + ]; + + $fixture = new Description($body, $tags); + $expected = '@JoinTable(name="table", joinColumns={@JoinColumn (name="column_id", referencedColumnName="id")}, inverseJoinColumns={@JoinColumn (name="column_id_2", referencedColumnName="id")})'; + $this->assertSame($expected, (string)$fixture); + } + /** * @covers ::__construct * @expectedException \InvalidArgumentException