1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class PathTest extends SwaggerGen_TestCase |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
|
6
|
|
|
protected $parent; |
7
|
|
|
|
8
|
|
|
protected function setUp() |
9
|
|
|
{ |
10
|
|
|
$this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
protected function assertPreConditions() |
14
|
|
|
{ |
15
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @covers \SwaggerGen\Swagger\Path::__construct |
20
|
|
|
*/ |
21
|
|
|
public function testConstructor_Empty() |
22
|
|
|
{ |
23
|
|
|
$object = new \SwaggerGen\Swagger\Path($this->parent); |
24
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Path', $object); |
25
|
|
|
|
26
|
|
|
$this->assertSame(array(), $object->toArray()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @covers \SwaggerGen\Swagger\Path::__construct |
31
|
|
|
*/ |
32
|
|
|
public function testConstructor_Tag() |
33
|
|
|
{ |
34
|
|
|
$object = new \SwaggerGen\Swagger\Path($this->parent, new SwaggerGen\Swagger\Tag($this->parent, 'Tag')); |
35
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Path', $object); |
36
|
|
|
|
37
|
|
|
$this->assertSame(array(), $object->toArray()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @covers \SwaggerGen\Swagger\Path::handleCommand |
42
|
|
|
*/ |
43
|
|
|
public function testHandleCommand_Method_Empty() |
44
|
|
|
{ |
45
|
|
|
$object = new \SwaggerGen\Swagger\Path($this->parent, new SwaggerGen\Swagger\Tag($this->parent, 'Tag')); |
46
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Path', $object); |
47
|
|
|
|
48
|
|
|
$this->expectException('\SwaggerGen\Exception', "Unrecognized operation method ''"); |
49
|
|
|
$return = $object->handleCommand('method'); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @covers \SwaggerGen\Swagger\Path::handleCommand |
54
|
|
|
*/ |
55
|
|
|
public function testHandleCommand_Method_Unknown() |
56
|
|
|
{ |
57
|
|
|
$object = new \SwaggerGen\Swagger\Path($this->parent, new SwaggerGen\Swagger\Tag($this->parent, 'Tag')); |
58
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Path', $object); |
59
|
|
|
|
60
|
|
|
$this->expectException('\SwaggerGen\Exception', "Unrecognized operation method 'foo'"); |
61
|
|
|
$return = $object->handleCommand('method', 'foo'); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @covers \SwaggerGen\Swagger\Path::handleCommand |
66
|
|
|
*/ |
67
|
|
|
public function testHandleCommand_Method_Get() |
68
|
|
|
{ |
69
|
|
|
$object = new \SwaggerGen\Swagger\Path($this->parent, new SwaggerGen\Swagger\Tag($this->parent, 'Tag')); |
70
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Path', $object); |
71
|
|
|
|
72
|
|
|
$operation = $object->handleCommand('method', 'get'); |
73
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
74
|
|
|
$operation->handleCommand('response', 200); |
75
|
|
|
|
76
|
|
|
$this->assertSame(array( |
77
|
|
|
'get' => array( |
78
|
|
|
'tags' => array( |
79
|
|
|
'Tag', |
80
|
|
|
), |
81
|
|
|
'responses' => array( |
82
|
|
|
200 => array( |
83
|
|
|
'description' => 'OK', |
84
|
|
|
), |
85
|
|
|
), |
86
|
|
|
), |
87
|
|
|
), $object->toArray()); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @covers \SwaggerGen\Swagger\Path::handleCommand |
92
|
|
|
*/ |
93
|
|
|
public function testHandleCommand_Method_Description() |
94
|
|
|
{ |
95
|
|
|
$this->markTestIncomplete('This test has not been implemented yet.'); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @covers \SwaggerGen\Swagger\Path::handleCommand |
100
|
|
|
*/ |
101
|
|
|
public function testHandleCommand_Operation_Get() |
102
|
|
|
{ |
103
|
|
|
$object = new \SwaggerGen\Swagger\Path($this->parent, new SwaggerGen\Swagger\Tag($this->parent, 'Tag')); |
104
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Path', $object); |
105
|
|
|
|
106
|
|
|
$operation = $object->handleCommand('operation', 'get'); |
107
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
108
|
|
|
$operation->handleCommand('response', 200); |
109
|
|
|
|
110
|
|
|
$this->assertSame(array( |
111
|
|
|
'get' => array( |
112
|
|
|
'tags' => array( |
113
|
|
|
'Tag', |
114
|
|
|
), |
115
|
|
|
'responses' => array( |
116
|
|
|
200 => array( |
117
|
|
|
'description' => 'OK', |
118
|
|
|
), |
119
|
|
|
), |
120
|
|
|
), |
121
|
|
|
), $object->toArray()); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
/** |
125
|
|
|
* @covers \SwaggerGen\Swagger\Path::handleCommand |
126
|
|
|
*/ |
127
|
|
|
public function testHandleCommand_MethodOrdering() |
128
|
|
|
{ |
129
|
|
|
$object = new \SwaggerGen\Swagger\Path($this->parent, new SwaggerGen\Swagger\Tag($this->parent, 'Tag')); |
130
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Path', $object); |
131
|
|
|
|
132
|
|
|
$operation = $object->handleCommand('method', 'post'); |
133
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
134
|
|
|
$operation->handleCommand('response', 200); |
135
|
|
|
|
136
|
|
|
$operation = $object->handleCommand('method', 'delete'); |
137
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
138
|
|
|
$operation->handleCommand('response', 200); |
139
|
|
|
|
140
|
|
|
$operation = $object->handleCommand('method', 'patch'); |
141
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
142
|
|
|
$operation->handleCommand('response', 200); |
143
|
|
|
|
144
|
|
|
$operation = $object->handleCommand('method', 'put'); |
145
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
146
|
|
|
$operation->handleCommand('response', 200); |
147
|
|
|
|
148
|
|
|
$operation = $object->handleCommand('method', 'head'); |
149
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
150
|
|
|
$operation->handleCommand('response', 200); |
151
|
|
|
|
152
|
|
|
$operation = $object->handleCommand('method', 'get'); |
153
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
154
|
|
|
$operation->handleCommand('response', 200); |
155
|
|
|
|
156
|
|
|
$operation = $object->handleCommand('method', 'options'); |
157
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
158
|
|
|
$operation->handleCommand('response', 200); |
159
|
|
|
|
160
|
|
|
$this->assertSame(array( |
161
|
|
|
'get' => array( |
162
|
|
|
'tags' => array( |
163
|
|
|
'Tag', |
164
|
|
|
), |
165
|
|
|
'responses' => array( |
166
|
|
|
200 => array( |
167
|
|
|
'description' => 'OK', |
168
|
|
|
), |
169
|
|
|
), |
170
|
|
|
), |
171
|
|
|
'put' => array( |
172
|
|
|
'tags' => array( |
173
|
|
|
'Tag', |
174
|
|
|
), |
175
|
|
|
'responses' => array( |
176
|
|
|
200 => array( |
177
|
|
|
'description' => 'OK', |
178
|
|
|
), |
179
|
|
|
), |
180
|
|
|
), |
181
|
|
|
'post' => array( |
182
|
|
|
'tags' => array( |
183
|
|
|
'Tag', |
184
|
|
|
), |
185
|
|
|
'responses' => array( |
186
|
|
|
200 => array( |
187
|
|
|
'description' => 'OK', |
188
|
|
|
), |
189
|
|
|
), |
190
|
|
|
), |
191
|
|
|
'delete' => array( |
192
|
|
|
'tags' => array( |
193
|
|
|
'Tag', |
194
|
|
|
), |
195
|
|
|
'responses' => array( |
196
|
|
|
200 => array( |
197
|
|
|
'description' => 'OK', |
198
|
|
|
), |
199
|
|
|
), |
200
|
|
|
), |
201
|
|
|
'options' => array( |
202
|
|
|
'tags' => array( |
203
|
|
|
'Tag', |
204
|
|
|
), |
205
|
|
|
'responses' => array( |
206
|
|
|
200 => array( |
207
|
|
|
'description' => 'OK', |
208
|
|
|
), |
209
|
|
|
), |
210
|
|
|
), |
211
|
|
|
'head' => array( |
212
|
|
|
'tags' => array( |
213
|
|
|
'Tag', |
214
|
|
|
), |
215
|
|
|
'responses' => array( |
216
|
|
|
200 => array( |
217
|
|
|
'description' => 'OK', |
218
|
|
|
), |
219
|
|
|
), |
220
|
|
|
), |
221
|
|
|
'patch' => array( |
222
|
|
|
'tags' => array( |
223
|
|
|
'Tag', |
224
|
|
|
), |
225
|
|
|
'responses' => array( |
226
|
|
|
200 => array( |
227
|
|
|
'description' => 'OK', |
228
|
|
|
), |
229
|
|
|
), |
230
|
|
|
), |
231
|
|
|
), $object->toArray()); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
} |
235
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.