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\Plugin\LegacyNamespaceConverter; |
14
|
|
|
|
15
|
|
|
use Mockery as m; |
16
|
|
|
use phpDocumentor\Descriptor\DescriptorAbstract; |
17
|
|
|
use phpDocumentor\Descriptor\ProjectDescriptorBuilder; |
18
|
|
|
use phpDocumentor\Plugin\LegacyNamespaceConverter\LegacyNamespaceFilter; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Tests the phpDocumentor\Plugin\LegacyNamespaceConverter\LegacyNamespaceFilter class. |
22
|
|
|
*/ |
23
|
|
|
class LegacyNamespaceFilterTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
24
|
|
|
{ |
25
|
|
|
/** @var LegacyNamespaceFilter */ |
26
|
|
|
private $filter; |
27
|
|
|
|
28
|
|
|
/** @var ProjectDescriptorBuilder|m\MockInterface $builder */ |
29
|
|
|
protected $builderMock; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Initializes the fixture and mocks any dependencies. |
33
|
|
|
* |
34
|
|
|
* @return void |
35
|
|
|
*/ |
36
|
|
|
public function setUp() |
37
|
|
|
{ |
38
|
|
|
$this->builderMock = m::mock('phpDocumentor\Descriptor\ProjectDescriptorBuilder'); |
39
|
|
|
$this->filter = new LegacyNamespaceFilter($this->builderMock); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @covers \phpDocumentor\Plugin\LegacyNamespaceConverter\LegacyNamespaceFilter::filter |
44
|
|
|
*/ |
45
|
|
|
public function testConvertClassNameWithUnderscoreWillBeConvertedToNamespace() |
46
|
|
|
{ |
47
|
|
|
$descriptor = $this->createDescriptorMock(); |
48
|
|
|
$descriptor->shouldReceive('getName')->andReturn('LegacyNamespace_ClassName'); |
|
|
|
|
49
|
|
|
$descriptor->shouldReceive('getNamespace')->andReturn('\\'); |
50
|
|
|
|
51
|
|
|
$descriptor->shouldReceive('setName')->with('ClassName')->once(); |
52
|
|
|
$descriptor->shouldReceive('setNamespace')->with('\LegacyNamespace')->once(); |
53
|
|
|
|
54
|
|
|
$this->filter->filter($descriptor); |
|
|
|
|
55
|
|
|
|
56
|
|
|
$this->assertTrue(true); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @covers \phpDocumentor\Plugin\LegacyNamespaceConverter\LegacyNamespaceFilter::filter |
61
|
|
|
*/ |
62
|
|
|
public function testMultiLevelLegacyNamespace() |
63
|
|
|
{ |
64
|
|
|
$descriptor = $this->createDescriptorMock(); |
65
|
|
|
$descriptor->shouldReceive('getName')->andReturn('LegacyNamespace_Sub_ClassName'); |
|
|
|
|
66
|
|
|
$descriptor->shouldReceive('getNamespace')->andReturn('\\'); |
67
|
|
|
|
68
|
|
|
$descriptor->shouldReceive('setName')->with('ClassName')->once(); |
69
|
|
|
$descriptor->shouldReceive('setNamespace')->with('\LegacyNamespace\Sub')->once(); |
70
|
|
|
|
71
|
|
|
$this->filter->filter($descriptor); |
|
|
|
|
72
|
|
|
|
73
|
|
|
$this->assertTrue(true); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @covers phpDocumentor\Plugin\LegacyNamespaceConverter\LegacyNamespaceFilter::filter |
78
|
|
|
*/ |
79
|
|
|
public function testMixedNamespacesCanBeUnified() |
80
|
|
|
{ |
81
|
|
|
$descriptor = $this->createDescriptorMock(); |
82
|
|
|
$descriptor->shouldReceive('getName')->andReturn('LegacyNamespace_ClassName'); |
|
|
|
|
83
|
|
|
$descriptor->shouldReceive('getNamespace')->andReturn('\\NewNamespace'); |
84
|
|
|
|
85
|
|
|
$descriptor->shouldReceive('setName')->with('ClassName')->once(); |
86
|
|
|
$descriptor->shouldReceive('setNamespace')->with('\\NewNamespace\\LegacyNamespace')->once(); |
87
|
|
|
|
88
|
|
|
$this->filter->filter($descriptor); |
|
|
|
|
89
|
|
|
|
90
|
|
|
$this->assertTrue(true); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @covers phpDocumentor\Plugin\LegacyNamespaceConverter\LegacyNamespaceFilter::filter |
95
|
|
|
*/ |
96
|
|
|
public function testClassNameWithNewNamespaceWillNotBeModified() |
97
|
|
|
{ |
98
|
|
|
$descriptor = $this->createDescriptorMock(); |
99
|
|
|
$descriptor->shouldReceive('getName')->andReturn('ClassName'); |
|
|
|
|
100
|
|
|
$descriptor->shouldReceive('getNamespace')->andReturn('\\NewNamespace'); |
101
|
|
|
|
102
|
|
|
$descriptor->shouldReceive('setName')->with('ClassName')->once(); |
103
|
|
|
$descriptor->shouldReceive('setNamespace')->with('\\NewNamespace')->once(); |
104
|
|
|
|
105
|
|
|
$this->filter->filter($descriptor); |
|
|
|
|
106
|
|
|
|
107
|
|
|
$this->assertTrue(true); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @covers phpDocumentor\Plugin\LegacyNamespaceConverter\LegacyNamespaceFilter::filter |
112
|
|
|
*/ |
113
|
|
|
public function testClassNameWithEmptyNamespace() |
114
|
|
|
{ |
115
|
|
|
$descriptor = $this->createDescriptorMock(); |
116
|
|
|
$descriptor->shouldReceive('getName')->andReturn('ClassName'); |
|
|
|
|
117
|
|
|
$descriptor->shouldReceive('getNamespace')->andReturn('\\'); |
118
|
|
|
|
119
|
|
|
$descriptor->shouldReceive('setName')->with('ClassName')->once(); |
120
|
|
|
$descriptor->shouldReceive('setNamespace')->with('\\')->once(); |
121
|
|
|
|
122
|
|
|
$this->filter->filter($descriptor); |
|
|
|
|
123
|
|
|
|
124
|
|
|
$this->assertTrue(true); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @covers phpDocumentor\Plugin\LegacyNamespaceConverter\LegacyNamespaceFilter::filter |
129
|
|
|
*/ |
130
|
|
|
public function testPrefixedNamespace() |
131
|
|
|
{ |
132
|
|
|
$this->filter->setNamespacePrefix('Vendor'); |
133
|
|
|
|
134
|
|
|
$descriptor = $this->createDescriptorMock(); |
135
|
|
|
$descriptor->shouldReceive('getName')->andReturn('ClassName'); |
|
|
|
|
136
|
|
|
$descriptor->shouldReceive('getNamespace')->andReturn(''); |
137
|
|
|
|
138
|
|
|
$descriptor->shouldReceive('setName')->with('ClassName')->once(); |
139
|
|
|
$descriptor->shouldReceive('setNamespace')->with('\\Vendor')->once(); |
140
|
|
|
|
141
|
|
|
$this->filter->filter($descriptor); |
|
|
|
|
142
|
|
|
|
143
|
|
|
$this->assertTrue(true); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @covers phpDocumentor\Plugin\LegacyNamespaceConverter\LegacyNamespaceFilter::filter |
148
|
|
|
*/ |
149
|
|
|
public function testPrefixedNamespaceWithNamespacedClassWillNotBeModified() |
150
|
|
|
{ |
151
|
|
|
$this->filter->setNamespacePrefix('Vendor'); |
152
|
|
|
|
153
|
|
|
$descriptor = $this->createDescriptorMock(); |
154
|
|
|
$descriptor->shouldReceive('getName')->andReturn('ClassName'); |
|
|
|
|
155
|
|
|
$descriptor->shouldReceive('getNamespace')->andReturn('\\'); |
156
|
|
|
|
157
|
|
|
$descriptor->shouldReceive('setName')->with('ClassName')->once(); |
158
|
|
|
$descriptor->shouldReceive('setNamespace')->with('\\')->once(); |
159
|
|
|
|
160
|
|
|
$this->filter->filter($descriptor); |
|
|
|
|
161
|
|
|
|
162
|
|
|
$this->assertTrue(true); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Creates a mocked Descriptor. |
167
|
|
|
* |
168
|
|
|
* @return m\MockInterface|DescriptorAbstract |
169
|
|
|
*/ |
170
|
|
|
private function createDescriptorMock() |
171
|
|
|
{ |
172
|
|
|
return m::mock('phpDocumentor\Descriptor\DescriptorAbstract'); |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: