Completed
Push — develop ( 051570...d34eae )
by Jaap
06:16
created

SeeAssemblerTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 154
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 154
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 7

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 6 1
A testCreateSeeDescriptorFromSeeTagWhenReferenceIsRelativeClassnameNotInNamespaceAliasses() 0 20 1
A testCreateSeeDescriptorFromSeeTagWhenReferenceIsRelativeClassnameInNamespaceAliases() 0 20 1
A testCreateSeeDescriptorFromSeeTagWhenReferenceIsUrl() 0 19 1
A testCreateSeeDescriptorFromSeeTagWhenReferenceHasMultipleParts() 0 20 1
A givenASeeTag() 0 10 1
A givenADocBlock() 0 7 1
A givenAContext() 0 8 1
A provideReferences() 0 11 1
1
<?php
2
/**
3
 * This file is part of phpDocumentor.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @copyright 2010-2017 Mike van Riel<[email protected]>
9
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
10
 * @link      http://phpdoc.org
11
 */
12
13
namespace phpDocumentor\Descriptor\Builder\Reflector\Tags;
14
15
use Mockery as m;
16
use phpDocumentor\Descriptor\ProjectDescriptorBuilder;
17
18
/**
19
 * Test class for phpDocumentor\Descriptor\Builder\Reflector\Tags\SeeAssembler
20
 *
21
 * @coversDefaultClass \phpDocumentor\Descriptor\Builder\Reflector\Tags\SeeAssembler
22
 * @covers ::<private>
23
 */
24
class SeeAssemblerTest extends \PHPUnit_Framework_TestCase
25
{
26
    /** @var SeeAssembler $fixture */
27
    protected $fixture;
28
29
    /** @var ProjectDescriptorBuilder|m\MockInterface */
30
    protected $builderMock;
31
32
    /**
33
     * Creates a new fixture to test with.
34
     */
35
    protected function setUp()
36
    {
37
        $this->builderMock = m::mock('phpDocumentor\Descriptor\ProjectDescriptorBuilder');
38
        $this->fixture = new SeeAssembler();
39
        $this->fixture->setBuilder($this->builderMock);
40
    }
41
42
    /**
43
     * @covers ::create
44
     */
45
    public function testCreateSeeDescriptorFromSeeTagWhenReferenceIsRelativeClassnameNotInNamespaceAliasses()
46
    {
47
        // Arrange
48
        $name = 'see';
49
        $description = 'a see tag';
50
        $reference = 'ReferenceClass';
51
        $context = $this->givenAContext([$reference => '\My\Namespace\Alias\AnotherClass']);
52
        $docBlock = $this->givenADocBlock($context);
53
54
        $seeTagMock = $this->givenASeeTag($name, $description, $reference, $docBlock);
55
56
        // Act
57
        $descriptor = $this->fixture->create($seeTagMock);
58
59
        // Assert
60
        $this->assertSame($name, $descriptor->getName());
61
        $this->assertSame($description, $descriptor->getDescription());
62
        $this->assertSame('@context::' . $reference, $descriptor->getReference());
63
        $this->assertSame([], $descriptor->getErrors()->getAll());
64
    }
65
66
    /**
67
     * @covers ::create
68
     */
69
    public function testCreateSeeDescriptorFromSeeTagWhenReferenceIsRelativeClassnameInNamespaceAliases()
70
    {
71
        // Arrange
72
        $name = 'see';
73
        $description = 'a see tag';
74
        $reference = 'ReferenceClass';
75
        $context = $this->givenAContext([$reference => '\My\Namespace\Alias\ReferenceClass']);
76
        $docBlock = $this->givenADocBlock($context);
77
78
        $seeTagMock = $this->givenASeeTag($name, $description, $reference, $docBlock);
79
80
        // Act
81
        $descriptor = $this->fixture->create($seeTagMock);
82
83
        // Assert
84
        $this->assertSame($name, $descriptor->getName());
85
        $this->assertSame($description, $descriptor->getDescription());
86
        $this->assertSame('\\My\\Namespace\Alias\\' . $reference, $descriptor->getReference());
87
        $this->assertSame([], $descriptor->getErrors()->getAll());
88
    }
89
90
    /**
91
     * @covers ::create
92
     * @dataProvider provideReferences
93
     */
94
    public function testCreateSeeDescriptorFromSeeTagWhenReferenceIsUrl($reference)
95
    {
96
        // Arrange
97
        $name = 'see';
98
        $description = 'a see tag';
99
        $context = $this->givenAContext([]);
100
        $docBlock = $this->givenADocBlock($context);
101
102
        $seeTagMock = $this->givenASeeTag($name, $description, $reference, $docBlock);
103
104
        // Act
105
        $descriptor = $this->fixture->create($seeTagMock);
106
107
        // Assert
108
        $this->assertSame($name, $descriptor->getName());
109
        $this->assertSame($description, $descriptor->getDescription());
110
        $this->assertSame($reference, $descriptor->getReference());
111
        $this->assertSame([], $descriptor->getErrors()->getAll());
112
    }
113
114
    /**
115
     * @covers ::create
116
     */
117
    public function testCreateSeeDescriptorFromSeeTagWhenReferenceHasMultipleParts()
118
    {
119
        // Arrange
120
        $name = 'see';
121
        $description = 'a see tag';
122
        $reference = 'ReferenceClass::$property';
123
        $context = $this->givenAContext(['ReferenceClass' => '\My\Namespace\Alias\ReferenceClass']);
124
        $docBlock = $this->givenADocBlock($context);
125
126
        $seeTagMock = $this->givenASeeTag($name, $description, $reference, $docBlock);
127
128
        // Act
129
        $descriptor = $this->fixture->create($seeTagMock);
130
131
        // Assert
132
        $this->assertSame($name, $descriptor->getName());
133
        $this->assertSame($description, $descriptor->getDescription());
134
        $this->assertSame('\\My\\Namespace\Alias\\' . $reference, $descriptor->getReference());
135
        $this->assertSame([], $descriptor->getErrors()->getAll());
136
    }
137
138
    protected function givenASeeTag($name, $description, $reference, $docBlock)
139
    {
140
        $seeTagMock = m::mock('phpDocumentor\Reflection\DocBlock\Tag\SeeTag');
141
        $seeTagMock->shouldReceive('getName')->andReturn($name);
142
        $seeTagMock->shouldReceive('getDescription')->andReturn($description);
143
        $seeTagMock->shouldReceive('getReference')->andReturn($reference);
144
        $seeTagMock->shouldReceive('getDocBlock')->andReturn($docBlock);
145
146
        return $seeTagMock;
147
    }
148
149
    protected function givenADocBlock($context)
150
    {
151
        $docBlockMock = m::mock('phpDocumentor\Reflection\DocBlock');
152
        $docBlockMock->shouldReceive('getContext')->andReturn($context);
153
154
        return $docBlockMock;
155
    }
156
157
    protected function givenAContext($aliases)
158
    {
159
        $context = m::mock('phpDocumentor\Reflection\DocBlock\Context');
160
        $context->shouldReceive('getNamespace')->andReturn('\My\Namespace');
161
        $context->shouldReceive('getNamespaceAliases')->andReturn($aliases);
162
163
        return $context;
164
    }
165
166
    public function provideReferences()
167
    {
168
        return [
169
            ['http://phpdoc.org'],
170
            ['https://phpdoc.org'],
171
            ['ftp://phpdoc.org'],
172
            ['$this'],
173
            ['self'],
174
            ['\My\Namespace\Class']
175
        ];
176
    }
177
}
178