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