1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of phpDocumentor. |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
* |
9
|
|
|
* @copyright 2010-2018 Mike van Riel<[email protected]> |
10
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
11
|
|
|
* @link http://phpdoc.org |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace phpDocumentor\Transformer\Writer\Xslt; |
15
|
|
|
|
16
|
|
|
use Mockery as m; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Test class for \phpDocumentor\Transformer\Writer\Xslt\Extension. |
20
|
|
|
* |
21
|
|
|
* @covers \phpDocumentor\Transformer\Writer\Xslt\Extension |
22
|
|
|
*/ |
23
|
|
|
class ExtensionTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @covers \phpDocumentor\Transformer\Writer\Xslt\Extension::markdown |
27
|
|
|
*/ |
28
|
|
|
public function testMarkdownWithString() |
29
|
|
|
{ |
30
|
|
|
$text = '`this is markdown`'; |
31
|
|
|
|
32
|
|
|
$result = Extension::markdown($text); |
33
|
|
|
|
34
|
|
|
$this->assertSame('<p><code>this is markdown</code></p>', $result); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @covers \phpDocumentor\Transformer\Writer\Xslt\Extension::markdown |
39
|
|
|
*/ |
40
|
|
|
public function testMarkdownReturnsInputUnchangedWhenInputIsNotString() |
41
|
|
|
{ |
42
|
|
|
$text = []; |
43
|
|
|
|
44
|
|
|
$result = Extension::markdown($text); |
|
|
|
|
45
|
|
|
|
46
|
|
|
$this->assertSame([], $result); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @covers \phpDocumentor\Transformer\Writer\Xslt\Extension::path |
51
|
|
|
*/ |
52
|
|
|
public function testPathWithExternalLink() |
53
|
|
|
{ |
54
|
|
|
$elementList = m::mock('phpDocumentor\Descriptor\Collection'); |
55
|
|
|
$elementList->shouldReceive('get')->andReturn(null); |
|
|
|
|
56
|
|
|
|
57
|
|
|
$rule = m::mock('phpDocumentor\Transformer\Router'); |
58
|
|
|
$rule->shouldReceive('generate')->andReturn('http://phpdoc.org'); |
59
|
|
|
$router = $this->givenARouter($rule); |
60
|
|
|
|
61
|
|
|
$projectDescriptor = m::mock('\phpDocumentor\Descriptor\ProjectDescriptor'); |
62
|
|
|
$projectDescriptor->shouldReceive('getIndexes')->andReturn($elementList); |
63
|
|
|
|
64
|
|
|
Extension::$projectDescriptor = $projectDescriptor; |
65
|
|
|
Extension::$routers = $router; |
66
|
|
|
$result = Extension::path('http://phpdoc.org'); |
67
|
|
|
|
68
|
|
|
$this->assertSame('http://phpdoc.org', $result); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @covers \phpDocumentor\Transformer\Writer\Xslt\Extension::path |
73
|
|
|
*/ |
74
|
|
|
public function testPathWithUndocumentedElement() |
75
|
|
|
{ |
76
|
|
|
$elementList = m::mock('phpDocumentor\Descriptor\Collection'); |
77
|
|
|
$elementList->shouldReceive('get')->andReturn(null); |
|
|
|
|
78
|
|
|
|
79
|
|
|
$router = $this->givenARouter(null); |
80
|
|
|
|
81
|
|
|
$projectDescriptor = m::mock('\phpDocumentor\Descriptor\ProjectDescriptor'); |
82
|
|
|
$projectDescriptor->shouldReceive('getIndexes')->andReturn($elementList); |
83
|
|
|
|
84
|
|
|
Extension::$projectDescriptor = $projectDescriptor; |
85
|
|
|
Extension::$routers = $router; |
86
|
|
|
$result = Extension::path('undocumented'); |
87
|
|
|
|
88
|
|
|
$this->assertSame('', $result); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @covers \phpDocumentor\Transformer\Writer\Xslt\Extension::path |
93
|
|
|
*/ |
94
|
|
|
public function testPathWithDocumentedElement() |
95
|
|
|
{ |
96
|
|
|
$elementList = m::mock('phpDocumentor\Descriptor\Collection'); |
97
|
|
|
$element = m::mock('phpDocumentor\Descriptor\Collection'); |
98
|
|
|
$element->shouldReceive('offsetExists')->andReturn(true); |
|
|
|
|
99
|
|
|
$element->shouldReceive('offsetGet'); |
100
|
|
|
$elementList->shouldReceive('get')->andReturn($element); |
101
|
|
|
|
102
|
|
|
$rule = m::mock('phpDocumentor\Transformer\Router'); |
103
|
|
|
$rule->shouldReceive('generate')->andReturn('/classes/my.namespace.class.html'); |
104
|
|
|
|
105
|
|
|
$router = $this->givenARouter($rule); |
106
|
|
|
|
107
|
|
|
$projectDescriptor = m::mock('\phpDocumentor\Descriptor\ProjectDescriptor'); |
108
|
|
|
$projectDescriptor->shouldReceive('getIndexes')->andReturn($elementList); |
109
|
|
|
|
110
|
|
|
Extension::$projectDescriptor = $projectDescriptor; |
111
|
|
|
Extension::$routers = $router; |
112
|
|
|
$result = Extension::path('\\my\\namespace\\class'); |
113
|
|
|
|
114
|
|
|
$this->assertSame('classes/my.namespace.class.html', $result); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @covers \phpDocumentor\Transformer\Writer\Xslt\Extension::typeOfElement |
119
|
|
|
*/ |
120
|
|
|
public function testTypeOfElementWithUrl() |
121
|
|
|
{ |
122
|
|
|
$elementList = m::mock('phpDocumentor\Descriptor\Collection'); |
123
|
|
|
$elementList->shouldReceive('get')->andReturn(null); |
|
|
|
|
124
|
|
|
|
125
|
|
|
$router = $this->givenARouter(null); |
126
|
|
|
|
127
|
|
|
$projectDescriptor = m::mock('\phpDocumentor\Descriptor\ProjectDescriptor'); |
128
|
|
|
$projectDescriptor->shouldReceive('getIndexes')->andReturn($elementList); |
129
|
|
|
|
130
|
|
|
Extension::$projectDescriptor = $projectDescriptor; |
131
|
|
|
Extension::$routers = $router; |
132
|
|
|
$result = Extension::typeOfElement('http://phpdoc.org'); |
133
|
|
|
|
134
|
|
|
$this->assertSame('url', $result); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* @covers \phpDocumentor\Transformer\Writer\Xslt\Extension::typeOfElement |
139
|
|
|
*/ |
140
|
|
|
public function testTypeOfElementWithUndocumentedElement() |
141
|
|
|
{ |
142
|
|
|
$elementList = m::mock('phpDocumentor\Descriptor\Collection'); |
143
|
|
|
$elementList->shouldReceive('get')->andReturn(null); |
|
|
|
|
144
|
|
|
|
145
|
|
|
$router = $this->givenARouter(null); |
146
|
|
|
|
147
|
|
|
$projectDescriptor = m::mock('\phpDocumentor\Descriptor\ProjectDescriptor'); |
148
|
|
|
$projectDescriptor->shouldReceive('getIndexes')->andReturn($elementList); |
149
|
|
|
|
150
|
|
|
Extension::$projectDescriptor = $projectDescriptor; |
151
|
|
|
Extension::$routers = $router; |
152
|
|
|
$result = Extension::typeOfElement('undocumented element'); |
153
|
|
|
|
154
|
|
|
$this->assertSame('undocumented', $result); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @covers \phpDocumentor\Transformer\Writer\Xslt\Extension::typeOfElement |
159
|
|
|
*/ |
160
|
|
|
public function testTypeOfElementWithDocumentedElement() |
161
|
|
|
{ |
162
|
|
|
$elementList = m::mock('phpDocumentor\Descriptor\Collection'); |
163
|
|
|
$element = m::mock('phpDocumentor\Descriptor\Collection'); |
164
|
|
|
$element->shouldReceive('offsetExists')->with('my\\namespace')->andReturn(false); |
165
|
|
|
$element->shouldReceive('offsetExists')->with('~\\my\\namespace')->andReturn(true); |
166
|
|
|
$element->shouldReceive('offsetGet')->with('~\\my\\namespace')->andReturn('the namespace descriptor'); |
167
|
|
|
$elementList->shouldReceive('get')->andReturn($element); |
|
|
|
|
168
|
|
|
|
169
|
|
|
$rule = m::mock('phpDocumentor\Transformer\Router'); |
170
|
|
|
$rule->shouldReceive('generate')->andReturn('/classes/my.namespace.class.html'); |
171
|
|
|
|
172
|
|
|
$router = $this->givenARouter(null); |
173
|
|
|
|
174
|
|
|
$projectDescriptor = m::mock('\phpDocumentor\Descriptor\ProjectDescriptor'); |
175
|
|
|
$projectDescriptor->shouldReceive('getIndexes')->andReturn($elementList); |
176
|
|
|
|
177
|
|
|
Extension::$projectDescriptor = $projectDescriptor; |
178
|
|
|
Extension::$routers = $router; |
179
|
|
|
$result = Extension::typeOfElement('my\\namespace'); |
180
|
|
|
|
181
|
|
|
$this->assertSame('documented', $result); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
private function givenARouter($rule) |
185
|
|
|
{ |
186
|
|
|
$queue = m::mock('phpDocumentor\Transformer\Router\Queue'); |
187
|
|
|
$router = m::mock('phpDocumentor\Transformer\Router\StandardRouter'); |
188
|
|
|
$queue->shouldReceive('insert'); |
189
|
|
|
$router->shouldReceive('match')->andReturn($rule); |
|
|
|
|
190
|
|
|
return $router; |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: