|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Issue0005Test extends SwaggerGen_TestCase { |
|
|
|
|
|
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @covers \SwaggerGen\Swagger\Swagger::__construct |
|
7
|
|
|
*/ |
|
8
|
|
|
public function testHandleCommand_Model_Property() |
|
9
|
|
|
{ |
|
10
|
|
|
$object = new \SwaggerGen\Swagger\Swagger(); |
|
11
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Swagger', $object); |
|
12
|
|
|
|
|
13
|
|
|
$schema = $object->handleCommand('model', 'foo'); |
|
14
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Schema', $schema); |
|
15
|
|
|
|
|
16
|
|
|
$schema->handleCommand('property', 'string bar Some words here'); |
|
17
|
|
|
|
|
18
|
|
|
$path = $object->handleCommand('endpoint'); |
|
19
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Path', $path); |
|
20
|
|
|
|
|
21
|
|
|
$this->assertSame(array( |
|
22
|
|
|
'swagger' => '2.0', |
|
23
|
|
|
'info' => array( |
|
24
|
|
|
'title' => 'undefined', |
|
25
|
|
|
'version' => '0', |
|
26
|
|
|
), |
|
27
|
|
|
'paths' => array( |
|
28
|
|
|
'/' => array(), |
|
29
|
|
|
), |
|
30
|
|
|
'definitions' => array( |
|
31
|
|
|
'foo' => array( |
|
32
|
|
|
'type' => 'object', |
|
33
|
|
|
'required' => array( |
|
34
|
|
|
'bar', |
|
35
|
|
|
), |
|
36
|
|
|
'properties' => array( |
|
37
|
|
|
'bar' => array( |
|
38
|
|
|
'type' => 'string', |
|
39
|
|
|
'description' => 'Some words here', |
|
40
|
|
|
), |
|
41
|
|
|
), |
|
42
|
|
|
), |
|
43
|
|
|
), |
|
44
|
|
|
), $object->toArray()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @covers \SwaggerGen\Swagger\Swagger::__construct |
|
49
|
|
|
*/ |
|
50
|
|
|
public function testHandleCommand_Model_DuplicateProperties() |
|
51
|
|
|
{ |
|
52
|
|
|
$object = new \SwaggerGen\Swagger\Swagger(); |
|
53
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Swagger', $object); |
|
54
|
|
|
|
|
55
|
|
|
$schema = $object->handleCommand('model', 'foo'); |
|
56
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Schema', $schema); |
|
57
|
|
|
|
|
58
|
|
|
$schema->handleCommand('property', 'string bar Some words here'); |
|
59
|
|
|
$schema->handleCommand('property', 'integer bar Some other words'); |
|
60
|
|
|
|
|
61
|
|
|
$path = $object->handleCommand('endpoint'); |
|
62
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Path', $path); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertSame(array( |
|
65
|
|
|
'swagger' => '2.0', |
|
66
|
|
|
'info' => array( |
|
67
|
|
|
'title' => 'undefined', |
|
68
|
|
|
'version' => '0', |
|
69
|
|
|
), |
|
70
|
|
|
'paths' => array( |
|
71
|
|
|
'/' => array(), |
|
72
|
|
|
), |
|
73
|
|
|
'definitions' => array( |
|
74
|
|
|
'foo' => array( |
|
75
|
|
|
'type' => 'object', |
|
76
|
|
|
'required' => array( |
|
77
|
|
|
'bar', |
|
78
|
|
|
), |
|
79
|
|
|
'properties' => array( |
|
80
|
|
|
'bar' => array( |
|
81
|
|
|
'type' => 'integer', |
|
82
|
|
|
'format' => 'int32', |
|
83
|
|
|
'description' => 'Some other words', |
|
84
|
|
|
), |
|
85
|
|
|
), |
|
86
|
|
|
), |
|
87
|
|
|
), |
|
88
|
|
|
), $object->toArray()); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* @covers \SwaggerGen\Swagger\Operation::handleCommand |
|
93
|
|
|
*/ |
|
94
|
|
|
public function testHandleCommand_Query_Duplicate() |
|
95
|
|
|
{ |
|
96
|
|
|
$object = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); |
|
97
|
|
|
|
|
98
|
|
|
$operation = new \SwaggerGen\Swagger\Operation($object); |
|
99
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Operation', $operation); |
|
100
|
|
|
|
|
101
|
|
|
$parameter = $operation->handleCommand('query', 'int foo Some text'); |
|
102
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $parameter); |
|
103
|
|
|
|
|
104
|
|
|
$parameter = $operation->handleCommand('query', 'string foo Other text'); |
|
105
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $parameter); |
|
106
|
|
|
|
|
107
|
|
|
$response = $operation->handleCommand('response', '200'); |
|
108
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Response', $response); |
|
109
|
|
|
|
|
110
|
|
|
$this->assertSame(array( |
|
111
|
|
|
'parameters' => array( |
|
112
|
|
|
array( |
|
113
|
|
|
'name' => 'foo', |
|
114
|
|
|
'in' => 'query', |
|
115
|
|
|
'description' => 'Other text', |
|
116
|
|
|
'required' => true, |
|
117
|
|
|
'type' => 'string', |
|
118
|
|
|
), |
|
119
|
|
|
), |
|
120
|
|
|
'responses' => array( |
|
121
|
|
|
200 => array( |
|
122
|
|
|
'description' => 'OK', |
|
123
|
|
|
), |
|
124
|
|
|
), |
|
125
|
|
|
), $operation->toArray()); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
} |
|
129
|
|
|
|
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.