1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class ParameterTest 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\Parameter::__construct |
20
|
|
|
*/ |
21
|
|
|
public function testConstructor_InEmpty() |
22
|
|
|
{ |
23
|
|
|
$this->expectException('\SwaggerGen\Exception', "Invalid in for parameter: ''"); |
24
|
|
|
|
25
|
|
|
$object = new \SwaggerGen\Swagger\Parameter($this->parent, '', ''); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @covers \SwaggerGen\Swagger\Parameter::__construct |
30
|
|
|
*/ |
31
|
|
|
public function testConstructor_InNotValid() |
32
|
|
|
{ |
33
|
|
|
$this->expectException('\SwaggerGen\Exception', "Invalid in for parameter: 'foo'"); |
34
|
|
|
|
35
|
|
|
$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'foo', ''); |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @covers \SwaggerGen\Swagger\Parameter::__construct |
40
|
|
|
*/ |
41
|
|
|
public function testConstructor_DefinitionEmpty() |
42
|
|
|
{ |
43
|
|
|
$this->expectException('\SwaggerGen\Exception', "No type definition for parameter"); |
44
|
|
|
|
45
|
|
|
$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'path', ''); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @covers \SwaggerGen\Swagger\Parameter::__construct |
50
|
|
|
*/ |
51
|
|
|
public function testConstructor_NameEmpty() |
52
|
|
|
{ |
53
|
|
|
$this->expectException('\SwaggerGen\Exception', "No name for parameter"); |
54
|
|
|
|
55
|
|
|
$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'path', 'int'); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @covers \SwaggerGen\Swagger\Parameter::__construct |
60
|
|
|
*/ |
61
|
|
|
public function testConstructor_DefinitionUnknownType() |
62
|
|
|
{ |
63
|
|
|
$this->expectException('\SwaggerGen\Exception', "Type format not recognized: 'foo'"); |
64
|
|
|
|
65
|
|
|
$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'path', 'foo bar'); |
|
|
|
|
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @covers \SwaggerGen\Swagger\Parameter::__construct |
70
|
|
|
*/ |
71
|
|
|
public function testConstructor() |
72
|
|
|
{ |
73
|
|
|
$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'path', 'int foo'); |
74
|
|
|
|
75
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $object); |
76
|
|
|
|
77
|
|
|
$this->assertSame(array( |
78
|
|
|
'name' => 'foo', |
79
|
|
|
'in' => 'path', |
80
|
|
|
'required' => true, |
81
|
|
|
'type' => 'integer', |
82
|
|
|
'format' => 'int32', |
83
|
|
|
), $object->toArray()); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @covers \SwaggerGen\Swagger\Parameter::__construct |
88
|
|
|
*/ |
89
|
|
|
public function testConstructor_PathAlwaysRequired() |
90
|
|
|
{ |
91
|
|
|
$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'path', 'int foo', false); |
92
|
|
|
|
93
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $object); |
94
|
|
|
|
95
|
|
|
$this->assertSame(array( |
96
|
|
|
'name' => 'foo', |
97
|
|
|
'in' => 'path', |
98
|
|
|
'required' => true, |
99
|
|
|
'type' => 'integer', |
100
|
|
|
'format' => 'int32', |
101
|
|
|
), $object->toArray()); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @covers \SwaggerGen\Swagger\Parameter::__construct |
106
|
|
|
*/ |
107
|
|
|
public function testConstructor_Optional() |
108
|
|
|
{ |
109
|
|
|
$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'query', 'int foo', false); |
110
|
|
|
|
111
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $object); |
112
|
|
|
|
113
|
|
|
$this->assertSame(array( |
114
|
|
|
'name' => 'foo', |
115
|
|
|
'in' => 'query', |
116
|
|
|
'type' => 'integer', |
117
|
|
|
'format' => 'int32', |
118
|
|
|
), $object->toArray()); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @covers \SwaggerGen\Swagger\Parameter::__construct |
123
|
|
|
*/ |
124
|
|
|
public function testConstructor_Description() |
125
|
|
|
{ |
126
|
|
|
$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'path', 'int foo Some words'); |
127
|
|
|
|
128
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $object); |
129
|
|
|
|
130
|
|
|
$this->assertSame(array( |
131
|
|
|
'name' => 'foo', |
132
|
|
|
'in' => 'path', |
133
|
|
|
'description' => 'Some words', |
134
|
|
|
'required' => true, |
135
|
|
|
'type' => 'integer', |
136
|
|
|
'format' => 'int32', |
137
|
|
|
), $object->toArray()); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @covers \SwaggerGen\Swagger\Parameter::__construct |
142
|
|
|
*/ |
143
|
|
|
public function testConstructor_Form() |
144
|
|
|
{ |
145
|
|
|
$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'form', 'int foo', false); |
146
|
|
|
|
147
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $object); |
148
|
|
|
|
149
|
|
|
$this->assertSame(array( |
150
|
|
|
'name' => 'foo', |
151
|
|
|
'in' => 'formData', |
152
|
|
|
'type' => 'integer', |
153
|
|
|
'format' => 'int32', |
154
|
|
|
), $object->toArray()); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @covers \SwaggerGen\Swagger\Parameter::__construct |
159
|
|
|
*/ |
160
|
|
|
public function testConstructor_Header() |
161
|
|
|
{ |
162
|
|
|
$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'header', 'int foo', false); |
163
|
|
|
|
164
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $object); |
165
|
|
|
|
166
|
|
|
$this->assertSame(array( |
167
|
|
|
'name' => 'foo', |
168
|
|
|
'in' => 'header', |
169
|
|
|
'type' => 'integer', |
170
|
|
|
'format' => 'int32', |
171
|
|
|
), $object->toArray()); |
172
|
|
|
} |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @covers \SwaggerGen\Swagger\Type\Parameter->handleCommand |
176
|
|
|
*/ |
177
|
|
|
public function testHandleCommand_Passing() |
178
|
|
|
{ |
179
|
|
|
$object = new \SwaggerGen\Swagger\Parameter($this->parent, 'path', 'int foo', false); |
180
|
|
|
|
181
|
|
|
$this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $object); |
182
|
|
|
|
183
|
|
|
$object->handleCommand('default', '123'); |
184
|
|
|
|
185
|
|
|
$this->assertSame(array( |
186
|
|
|
'name' => 'foo', |
187
|
|
|
'in' => 'path', |
188
|
|
|
'required' => true, |
189
|
|
|
'type' => 'integer', |
190
|
|
|
'format' => 'int32', |
191
|
|
|
'default' => 123, |
192
|
|
|
), $object->toArray()); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
} |
196
|
|
|
|
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.