1 | <?php |
||
23 | class DescriptionTest extends TestCase |
||
24 | { |
||
25 | /** |
||
26 | * Call Mockery::close after each test. |
||
27 | */ |
||
28 | public function tearDown() |
||
29 | { |
||
30 | m::close(); |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * @covers ::__construct |
||
35 | * @covers ::render |
||
36 | * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic |
||
37 | * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
||
38 | * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter |
||
39 | */ |
||
40 | public function testDescriptionCanRenderUsingABodyWithPlaceholdersAndTags() |
||
41 | { |
||
42 | $body = 'This is a %1$s body.'; |
||
43 | $expected = 'This is a {@internal significant} body.'; |
||
44 | $tags = [new Generic('internal', new Description('significant '))]; |
||
45 | |||
46 | $fixture = new Description($body, $tags); |
||
47 | |||
48 | // without formatter (thus the PassthroughFormatter by default) |
||
49 | $this->assertSame($expected, $fixture->render()); |
||
50 | |||
51 | // with a custom formatter |
||
52 | $formatter = m::mock(PassthroughFormatter::class); |
||
53 | $formatter->shouldReceive('format')->with($tags[0])->andReturn('@internal significant'); |
||
54 | $this->assertSame($expected, $fixture->render($formatter)); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @covers ::__construct |
||
59 | * @covers ::render |
||
60 | * @covers ::__toString |
||
61 | * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic |
||
62 | * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
||
63 | * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter |
||
64 | */ |
||
65 | public function testDescriptionCanBeCastToString() |
||
66 | { |
||
67 | $body = 'This is a %1$s body.'; |
||
68 | $expected = 'This is a {@internal significant} body.'; |
||
69 | $tags = [new Generic('internal', new Description('significant '))]; |
||
70 | |||
71 | $fixture = new Description($body, $tags); |
||
72 | |||
73 | $this->assertSame($expected, (string)$fixture); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @covers ::getTags |
||
78 | * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic |
||
79 | * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
||
80 | */ |
||
81 | public function testDescriptionTagsGetter() |
||
82 | { |
||
83 | $body = '@JoinTable(name="table", joinColumns=%1$s, inverseJoinColumns=%2$s)'; |
||
84 | |||
85 | $tag1 = new Generic('JoinColumn', new Description('(name="column_id", referencedColumnName="id")')); |
||
86 | $tag2 = new Generic('JoinColumn', new Description('(name="column_id_2", referencedColumnName="id")')); |
||
87 | |||
88 | $tags = [ |
||
89 | $tag1, |
||
90 | $tag2, |
||
91 | ]; |
||
92 | |||
93 | $fixture = new Description($body, $tags); |
||
94 | |||
95 | $this->assertEquals(2, count($fixture->getTags())); |
||
96 | |||
97 | $actualTags = $fixture->getTags(); |
||
98 | $this->assertSame($tags, $actualTags); |
||
99 | $this->assertSame($tag1, $actualTags[0]); |
||
100 | $this->assertSame($tag2, $actualTags[1]); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * @covers ::__construct |
||
105 | * @covers ::render |
||
106 | * @covers ::__toString |
||
107 | * @uses \phpDocumentor\Reflection\DocBlock\Tags\Generic |
||
108 | * @uses \phpDocumentor\Reflection\DocBlock\Tags\BaseTag |
||
109 | * @uses \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter |
||
110 | */ |
||
111 | public function testDescriptionMultipleTagsCanBeCastToString() |
||
112 | { |
||
113 | $body = '@JoinTable(name="table", joinColumns=%1$s, inverseJoinColumns=%2$s)'; |
||
114 | |||
115 | $tag1 = new Generic('JoinColumn', new Description('(name="column_id", referencedColumnName="id")')); |
||
116 | $tag2 = new Generic('JoinColumn', new Description('(name="column_id_2", referencedColumnName="id")')); |
||
117 | |||
118 | $tags = [ |
||
119 | $tag1, |
||
120 | $tag2, |
||
121 | ]; |
||
122 | |||
123 | $fixture = new Description($body, $tags); |
||
124 | $expected = '@JoinTable(name="table", joinColumns={@JoinColumn (name="column_id", referencedColumnName="id")}, inverseJoinColumns={@JoinColumn (name="column_id_2", referencedColumnName="id")})'; |
||
125 | $this->assertSame($expected, (string)$fixture); |
||
126 | } |
||
127 | |||
128 | /** |
||
129 | * @covers ::__construct |
||
130 | * @expectedException \InvalidArgumentException |
||
131 | */ |
||
132 | public function testBodyTemplateMustBeAString() |
||
133 | { |
||
134 | new Description([]); |
||
135 | } |
||
136 | } |
||
137 |