1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class OperationTest extends SwaggerGen_TestCase |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
|
6
|
|
|
protected $parent; |
7
|
|
|
|
8
|
|
|
protected function setUp() |
9
|
|
|
{ |
10
|
|
|
$this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\Swagger'); |
11
|
|
|
} |
12
|
|
|
|
13
|
|
|
protected function assertPreConditions() |
14
|
|
|
{ |
15
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @covers \SwaggerGen\Swagger\Operation::__construct |
20
|
|
|
*/ |
21
|
|
|
public function testConstructor_NoResponse() |
22
|
|
|
{ |
23
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
24
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
25
|
|
|
|
26
|
|
|
$this->expectException('\SwaggerGen\Exception', "No response defined for operation"); |
27
|
|
|
$object->toArray(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
32
|
|
|
*/ |
33
|
|
|
public function testConstructor_Summary() |
34
|
|
|
{ |
35
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent, 'Some words'); |
36
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
37
|
|
|
|
38
|
|
|
$return = $object->handleCommand('error', 404); |
39
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Error', $return); |
40
|
|
|
|
41
|
|
|
$this->assertSame(array( |
42
|
|
|
'summary' => 'Some words', |
43
|
|
|
'responses' => array( |
44
|
|
|
404 => array( |
45
|
|
|
'description' => 'Not Found', |
46
|
|
|
), |
47
|
|
|
), |
48
|
|
|
), $object->toArray()); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
53
|
|
|
*/ |
54
|
|
|
public function testConstructor_Tag() |
55
|
|
|
{ |
56
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent, '', new SwaggerGen\Swagger\Tag($this->parent, 'Operations')); |
57
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
58
|
|
|
|
59
|
|
|
$return = $object->handleCommand('error', 404); |
60
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Error', $return); |
61
|
|
|
|
62
|
|
|
$this->assertSame(array( |
63
|
|
|
'tags' => array( |
64
|
|
|
'Operations', |
65
|
|
|
), |
66
|
|
|
'responses' => array( |
67
|
|
|
404 => array( |
68
|
|
|
'description' => 'Not Found', |
69
|
|
|
), |
70
|
|
|
), |
71
|
|
|
), $object->toArray()); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
76
|
|
|
*/ |
77
|
|
|
public function testHandleCommand_Summary_Empty() |
78
|
|
|
{ |
79
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
80
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
81
|
|
|
|
82
|
|
|
$return = $object->handleCommand('summary'); |
83
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
84
|
|
|
|
85
|
|
|
$return = $object->handleCommand('response', '200'); |
86
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
87
|
|
|
|
88
|
|
|
$this->assertSame(array( |
89
|
|
|
'responses' => array( |
90
|
|
|
200 => array( |
91
|
|
|
'description' => 'OK', |
92
|
|
|
), |
93
|
|
|
), |
94
|
|
|
), $object->toArray()); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
99
|
|
|
*/ |
100
|
|
|
public function testHandleCommand_Summary() |
101
|
|
|
{ |
102
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
103
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
104
|
|
|
|
105
|
|
|
$return = $object->handleCommand('summary', 'Some words'); |
106
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
107
|
|
|
|
108
|
|
|
$return = $object->handleCommand('response', '200'); |
109
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
110
|
|
|
|
111
|
|
|
$this->assertSame(array( |
112
|
|
|
'summary' => 'Some words', |
113
|
|
|
'responses' => array( |
114
|
|
|
200 => array( |
115
|
|
|
'description' => 'OK', |
116
|
|
|
), |
117
|
|
|
), |
118
|
|
|
), $object->toArray()); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
123
|
|
|
*/ |
124
|
|
|
public function testHandleCommand_Description_Empty() |
125
|
|
|
{ |
126
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
127
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
128
|
|
|
|
129
|
|
|
$return = $object->handleCommand('description'); |
130
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
131
|
|
|
|
132
|
|
|
$return = $object->handleCommand('response', '200'); |
133
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
134
|
|
|
|
135
|
|
|
$this->assertSame(array( |
136
|
|
|
'responses' => array( |
137
|
|
|
200 => array( |
138
|
|
|
'description' => 'OK', |
139
|
|
|
), |
140
|
|
|
), |
141
|
|
|
), $object->toArray()); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
146
|
|
|
*/ |
147
|
|
|
public function testHandleCommand_Description() |
148
|
|
|
{ |
149
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
150
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
151
|
|
|
|
152
|
|
|
$return = $object->handleCommand('description', 'Some words'); |
153
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
154
|
|
|
|
155
|
|
|
$return = $object->handleCommand('response', '200'); |
156
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
157
|
|
|
|
158
|
|
|
$this->assertSame(array( |
159
|
|
|
'description' => 'Some words', |
160
|
|
|
'responses' => array( |
161
|
|
|
200 => array( |
162
|
|
|
'description' => 'OK', |
163
|
|
|
), |
164
|
|
|
), |
165
|
|
|
), $object->toArray()); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
170
|
|
|
*/ |
171
|
|
|
public function testHandleCommand_Deprecated() |
172
|
|
|
{ |
173
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
174
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
175
|
|
|
|
176
|
|
|
$return = $object->handleCommand('deprecated'); |
177
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
178
|
|
|
|
179
|
|
|
$return = $object->handleCommand('response', '200'); |
180
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
181
|
|
|
|
182
|
|
|
$this->assertSame(array( |
183
|
|
|
'deprecated' => true, |
184
|
|
|
'responses' => array( |
185
|
|
|
200 => array( |
186
|
|
|
'description' => 'OK', |
187
|
|
|
), |
188
|
|
|
), |
189
|
|
|
), $object->toArray()); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
194
|
|
|
*/ |
195
|
|
|
public function testHandleCommand_OperationId() |
196
|
|
|
{ |
197
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
198
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
199
|
|
|
|
200
|
|
|
$return = $object->handleCommand('id', 'SomeOperation'); |
201
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
202
|
|
|
|
203
|
|
|
$return = $object->handleCommand('response', '200'); |
204
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
205
|
|
|
|
206
|
|
|
$this->assertSame(array( |
207
|
|
|
'operationId' => 'SomeOperation', |
208
|
|
|
'responses' => array( |
209
|
|
|
200 => array( |
210
|
|
|
'description' => 'OK', |
211
|
|
|
), |
212
|
|
|
), |
213
|
|
|
), $object->toArray()); |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
218
|
|
|
*/ |
219
|
|
|
public function testHandleCommand_OperationId_UniqueInPath() |
220
|
|
|
{ |
221
|
|
|
$path = $this->parent->handleCommand('endpoint', 'foo'); |
222
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Path', $path); |
223
|
|
|
|
224
|
|
|
// First occurance |
225
|
|
|
$operation = $path->handleCommand('operation', 'GET'); |
226
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
227
|
|
|
|
228
|
|
|
$return = $operation->handleCommand('id', 'SomeOperation'); |
229
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
230
|
|
|
|
231
|
|
|
// Second occurance |
232
|
|
|
$operation = $path->handleCommand('operation', 'GET'); |
233
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
234
|
|
|
|
235
|
|
|
$this->expectException('\SwaggerGen\Exception', "Duplicate operation id 'SomeOperation'"); |
236
|
|
|
$operation->handleCommand('id', 'SomeOperation'); |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
241
|
|
|
*/ |
242
|
|
|
public function testHandleCommand_OperationId_UniqueInSwagger() |
243
|
|
|
{ |
244
|
|
|
// First occurance |
245
|
|
|
$path = $this->parent->handleCommand('endpoint', 'foo'); |
246
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Path', $path); |
247
|
|
|
|
248
|
|
|
$operation = $path->handleCommand('operation', 'GET'); |
249
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
250
|
|
|
|
251
|
|
|
$return = $operation->handleCommand('id', 'SomeOperation'); |
252
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
253
|
|
|
|
254
|
|
|
// Second occurance |
255
|
|
|
$path = $this->parent->handleCommand('endpoint', 'bar'); |
256
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Path', $path); |
257
|
|
|
|
258
|
|
|
$operation = $path->handleCommand('operation', 'GET'); |
259
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
260
|
|
|
|
261
|
|
|
$this->expectException('\SwaggerGen\Exception', "Duplicate operation id 'SomeOperation'"); |
262
|
|
|
$operation->handleCommand('id', 'SomeOperation'); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
/** |
266
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
267
|
|
|
*/ |
268
|
|
|
public function testHandleCommand_Tags_Empty() |
269
|
|
|
{ |
270
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
271
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
272
|
|
|
|
273
|
|
|
$return = $object->handleCommand('tags'); |
274
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
275
|
|
|
|
276
|
|
|
$return = $object->handleCommand('response', '200'); |
277
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
278
|
|
|
|
279
|
|
|
$this->assertSame(array( |
280
|
|
|
'responses' => array( |
281
|
|
|
200 => array( |
282
|
|
|
'description' => 'OK', |
283
|
|
|
), |
284
|
|
|
), |
285
|
|
|
), $object->toArray()); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
290
|
|
|
*/ |
291
|
|
|
public function testHandleCommand_Tags() |
292
|
|
|
{ |
293
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
294
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
295
|
|
|
|
296
|
|
|
$return = $object->handleCommand('tags', 'black white'); |
297
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
298
|
|
|
|
299
|
|
|
$return = $object->handleCommand('response', '200'); |
300
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
301
|
|
|
|
302
|
|
|
$this->assertSame(array( |
303
|
|
|
'tags' => array( |
304
|
|
|
'black', |
305
|
|
|
'white', |
306
|
|
|
), |
307
|
|
|
'responses' => array( |
308
|
|
|
200 => array( |
309
|
|
|
'description' => 'OK', |
310
|
|
|
), |
311
|
|
|
), |
312
|
|
|
), $object->toArray()); |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
317
|
|
|
*/ |
318
|
|
|
public function testHandleCommand_Tags_Append() |
319
|
|
|
{ |
320
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent, null, new SwaggerGen\Swagger\Tag($this->parent, 'purple')); |
321
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
322
|
|
|
|
323
|
|
|
$return = $object->handleCommand('tags', 'black white'); |
324
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
325
|
|
|
|
326
|
|
|
$return = $object->handleCommand('tags', 'black green'); |
327
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
328
|
|
|
|
329
|
|
|
$return = $object->handleCommand('response', '200'); |
330
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
331
|
|
|
|
332
|
|
|
$this->assertSame(array( |
333
|
|
|
'tags' => array( |
334
|
|
|
'black', |
335
|
|
|
'green', |
336
|
|
|
'purple', |
337
|
|
|
'white', |
338
|
|
|
), |
339
|
|
|
'responses' => array( |
340
|
|
|
200 => array( |
341
|
|
|
'description' => 'OK', |
342
|
|
|
), |
343
|
|
|
), |
344
|
|
|
), $object->toArray()); |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
/** |
348
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
349
|
|
|
*/ |
350
|
|
|
public function testHandleCommand_Schemes_Empty() |
351
|
|
|
{ |
352
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
353
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
354
|
|
|
|
355
|
|
|
$return = $object->handleCommand('schemes'); |
356
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
357
|
|
|
|
358
|
|
|
$return = $object->handleCommand('response', '200'); |
359
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
360
|
|
|
|
361
|
|
|
$this->assertSame(array( |
362
|
|
|
'responses' => array( |
363
|
|
|
200 => array( |
364
|
|
|
'description' => 'OK', |
365
|
|
|
), |
366
|
|
|
), |
367
|
|
|
), $object->toArray()); |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
372
|
|
|
*/ |
373
|
|
|
public function testHandleCommand_Schemes() |
374
|
|
|
{ |
375
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
376
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
377
|
|
|
|
378
|
|
|
$return = $object->handleCommand('schemes', 'http https'); |
379
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
380
|
|
|
|
381
|
|
|
$return = $object->handleCommand('response', '200'); |
382
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
383
|
|
|
|
384
|
|
|
$this->assertSame(array( |
385
|
|
|
'schemes' => array( |
386
|
|
|
'http', |
387
|
|
|
'https', |
388
|
|
|
), |
389
|
|
|
'responses' => array( |
390
|
|
|
200 => array( |
391
|
|
|
'description' => 'OK', |
392
|
|
|
), |
393
|
|
|
), |
394
|
|
|
), $object->toArray()); |
395
|
|
|
} |
396
|
|
|
|
397
|
|
|
/** |
398
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
399
|
|
|
*/ |
400
|
|
|
public function testHandleCommand_Schemes_Append() |
401
|
|
|
{ |
402
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
403
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
404
|
|
|
|
405
|
|
|
$return = $object->handleCommand('schemes', 'ws wss'); |
406
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
407
|
|
|
|
408
|
|
|
$return = $object->handleCommand('schemes', 'http ws'); |
409
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
410
|
|
|
|
411
|
|
|
$return = $object->handleCommand('response', '200'); |
412
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
413
|
|
|
|
414
|
|
|
$this->assertSame(array( |
415
|
|
|
'schemes' => array( |
416
|
|
|
'http', |
417
|
|
|
'ws', |
418
|
|
|
'wss', |
419
|
|
|
), |
420
|
|
|
'responses' => array( |
421
|
|
|
200 => array( |
422
|
|
|
'description' => 'OK', |
423
|
|
|
), |
424
|
|
|
), |
425
|
|
|
), $object->toArray()); |
426
|
|
|
} |
427
|
|
|
|
428
|
|
|
/** |
429
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
430
|
|
|
*/ |
431
|
|
|
public function testHandleCommand_Consumes_Empty() |
432
|
|
|
{ |
433
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
434
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
435
|
|
|
|
436
|
|
|
$return = $object->handleCommand('consumes'); |
437
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
438
|
|
|
|
439
|
|
|
$return = $object->handleCommand('response', '200'); |
440
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
441
|
|
|
|
442
|
|
|
$this->assertSame(array( |
443
|
|
|
'responses' => array( |
444
|
|
|
200 => array( |
445
|
|
|
'description' => 'OK', |
446
|
|
|
), |
447
|
|
|
), |
448
|
|
|
), $object->toArray()); |
449
|
|
|
} |
450
|
|
|
|
451
|
|
|
/** |
452
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
453
|
|
|
*/ |
454
|
|
|
public function testHandleCommand_Consumes() |
455
|
|
|
{ |
456
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
457
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
458
|
|
|
|
459
|
|
|
$return = $object->handleCommand('consumes', 'image/png text'); |
460
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
461
|
|
|
|
462
|
|
|
$return = $object->handleCommand('response', '200'); |
463
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
464
|
|
|
|
465
|
|
|
$this->assertSame(array( |
466
|
|
|
'consumes' => array( |
467
|
|
|
'image/png', |
468
|
|
|
'text/plain', |
469
|
|
|
), |
470
|
|
|
'responses' => array( |
471
|
|
|
200 => array( |
472
|
|
|
'description' => 'OK', |
473
|
|
|
), |
474
|
|
|
), |
475
|
|
|
), $object->toArray()); |
476
|
|
|
} |
477
|
|
|
|
478
|
|
|
/** |
479
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
480
|
|
|
*/ |
481
|
|
|
public function testHandleCommand_Consumes_Append() |
482
|
|
|
{ |
483
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
484
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
485
|
|
|
|
486
|
|
|
$return = $object->handleCommand('consumes', 'image/png text'); |
487
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
488
|
|
|
|
489
|
|
|
$return = $object->handleCommand('consumes', 'text json'); |
490
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
491
|
|
|
|
492
|
|
|
$return = $object->handleCommand('response', '200'); |
493
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
494
|
|
|
|
495
|
|
|
$this->assertSame(array( |
496
|
|
|
'consumes' => array( |
497
|
|
|
'application/json', |
498
|
|
|
'image/png', |
499
|
|
|
'text/plain', |
500
|
|
|
), |
501
|
|
|
'responses' => array( |
502
|
|
|
200 => array( |
503
|
|
|
'description' => 'OK', |
504
|
|
|
), |
505
|
|
|
), |
506
|
|
|
), $object->toArray()); |
507
|
|
|
} |
508
|
|
|
|
509
|
|
|
/** |
510
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
511
|
|
|
*/ |
512
|
|
|
public function testHandleCommand_Produces_Empty() |
513
|
|
|
{ |
514
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
515
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
516
|
|
|
|
517
|
|
|
$return = $object->handleCommand('produces'); |
518
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
519
|
|
|
|
520
|
|
|
$return = $object->handleCommand('response', '200'); |
521
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
522
|
|
|
|
523
|
|
|
$this->assertSame(array( |
524
|
|
|
'responses' => array( |
525
|
|
|
200 => array( |
526
|
|
|
'description' => 'OK', |
527
|
|
|
), |
528
|
|
|
), |
529
|
|
|
), $object->toArray()); |
530
|
|
|
} |
531
|
|
|
|
532
|
|
|
/** |
533
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
534
|
|
|
*/ |
535
|
|
|
public function testHandleCommand_Produces() |
536
|
|
|
{ |
537
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
538
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
539
|
|
|
|
540
|
|
|
$return = $object->handleCommand('produces', 'image/png text'); |
541
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
542
|
|
|
|
543
|
|
|
$return = $object->handleCommand('response', '200'); |
544
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
545
|
|
|
|
546
|
|
|
$this->assertSame(array( |
547
|
|
|
'produces' => array( |
548
|
|
|
'image/png', |
549
|
|
|
'text/plain', |
550
|
|
|
), |
551
|
|
|
'responses' => array( |
552
|
|
|
200 => array( |
553
|
|
|
'description' => 'OK', |
554
|
|
|
), |
555
|
|
|
), |
556
|
|
|
), $object->toArray()); |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
/** |
560
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
561
|
|
|
*/ |
562
|
|
|
public function testHandleCommand_Produces_Append() |
563
|
|
|
{ |
564
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
565
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
566
|
|
|
|
567
|
|
|
$return = $object->handleCommand('produces', 'image/png text'); |
568
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
569
|
|
|
|
570
|
|
|
$return = $object->handleCommand('produces', 'text json'); |
571
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
572
|
|
|
|
573
|
|
|
$return = $object->handleCommand('response', '200'); |
574
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
575
|
|
|
|
576
|
|
|
$this->assertSame(array( |
577
|
|
|
'produces' => array( |
578
|
|
|
'application/json', |
579
|
|
|
'image/png', |
580
|
|
|
'text/plain', |
581
|
|
|
), |
582
|
|
|
'responses' => array( |
583
|
|
|
200 => array( |
584
|
|
|
'description' => 'OK', |
585
|
|
|
), |
586
|
|
|
), |
587
|
|
|
), $object->toArray()); |
588
|
|
|
} |
589
|
|
|
|
590
|
|
|
/** |
591
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
592
|
|
|
*/ |
593
|
|
|
public function testHandleCommand_Error_Empty() |
594
|
|
|
{ |
595
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
596
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
597
|
|
|
|
598
|
|
|
$this->expectException('\SwaggerGen\Exception', "Invalid error code: ''"); |
599
|
|
|
$object->handleCommand('error'); |
600
|
|
|
} |
601
|
|
|
|
602
|
|
|
/** |
603
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
604
|
|
|
*/ |
605
|
|
|
public function testHandleCommand_Error_404() |
606
|
|
|
{ |
607
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
608
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
609
|
|
|
|
610
|
|
|
$return = $object->handleCommand('error', 404); |
611
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Error', $return); |
612
|
|
|
|
613
|
|
|
$this->assertSame(array( |
614
|
|
|
'responses' => array( |
615
|
|
|
404 => array( |
616
|
|
|
'description' => 'Not Found', |
617
|
|
|
), |
618
|
|
|
), |
619
|
|
|
), $object->toArray()); |
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
/** |
623
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
624
|
|
|
*/ |
625
|
|
|
public function testHandleCommand_Error_404Description() |
626
|
|
|
{ |
627
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
628
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
629
|
|
|
|
630
|
|
|
$return = $object->handleCommand('error', '404 Not here, Bro!'); |
631
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Error', $return); |
632
|
|
|
|
633
|
|
|
$this->assertSame(array( |
634
|
|
|
'responses' => array( |
635
|
|
|
404 => array( |
636
|
|
|
'description' => 'Not here, Bro!', |
637
|
|
|
), |
638
|
|
|
), |
639
|
|
|
), $object->toArray()); |
640
|
|
|
} |
641
|
|
|
|
642
|
|
|
/** |
643
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
644
|
|
|
*/ |
645
|
|
|
public function testHandleCommand_Errors_Empty() |
646
|
|
|
{ |
647
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
648
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
649
|
|
|
|
650
|
|
|
$object->handleCommand('errors'); |
651
|
|
|
|
652
|
|
|
$this->expectException('\SwaggerGen\Exception', "No response defined for operation"); |
653
|
|
|
$object->toArray(); |
654
|
|
|
} |
655
|
|
|
|
656
|
|
|
/** |
657
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
658
|
|
|
*/ |
659
|
|
|
public function testHandleCommand_Errors() |
660
|
|
|
{ |
661
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
662
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
663
|
|
|
|
664
|
|
|
$return = $object->handleCommand('errors', '404 403'); |
665
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
666
|
|
|
|
667
|
|
|
$this->assertSame(array( |
668
|
|
|
'responses' => array( |
669
|
|
|
403 => array( |
670
|
|
|
'description' => 'Forbidden', |
671
|
|
|
), |
672
|
|
|
404 => array( |
673
|
|
|
'description' => 'Not Found', |
674
|
|
|
), |
675
|
|
|
), |
676
|
|
|
), $object->toArray()); |
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
/** |
680
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
681
|
|
|
*/ |
682
|
|
|
public function testHandleCommand_Response_Empty() |
683
|
|
|
{ |
684
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
685
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
686
|
|
|
|
687
|
|
|
$this->expectException('\SwaggerGen\Exception', "Invalid response code: ''"); |
688
|
|
|
$object->handleCommand('response'); |
689
|
|
|
} |
690
|
|
|
|
691
|
|
|
/** |
692
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
693
|
|
|
*/ |
694
|
|
|
public function testHandleCommand_Response_200() |
695
|
|
|
{ |
696
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
697
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
698
|
|
|
|
699
|
|
|
$return = $object->handleCommand('response', '200'); |
700
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
701
|
|
|
|
702
|
|
|
$this->assertSame(array( |
703
|
|
|
'responses' => array( |
704
|
|
|
200 => array( |
705
|
|
|
'description' => 'OK', |
706
|
|
|
), |
707
|
|
|
), |
708
|
|
|
), $object->toArray()); |
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
/** |
712
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
713
|
|
|
*/ |
714
|
|
|
public function testHandleCommand_Response_Definition() |
715
|
|
|
{ |
716
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
717
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
718
|
|
|
|
719
|
|
|
$return = $object->handleCommand('response', '200 int'); |
720
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
721
|
|
|
|
722
|
|
|
$this->assertSame(array( |
723
|
|
|
'responses' => array( |
724
|
|
|
200 => array( |
725
|
|
|
'description' => 'OK', |
726
|
|
|
'schema' => Array( |
727
|
|
|
'type' => 'integer', |
728
|
|
|
'format' => 'int32', |
729
|
|
|
), |
730
|
|
|
), |
731
|
|
|
), |
732
|
|
|
), $object->toArray()); |
733
|
|
|
} |
734
|
|
|
|
735
|
|
|
/** |
736
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
737
|
|
|
*/ |
738
|
|
|
public function testHandleCommand_Response_Description() |
739
|
|
|
{ |
740
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
741
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
742
|
|
|
|
743
|
|
|
$return = $object->handleCommand('response', '200 int Stuff is returned'); |
744
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
745
|
|
|
|
746
|
|
|
$this->assertSame(array( |
747
|
|
|
'responses' => array( |
748
|
|
|
200 => array( |
749
|
|
|
'description' => 'Stuff is returned', |
750
|
|
|
'schema' => Array( |
751
|
|
|
'type' => 'integer', |
752
|
|
|
'format' => 'int32', |
753
|
|
|
), |
754
|
|
|
), |
755
|
|
|
), |
756
|
|
|
), $object->toArray()); |
757
|
|
|
} |
758
|
|
|
|
759
|
|
|
/** |
760
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
761
|
|
|
*/ |
762
|
|
|
public function testHandleCommand_Require_Empty() |
763
|
|
|
{ |
764
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
765
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
766
|
|
|
|
767
|
|
|
$this->expectException('\SwaggerGen\Exception', "Empty security requirement name"); |
768
|
|
|
$object->handleCommand('require'); |
769
|
|
|
} |
770
|
|
|
|
771
|
|
|
/** |
772
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
773
|
|
|
*/ |
774
|
|
|
public function testHandleCommand_Require_Basic_Undefined() |
775
|
|
|
{ |
776
|
|
|
// precondition |
777
|
|
|
$swagger = new \SwaggerGen\Swagger\Swagger(); |
778
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Swagger', $swagger); |
779
|
|
|
|
780
|
|
|
$object = new \SwaggerGen\Swagger\Operation($swagger); |
781
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
782
|
|
|
|
783
|
|
|
$return = $object->handleCommand('require', 'basic'); |
784
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
785
|
|
|
|
786
|
|
|
$return = $object->handleCommand('response', '200'); |
787
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
788
|
|
|
|
789
|
|
|
$this->expectException('\SwaggerGen\Exception', "Required security scheme not defined: 'basic'"); |
790
|
|
|
$object->toArray(); |
791
|
|
|
} |
792
|
|
|
|
793
|
|
|
/** |
794
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
795
|
|
|
*/ |
796
|
|
|
public function testHandleCommand_Require_Basic() |
797
|
|
|
{ |
798
|
|
|
// precondition |
799
|
|
|
$swagger = new \SwaggerGen\Swagger\Swagger(); |
800
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Swagger', $swagger); |
801
|
|
|
$swagger->handleCommand('security', 'basic basic'); |
802
|
|
|
|
803
|
|
|
$object = new \SwaggerGen\Swagger\Operation($swagger); |
804
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
805
|
|
|
|
806
|
|
|
$return = $object->handleCommand('require', 'basic'); |
807
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
808
|
|
|
|
809
|
|
|
$return = $object->handleCommand('response', '200'); |
810
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
811
|
|
|
|
812
|
|
|
$this->assertEquals(array( |
813
|
|
|
'responses' => array( |
814
|
|
|
200 => array( |
815
|
|
|
'description' => 'OK', |
816
|
|
|
), |
817
|
|
|
), |
818
|
|
|
'security' => array( |
819
|
|
|
array( |
820
|
|
|
'basic' => array(), |
821
|
|
|
), |
822
|
|
|
), |
823
|
|
|
), $object->toArray()); |
824
|
|
|
} |
825
|
|
|
|
826
|
|
|
/** |
827
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
828
|
|
|
*/ |
829
|
|
|
public function testHandleCommand_Require_Oauth2() |
830
|
|
|
{ |
831
|
|
|
// precondition |
832
|
|
|
$swagger = new \SwaggerGen\Swagger\Swagger(); |
833
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Swagger', $swagger); |
834
|
|
|
$swagger->handleCommand('security', 'oauth oauth2 implicit http://www.test'); |
835
|
|
|
|
836
|
|
|
$object = new \SwaggerGen\Swagger\Operation($swagger); |
837
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
838
|
|
|
|
839
|
|
|
$return = $object->handleCommand('require', 'oauth user:name user:email'); |
840
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $return); |
841
|
|
|
|
842
|
|
|
$return = $object->handleCommand('response', '200'); |
843
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
844
|
|
|
|
845
|
|
|
$this->assertSame(array( |
846
|
|
|
'responses' => array( |
847
|
|
|
200 => array( |
848
|
|
|
'description' => 'OK', |
849
|
|
|
), |
850
|
|
|
), |
851
|
|
|
'security' => array( |
852
|
|
|
array( |
853
|
|
|
'oauth' => array( |
854
|
|
|
'user:email', |
855
|
|
|
'user:name', |
856
|
|
|
), |
857
|
|
|
), |
858
|
|
|
), |
859
|
|
|
), $object->toArray()); |
860
|
|
|
} |
861
|
|
|
|
862
|
|
|
/** |
863
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
864
|
|
|
*/ |
865
|
|
|
public function testHandleCommand_Body_Required() |
866
|
|
|
{ |
867
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
868
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
869
|
|
|
|
870
|
|
|
$return = $object->handleCommand('body', 'int foo'); |
871
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\BodyParameter', $return); |
872
|
|
|
|
873
|
|
|
$return = $object->handleCommand('response', '200'); |
874
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
875
|
|
|
|
876
|
|
|
$this->assertSame(array( |
877
|
|
|
'parameters' => array( |
878
|
|
|
array( |
879
|
|
|
'name' => 'foo', |
880
|
|
|
'in' => 'body', |
881
|
|
|
'required' => true, |
882
|
|
|
'schema' => array( |
883
|
|
|
'type' => 'integer', |
884
|
|
|
'format' => 'int32', |
885
|
|
|
), |
886
|
|
|
), |
887
|
|
|
), |
888
|
|
|
'responses' => array( |
889
|
|
|
200 => array( |
890
|
|
|
'description' => 'OK', |
891
|
|
|
), |
892
|
|
|
), |
893
|
|
|
), $object->toArray()); |
894
|
|
|
} |
895
|
|
|
|
896
|
|
|
/** |
897
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
898
|
|
|
*/ |
899
|
|
|
public function testHandleCommand_Body_Optional() |
900
|
|
|
{ |
901
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
902
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
903
|
|
|
|
904
|
|
|
$return = $object->handleCommand('body?', 'int foo'); |
905
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\BodyParameter', $return); |
906
|
|
|
|
907
|
|
|
$return = $object->handleCommand('response', '200'); |
908
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
909
|
|
|
|
910
|
|
|
$this->assertSame(array( |
911
|
|
|
'parameters' => array( |
912
|
|
|
array( |
913
|
|
|
'name' => 'foo', |
914
|
|
|
'in' => 'body', |
915
|
|
|
'schema' => array( |
916
|
|
|
'type' => 'integer', |
917
|
|
|
'format' => 'int32', |
918
|
|
|
), |
919
|
|
|
), |
920
|
|
|
), |
921
|
|
|
'responses' => array( |
922
|
|
|
200 => array( |
923
|
|
|
'description' => 'OK', |
924
|
|
|
), |
925
|
|
|
), |
926
|
|
|
), $object->toArray()); |
927
|
|
|
} |
928
|
|
|
|
929
|
|
|
/** |
930
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
931
|
|
|
*/ |
932
|
|
|
public function testHandleCommand_Path_Required() |
933
|
|
|
{ |
934
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
935
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
936
|
|
|
|
937
|
|
|
$return = $object->handleCommand('path', 'int foo'); |
938
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $return); |
939
|
|
|
|
940
|
|
|
$return = $object->handleCommand('response', '200'); |
941
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
942
|
|
|
|
943
|
|
|
$this->assertSame(array( |
944
|
|
|
'parameters' => array( |
945
|
|
|
array( |
946
|
|
|
'name' => 'foo', |
947
|
|
|
'in' => 'path', |
948
|
|
|
'required' => true, |
949
|
|
|
'type' => 'integer', |
950
|
|
|
'format' => 'int32', |
951
|
|
|
), |
952
|
|
|
), |
953
|
|
|
'responses' => array( |
954
|
|
|
200 => array( |
955
|
|
|
'description' => 'OK', |
956
|
|
|
), |
957
|
|
|
), |
958
|
|
|
), $object->toArray()); |
959
|
|
|
} |
960
|
|
|
|
961
|
|
|
/** |
962
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
963
|
|
|
*/ |
964
|
|
|
public function testHandleCommand_Query_Required() |
965
|
|
|
{ |
966
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
967
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
968
|
|
|
|
969
|
|
|
$return = $object->handleCommand('query', 'int foo'); |
970
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $return); |
971
|
|
|
|
972
|
|
|
$return = $object->handleCommand('response', '200'); |
973
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
974
|
|
|
|
975
|
|
|
$this->assertSame(array( |
976
|
|
|
'parameters' => array( |
977
|
|
|
array( |
978
|
|
|
'name' => 'foo', |
979
|
|
|
'in' => 'query', |
980
|
|
|
'required' => true, |
981
|
|
|
'type' => 'integer', |
982
|
|
|
'format' => 'int32', |
983
|
|
|
), |
984
|
|
|
), |
985
|
|
|
'responses' => array( |
986
|
|
|
200 => array( |
987
|
|
|
'description' => 'OK', |
988
|
|
|
), |
989
|
|
|
), |
990
|
|
|
), $object->toArray()); |
991
|
|
|
} |
992
|
|
|
|
993
|
|
|
/** |
994
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
995
|
|
|
*/ |
996
|
|
|
public function testHandleCommand_Query_Optional() |
997
|
|
|
{ |
998
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
999
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
1000
|
|
|
|
1001
|
|
|
$return = $object->handleCommand('query?', 'int foo'); |
1002
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $return); |
1003
|
|
|
|
1004
|
|
|
$return = $object->handleCommand('response', '200'); |
1005
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
1006
|
|
|
|
1007
|
|
|
$this->assertSame(array( |
1008
|
|
|
'parameters' => array( |
1009
|
|
|
array( |
1010
|
|
|
'name' => 'foo', |
1011
|
|
|
'in' => 'query', |
1012
|
|
|
'type' => 'integer', |
1013
|
|
|
'format' => 'int32', |
1014
|
|
|
), |
1015
|
|
|
), |
1016
|
|
|
'responses' => array( |
1017
|
|
|
200 => array( |
1018
|
|
|
'description' => 'OK', |
1019
|
|
|
), |
1020
|
|
|
), |
1021
|
|
|
), $object->toArray()); |
1022
|
|
|
} |
1023
|
|
|
|
1024
|
|
|
/** |
1025
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
1026
|
|
|
*/ |
1027
|
|
|
public function testHandleCommand_Header_Required() |
1028
|
|
|
{ |
1029
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
1030
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
1031
|
|
|
|
1032
|
|
|
$return = $object->handleCommand('header', 'int foo'); |
1033
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $return); |
1034
|
|
|
|
1035
|
|
|
$return = $object->handleCommand('response', '200'); |
1036
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
1037
|
|
|
|
1038
|
|
|
$this->assertSame(array( |
1039
|
|
|
'parameters' => array( |
1040
|
|
|
array( |
1041
|
|
|
'name' => 'foo', |
1042
|
|
|
'in' => 'header', |
1043
|
|
|
'required' => true, |
1044
|
|
|
'type' => 'integer', |
1045
|
|
|
'format' => 'int32', |
1046
|
|
|
), |
1047
|
|
|
), |
1048
|
|
|
'responses' => array( |
1049
|
|
|
200 => array( |
1050
|
|
|
'description' => 'OK', |
1051
|
|
|
), |
1052
|
|
|
), |
1053
|
|
|
), $object->toArray()); |
1054
|
|
|
} |
1055
|
|
|
|
1056
|
|
|
/** |
1057
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
1058
|
|
|
*/ |
1059
|
|
|
public function testHandleCommand_Header_Optional() |
1060
|
|
|
{ |
1061
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
1062
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
1063
|
|
|
|
1064
|
|
|
$return = $object->handleCommand('header?', 'int foo'); |
1065
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $return); |
1066
|
|
|
|
1067
|
|
|
$return = $object->handleCommand('response', '200'); |
1068
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
1069
|
|
|
|
1070
|
|
|
$this->assertSame(array( |
1071
|
|
|
'parameters' => array( |
1072
|
|
|
array( |
1073
|
|
|
'name' => 'foo', |
1074
|
|
|
'in' => 'header', |
1075
|
|
|
'type' => 'integer', |
1076
|
|
|
'format' => 'int32', |
1077
|
|
|
), |
1078
|
|
|
), |
1079
|
|
|
'responses' => array( |
1080
|
|
|
200 => array( |
1081
|
|
|
'description' => 'OK', |
1082
|
|
|
), |
1083
|
|
|
), |
1084
|
|
|
), $object->toArray()); |
1085
|
|
|
} |
1086
|
|
|
|
1087
|
|
|
/** |
1088
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
1089
|
|
|
*/ |
1090
|
|
|
public function testHandleCommand_Form_Required() |
1091
|
|
|
{ |
1092
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
1093
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
1094
|
|
|
|
1095
|
|
|
$return = $object->handleCommand('form', 'int foo'); |
1096
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $return); |
1097
|
|
|
|
1098
|
|
|
$return = $object->handleCommand('response', '200'); |
1099
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
1100
|
|
|
|
1101
|
|
|
$this->assertSame(array( |
1102
|
|
|
'parameters' => array( |
1103
|
|
|
array( |
1104
|
|
|
'name' => 'foo', |
1105
|
|
|
'in' => 'formData', |
1106
|
|
|
'required' => true, |
1107
|
|
|
'type' => 'integer', |
1108
|
|
|
'format' => 'int32', |
1109
|
|
|
), |
1110
|
|
|
), |
1111
|
|
|
'responses' => array( |
1112
|
|
|
200 => array( |
1113
|
|
|
'description' => 'OK', |
1114
|
|
|
), |
1115
|
|
|
), |
1116
|
|
|
), $object->toArray()); |
1117
|
|
|
} |
1118
|
|
|
|
1119
|
|
|
/** |
1120
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
1121
|
|
|
*/ |
1122
|
|
|
public function testHandleCommand_Form_Optional() |
1123
|
|
|
{ |
1124
|
|
|
$object = new \SwaggerGen\Swagger\Operation($this->parent); |
1125
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $object); |
1126
|
|
|
|
1127
|
|
|
$return = $object->handleCommand('form?', 'int foo'); |
1128
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $return); |
1129
|
|
|
|
1130
|
|
|
$return = $object->handleCommand('response', '200'); |
1131
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $return); |
1132
|
|
|
|
1133
|
|
|
$this->assertSame(array( |
1134
|
|
|
'parameters' => array( |
1135
|
|
|
array( |
1136
|
|
|
'name' => 'foo', |
1137
|
|
|
'in' => 'formData', |
1138
|
|
|
'type' => 'integer', |
1139
|
|
|
'format' => 'int32', |
1140
|
|
|
), |
1141
|
|
|
), |
1142
|
|
|
'responses' => array( |
1143
|
|
|
200 => array( |
1144
|
|
|
'description' => 'OK', |
1145
|
|
|
), |
1146
|
|
|
), |
1147
|
|
|
), $object->toArray()); |
1148
|
|
|
} |
1149
|
|
|
|
1150
|
|
|
} |
1151
|
|
|
|
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.