1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* phpDocumentor |
4
|
|
|
* |
5
|
|
|
* PHP Version 5.3 |
6
|
|
|
* |
7
|
|
|
* @copyright 2010-2014 Mike van Riel / Naenius (http://www.naenius.com) |
8
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
9
|
|
|
* @link http://phpdoc.org |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace phpDocumentor\Transformer\Router; |
13
|
|
|
|
14
|
|
|
use Mockery as m; |
15
|
|
|
use phpDocumentor\Descriptor\Collection; |
16
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen; |
17
|
|
|
use phpDocumentor\Reflection\DocBlock\Tags\Reference\Url; |
18
|
|
|
use phpDocumentor\Reflection\Fqsen as RealFqsen; |
19
|
|
|
|
20
|
|
|
class StandardRouterTest extends \PHPUnit_Framework_TestCase |
21
|
|
|
{ |
22
|
|
|
/** @var StandardRouter */ |
23
|
|
|
private $fixture; |
24
|
|
|
|
25
|
|
|
/** @var Collection */ |
26
|
|
|
private $elementCollection; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Sets up the fixture. |
30
|
|
|
*/ |
31
|
|
|
public function setUp() |
32
|
|
|
{ |
33
|
|
|
$this->elementCollection = new Collection(); |
34
|
|
|
|
35
|
|
|
$builder = m::mock('phpDocumentor\Descriptor\ProjectDescriptorBuilder'); |
36
|
|
|
$builder |
37
|
|
|
->shouldReceive('getProjectDescriptor->getIndexes->get') |
38
|
|
|
->with('elements') |
39
|
|
|
->andReturn($this->elementCollection); |
40
|
|
|
|
41
|
|
|
$this->fixture = new StandardRouter($builder); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @covers phpDocumentor\Transformer\Router\StandardRouter::configure |
46
|
|
|
* @covers phpDocumentor\Transformer\Router\RouterAbstract::__construct |
47
|
|
|
* @covers phpDocumentor\Transformer\Router\RouterAbstract::configure |
48
|
|
|
* @covers phpDocumentor\Transformer\Router\RouterAbstract::match |
49
|
|
|
* @dataProvider provideDescriptorNames |
50
|
|
|
*/ |
51
|
|
|
public function testIfARouteForAFileCanBeGenerated($descriptorName, $generatorName = null) |
52
|
|
|
{ |
53
|
|
|
// Arrange |
54
|
|
|
$generatorName = $generatorName ?: $descriptorName; |
55
|
|
|
$file = m::mock('phpDocumentor\\Descriptor\\' . $descriptorName); |
56
|
|
|
|
57
|
|
|
// Act |
58
|
|
|
$rule = $this->fixture->match($file); |
59
|
|
|
|
60
|
|
|
// Assert |
61
|
|
|
$this->assertInstanceOf('phpDocumentor\\Transformer\\Router\\Rule', $rule); |
62
|
|
|
$this->assertAttributeInstanceOf( |
63
|
|
|
'\phpDocumentor\\Transformer\\Router\\UrlGenerator\\Standard\\' . $generatorName, |
64
|
|
|
'generator', |
65
|
|
|
$rule |
66
|
|
|
); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @covers phpDocumentor\Transformer\Router\StandardRouter::configure |
71
|
|
|
* @covers phpDocumentor\Transformer\Router\RouterAbstract::__construct |
72
|
|
|
* @covers phpDocumentor\Transformer\Router\RouterAbstract::configure |
73
|
|
|
* @covers phpDocumentor\Transformer\Router\RouterAbstract::match |
74
|
|
|
*/ |
75
|
|
|
public function testIfARouteForAFqsenFileCanBeGenerated() |
76
|
|
|
{ |
77
|
|
|
// Arrange |
78
|
|
|
$fqsen = new RealFqsen('\Fqsen'); |
79
|
|
|
$file = new Fqsen($fqsen); |
80
|
|
|
|
81
|
|
|
// Act |
82
|
|
|
$rule = $this->fixture->match($file); |
83
|
|
|
|
84
|
|
|
// Assert |
85
|
|
|
$this->assertInstanceOf('phpDocumentor\\Transformer\\Router\\Rule', $rule); |
86
|
|
|
$this->assertAttributeInstanceOf( |
87
|
|
|
'\phpDocumentor\\Transformer\\Router\\UrlGenerator\\Standard\\FqsenDescriptor', |
88
|
|
|
'generator', |
89
|
|
|
$rule |
90
|
|
|
); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @covers phpDocumentor\Transformer\Router\StandardRouter::configure |
96
|
|
|
* @covers phpDocumentor\Transformer\Router\RouterAbstract::__construct |
97
|
|
|
* @covers phpDocumentor\Transformer\Router\RouterAbstract::configure |
98
|
|
|
* @covers phpDocumentor\Transformer\Router\RouterAbstract::match |
99
|
|
|
*/ |
100
|
|
|
public function testIfARouteForAUrlCanBeGenerated() |
101
|
|
|
{ |
102
|
|
|
// Arrange |
103
|
|
|
$file = new Url('http://www.phpdoc.org'); |
104
|
|
|
|
105
|
|
|
// Act |
106
|
|
|
$rule = $this->fixture->match($file); |
107
|
|
|
$result = $rule->generate($file); |
108
|
|
|
|
109
|
|
|
// Assert |
110
|
|
|
$this->assertInstanceOf('phpDocumentor\\Transformer\\Router\\Rule', $rule); |
111
|
|
|
$this->assertSame('http://www.phpdoc.org', $result); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @covers phpDocumentor\Transformer\Router\StandardRouter::configure |
116
|
|
|
* @covers phpDocumentor\Transformer\Router\StandardRouter::__construct |
117
|
|
|
* @covers phpDocumentor\Transformer\Router\RouterAbstract::__construct |
118
|
|
|
* @covers phpDocumentor\Transformer\Router\RouterAbstract::configure |
119
|
|
|
* @covers phpDocumentor\Transformer\Router\RouterAbstract::match |
120
|
|
|
*/ |
121
|
|
|
public function testIfARouteForAFqsenCanBeGenerated() |
122
|
|
|
{ |
123
|
|
|
// Arrange |
124
|
|
|
$fqsen = '\My\ClassName::myMethod()'; |
125
|
|
|
$this->elementCollection[$fqsen] = m::mock('phpDocumentor\Descriptor\MethodDescriptor'); |
126
|
|
|
|
127
|
|
|
// Act |
128
|
|
|
$rule = $this->fixture->match($fqsen); |
129
|
|
|
|
130
|
|
|
// Assert |
131
|
|
|
$this->assertInstanceOf('phpDocumentor\\Transformer\\Router\\Rule', $rule); |
132
|
|
|
$this->assertAttributeInstanceOf( |
133
|
|
|
'\phpDocumentor\\Transformer\\Router\\UrlGenerator\\Standard\\MethodDescriptor', |
134
|
|
|
'generator', |
135
|
|
|
$rule |
136
|
|
|
); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* @covers phpDocumentor\Transformer\Router\RouterAbstract::match |
141
|
|
|
*/ |
142
|
|
|
public function testGeneratingRouteForUnknownNodeReturnsFalse() |
143
|
|
|
{ |
144
|
|
|
$this->assertFalse($this->fixture->match('Unknown')->generate('Unknown')); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Returns the names of descriptors and generators supported by the StandardRouter. |
149
|
|
|
* |
150
|
|
|
* @return string[][] |
151
|
|
|
*/ |
152
|
|
|
public function provideDescriptorNames() |
153
|
|
|
{ |
154
|
|
|
return array( |
155
|
|
|
array('FileDescriptor'), |
156
|
|
|
array('NamespaceDescriptor'), |
157
|
|
|
array('PackageDescriptor'), |
158
|
|
|
array('ClassDescriptor'), |
159
|
|
|
array('InterfaceDescriptor', 'ClassDescriptor'), |
160
|
|
|
array('TraitDescriptor', 'ClassDescriptor'), |
161
|
|
|
array('MethodDescriptor'), |
162
|
|
|
array('FunctionDescriptor'), |
163
|
|
|
array('PropertyDescriptor'), |
164
|
|
|
array('ConstantDescriptor'), |
165
|
|
|
); |
166
|
|
|
} |
167
|
|
|
} |
168
|
|
|
|