Completed
Push — master ( e3324e...f8d350 )
by Jaap
10:07 queued 10s
created

testFactoryMethodWithSpaceBeforeClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * This file is part of phpDocumentor.
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @link      http://phpdoc.org
12
 */
13
14
namespace phpDocumentor\Reflection\DocBlock\Tags;
15
16
use Mockery as m;
17
use phpDocumentor\Reflection\DocBlock\Description;
18
use phpDocumentor\Reflection\DocBlock\DescriptionFactory;
19
use phpDocumentor\Reflection\DocBlock\StandardTagFactory;
20
use phpDocumentor\Reflection\Fqsen;
21
use phpDocumentor\Reflection\FqsenResolver;
22
use phpDocumentor\Reflection\Types\Context;
23
use PHPUnit\Framework\TestCase;
24
25
/**
26
 * @coversDefaultClass \phpDocumentor\Reflection\DocBlock\Tags\Covers
27
 * @covers ::<private>
28
 */
29
class CoversTest extends TestCase
30
{
31
    /**
32
     * Call Mockery::close after each test.
33
     */
34
    public function tearDown() : void
35
    {
36
        m::close();
37
    }
38
39
    /**
40
     * @uses   \phpDocumentor\Reflection\DocBlock\Tags\Covers::__construct
41
     * @uses   \phpDocumentor\Reflection\DocBlock\Description
42
     *
43
     * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName
44
     */
45
    public function testIfCorrectTagNameIsReturned() : void
46
    {
47
        $fixture = new Covers(new Fqsen('\DateTime'), new Description('Description'));
48
49
        $this->assertSame('covers', $fixture->getName());
50
    }
51
52
    /**
53
     * @uses   \phpDocumentor\Reflection\DocBlock\Tags\Covers::__construct
54
     * @uses   \phpDocumentor\Reflection\DocBlock\Tags\Covers::__toString
55
     * @uses   \phpDocumentor\Reflection\DocBlock\Tags\Formatter\PassthroughFormatter
56
     * @uses   \phpDocumentor\Reflection\DocBlock\Description
57
     *
58
     * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render
59
     * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getName
60
     */
61
    public function testIfTagCanBeRenderedUsingDefaultFormatter() : void
62
    {
63
        $fixture = new Covers(new Fqsen('\DateTime'), new Description('Description'));
64
65
        $this->assertSame('@covers \DateTime Description', $fixture->render());
66
    }
67
68
    /**
69
     * @uses   \phpDocumentor\Reflection\DocBlock\Tags\Covers::__construct
70
     * @uses   \phpDocumentor\Reflection\DocBlock\Description
71
     *
72
     * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::render
73
     */
74
    public function testIfTagCanBeRenderedUsingSpecificFormatter() : void
75
    {
76
        $fixture = new Covers(new Fqsen('\DateTime'), new Description('Description'));
77
78
        $formatter = m::mock(Formatter::class);
79
        $formatter->shouldReceive('format')->with($fixture)->andReturn('Rendered output');
80
81
        $this->assertSame('Rendered output', $fixture->render($formatter));
82
    }
83
84
    /**
85
     * @covers ::__construct
86
     * @covers ::getReference
87
     */
88
    public function testHasReferenceToFqsen() : void
89
    {
90
        $expected = new Fqsen('\DateTime');
91
92
        $fixture = new Covers($expected);
93
94
        $this->assertSame($expected, $fixture->getReference());
95
    }
96
97
    /**
98
     * @uses   \phpDocumentor\Reflection\DocBlock\Description
99
     *
100
     * @covers ::__construct
101
     * @covers \phpDocumentor\Reflection\DocBlock\Tags\BaseTag::getDescription
102
     */
103
    public function testHasDescription() : void
104
    {
105
        $expected = new Description('Description');
106
107
        $fixture = new Covers(new Fqsen('\DateTime'), $expected);
108
109
        $this->assertSame($expected, $fixture->getDescription());
110
    }
111
112
    /**
113
     * @uses   \phpDocumentor\Reflection\DocBlock\Description
114
     *
115
     * @covers ::__construct
116
     * @covers ::__toString
117
     */
118
    public function testStringRepresentationIsReturned() : void
119
    {
120
        $fixture = new Covers(new Fqsen('\DateTime'), new Description('Description'));
121
122
        $this->assertSame('\DateTime Description', (string) $fixture);
123
    }
124
125
    /**
126
     * @uses \phpDocumentor\Reflection\DocBlock\Tags\Covers::<public>
127
     * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
128
     * @uses \phpDocumentor\Reflection\FqsenResolver
129
     * @uses \phpDocumentor\Reflection\DocBlock\Description
130
     * @uses \phpDocumentor\Reflection\Fqsen
131
     * @uses \phpDocumentor\Reflection\Types\Context
132
     *
133
     * @covers ::create
134
     */
135
    public function testFactoryMethod() : void
136
    {
137
        $descriptionFactory = m::mock(DescriptionFactory::class);
138
        $resolver           = m::mock(FqsenResolver::class);
139
        $context            = new Context('');
140
141
        $fqsen       = new Fqsen('\DateTime');
142
        $description = new Description('My Description');
143
144
        $descriptionFactory
145
            ->shouldReceive('create')->with('My Description', $context)->andReturn($description);
146
        $resolver->shouldReceive('resolve')->with('DateTime', $context)->andReturn($fqsen);
147
148
        $fixture = Covers::create('DateTime My Description', $descriptionFactory, $resolver, $context);
149
150
        $this->assertSame('\DateTime My Description', (string) $fixture);
151
        $this->assertSame($fqsen, $fixture->getReference());
152
        $this->assertSame($description, $fixture->getDescription());
153
    }
154
155
    /**
156
     * @covers ::__construct
157
     * @covers ::__toString
158
     */
159
    public function testStringRepresentationIsReturnedWithoutDescription() : void
160
    {
161
        $fixture = new Covers(new Fqsen('\\'));
162
163
        $this->assertSame('\\', (string) $fixture);
164
165
        // ---
166
167
        $fixture = new Covers(new Fqsen('\DateTime'));
168
169
        $this->assertSame('\DateTime', (string) $fixture);
170
171
        // ---
172
173
        $fixture = new Covers(new Fqsen('\DateTime'), new Description(''));
174
175
        $this->assertSame('\DateTime', (string) $fixture);
176
    }
177
178
    /**
179
     * @uses \phpDocumentor\Reflection\DocBlock\Tags\See::<public>
180
     * @uses \phpDocumentor\Reflection\DocBlock\DescriptionFactory
181
     * @uses \phpDocumentor\Reflection\FqsenResolver
182
     * @uses \phpDocumentor\Reflection\DocBlock\Description
183
     * @uses \phpDocumentor\Reflection\DocBlock\Tags\Reference\Url
184
     * @uses \phpDocumentor\Reflection\Types\Context
185
     *
186
     * @covers ::create
187
     */
188
    public function testFactoryMethodWithSpaceBeforeClass() : void
189
    {
190
        $fqsenResolver      = new FqsenResolver();
191
        $tagFactory         = new StandardTagFactory($fqsenResolver);
192
        $descriptionFactory = new DescriptionFactory($tagFactory);
193
        $context            = new Context('');
194
195
        $fixture = Covers::create(
196
            'Foo My Description ',
197
            $descriptionFactory,
198
            $fqsenResolver,
199
            $context
200
        );
201
202
        $this->assertSame('\Foo My Description ', (string) $fixture);
203
        $this->assertSame('\Foo', (string) $fixture->getReference());
204
        $this->assertSame('My Description ', $fixture->getDescription() . '');
205
    }
206
207
    /**
208
     * @covers ::__construct
209
     * @covers ::__toString
210
     */
211
    public function testStringRepresentationIsReturnedWithDescription() : void
212
    {
213
        $fixture = new Covers(new Fqsen('\DateTime'), new Description('My Description'));
214
215
        $this->assertSame('\DateTime My Description', (string) $fixture);
216
    }
217
218
    /**
219
     * @covers ::create
220
     */
221
    public function testFactoryMethodFailsIfBodyIsNotEmpty() : void
222
    {
223
        $this->expectException('InvalidArgumentException');
224
        $this->assertNull(Covers::create(''));
225
    }
226
}
227