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\UsesAssembler |
20
|
|
|
* |
21
|
|
|
* @coversDefaultClass \phpDocumentor\Descriptor\Builder\Reflector\Tags\UsesAssembler |
22
|
|
|
* @covers ::<private> |
23
|
|
|
*/ |
24
|
|
|
class UsesAssemblerTest extends \PHPUnit_Framework_TestCase |
25
|
|
|
{ |
26
|
|
|
/** @var UsesAssembler $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 UsesAssembler(); |
39
|
|
|
$this->fixture->setBuilder($this->builderMock); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @covers ::create |
44
|
|
|
*/ |
45
|
|
|
public function testCreateUsesDescriptorFromUsesTagWhenReferenceIsRelativeClassnameNotInNamespaceAliasses() |
46
|
|
|
{ |
47
|
|
|
// Arrange |
48
|
|
|
$name = 'uses'; |
49
|
|
|
$description = 'a uses tag'; |
50
|
|
|
$reference = 'ReferenceClass'; |
51
|
|
|
$context = $this->givenAContext([$reference => '\My\Namespace\Alias\AnotherClass']); |
52
|
|
|
$docBlock = $this->givenADocBlock($context); |
53
|
|
|
|
54
|
|
|
$usesTagMock = $this->givenAUsesTag($name, $description, $reference, $docBlock); |
55
|
|
|
|
56
|
|
|
// Act |
57
|
|
|
$descriptor = $this->fixture->create($usesTagMock); |
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 testCreateUsesDescriptorFromUsesTagWhenReferenceIsRelativeClassnameInNamespaceAliases() |
70
|
|
|
{ |
71
|
|
|
// Arrange |
72
|
|
|
$name = 'uses'; |
73
|
|
|
$description = 'a uses tag'; |
74
|
|
|
$reference = 'ReferenceClass'; |
75
|
|
|
$context = $this->givenAContext([$reference => '\My\Namespace\Alias\ReferenceClass']); |
76
|
|
|
$docBlock = $this->givenADocBlock($context); |
77
|
|
|
|
78
|
|
|
$usesTagMock = $this->givenAUsesTag($name, $description, $reference, $docBlock); |
79
|
|
|
|
80
|
|
|
// Act |
81
|
|
|
$descriptor = $this->fixture->create($usesTagMock); |
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 testCreateSeeDescriptorFromSeeTagWhenReferenceIsThisSelfOrAbsolute($reference) |
95
|
|
|
{ |
96
|
|
|
// Arrange |
97
|
|
|
$name = 'uses'; |
98
|
|
|
$description = 'a uses tag'; |
99
|
|
|
$context = $this->givenAContext([]); |
100
|
|
|
$docBlock = $this->givenADocBlock($context); |
101
|
|
|
|
102
|
|
|
$usesTagMock = $this->givenAUsesTag($name, $description, $reference, $docBlock); |
103
|
|
|
|
104
|
|
|
// Act |
105
|
|
|
$descriptor = $this->fixture->create($usesTagMock); |
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 testCreateUsesDescriptorFromUsesTagWhenReferenceHasMultipleParts() |
118
|
|
|
{ |
119
|
|
|
// Arrange |
120
|
|
|
$name = 'uses'; |
121
|
|
|
$description = 'a uses tag'; |
122
|
|
|
$reference = 'ReferenceClass::$property'; |
123
|
|
|
$context = $this->givenAContext(['ReferenceClass' => '\My\Namespace\Alias\ReferenceClass']); |
124
|
|
|
$docBlock = $this->givenADocBlock($context); |
125
|
|
|
|
126
|
|
|
$usesTagMock = $this->givenAUsesTag($name, $description, $reference, $docBlock); |
127
|
|
|
|
128
|
|
|
// Act |
129
|
|
|
$descriptor = $this->fixture->create($usesTagMock); |
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 givenAUsesTag($name, $description, $reference, $docBlock) |
139
|
|
|
{ |
140
|
|
|
$seeTagMock = m::mock('phpDocumentor\Reflection\DocBlock\Tag\UsesTag'); |
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
|
|
|
['$this'], |
170
|
|
|
['self'], |
171
|
|
|
['\My\Namespace\Class'] |
172
|
|
|
]; |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|