@@ -6,293 +6,293 @@ |
||
| 6 | 6 | class StringTypeTest extends TestCase |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - protected $parent; |
|
| 10 | - |
|
| 11 | - /** |
|
| 12 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 13 | - */ |
|
| 14 | - public function testConstructNotAString() |
|
| 15 | - { |
|
| 16 | - $this->expectException('\SwaggerGen\Exception', "Not a string: 'wrong'"); |
|
| 17 | - |
|
| 18 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'wrong'); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 23 | - */ |
|
| 24 | - public function testConstructEmptyRange() |
|
| 25 | - { |
|
| 26 | - $this->expectException('\SwaggerGen\Exception', "Empty string range: 'string[,]=1'"); |
|
| 27 | - |
|
| 28 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[,]=1'); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 33 | - */ |
|
| 34 | - public function testConstructDefaultTooLongInclusive() |
|
| 35 | - { |
|
| 36 | - $this->expectException('\SwaggerGen\Exception', "Default string length beyond maximum: 'long'"); |
|
| 37 | - |
|
| 38 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[,3]=long'); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 43 | - */ |
|
| 44 | - public function testConstructDefaultTooLongExclusive() |
|
| 45 | - { |
|
| 46 | - $this->expectException('\SwaggerGen\Exception', "Default string length beyond maximum: 'long'"); |
|
| 47 | - |
|
| 48 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[,4>=long'); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 53 | - */ |
|
| 54 | - public function testConstructDefaultTooShortInclusive() |
|
| 55 | - { |
|
| 56 | - $this->expectException('\SwaggerGen\Exception', "Default string length beyond minimum: 'short'"); |
|
| 57 | - |
|
| 58 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[6,]=short'); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 63 | - */ |
|
| 64 | - public function testConstructDefaultTooShortExclusive() |
|
| 65 | - { |
|
| 66 | - $this->expectException('\SwaggerGen\Exception', "Default string length beyond minimum: 'short'"); |
|
| 67 | - |
|
| 68 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string<5,]=short'); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 73 | - */ |
|
| 74 | - public function testConstructString() |
|
| 75 | - { |
|
| 76 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
| 77 | - |
|
| 78 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 79 | - |
|
| 80 | - $this->assertSame(array( |
|
| 81 | - 'type' => 'string', |
|
| 82 | - ), $object->toArray()); |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 87 | - */ |
|
| 88 | - public function testConstructStringEmptyDefault() |
|
| 89 | - { |
|
| 90 | - $this->expectException('\SwaggerGen\Exception', "Unparseable string definition: 'string='"); |
|
| 91 | - |
|
| 92 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string= '); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 97 | - */ |
|
| 98 | - public function testConstructStringDefaultLengthInclusive() |
|
| 99 | - { |
|
| 100 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[4,4]=word'); |
|
| 101 | - |
|
| 102 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 103 | - |
|
| 104 | - $this->assertSame(array( |
|
| 105 | - 'type' => 'string', |
|
| 106 | - 'default' => 'word', |
|
| 107 | - 'minLength' => 4, |
|
| 108 | - 'maxLength' => 4, |
|
| 109 | - ), $object->toArray()); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 114 | - */ |
|
| 115 | - public function testConstructStringDefaultLengthExclusive() |
|
| 116 | - { |
|
| 117 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string<3,5>=word'); |
|
| 118 | - |
|
| 119 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 120 | - |
|
| 121 | - $this->assertSame(array( |
|
| 122 | - 'type' => 'string', |
|
| 123 | - 'default' => 'word', |
|
| 124 | - 'minLength' => 4, |
|
| 125 | - 'maxLength' => 4, |
|
| 126 | - ), $object->toArray()); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 131 | - */ |
|
| 132 | - public function testConstructBinary() |
|
| 133 | - { |
|
| 134 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'binary'); |
|
| 135 | - |
|
| 136 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 137 | - |
|
| 138 | - $this->assertSame(array( |
|
| 139 | - 'type' => 'string', |
|
| 140 | - 'format' => 'binary', |
|
| 141 | - ), $object->toArray()); |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 146 | - */ |
|
| 147 | - public function testConstructEnumRange() |
|
| 148 | - { |
|
| 149 | - $this->expectException('\SwaggerGen\Exception', "Range not allowed in enumeration definition: 'enum(a,b)[,]'"); |
|
| 150 | - |
|
| 151 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'enum(a,b)[,]'); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 156 | - */ |
|
| 157 | - public function testConstructEnumInvalidDefault() |
|
| 158 | - { |
|
| 159 | - $this->expectException('\SwaggerGen\Exception', "Invalid enum default: 'c'"); |
|
| 160 | - |
|
| 161 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'enum(a,b)=c'); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 166 | - */ |
|
| 167 | - public function testConstructEnum() |
|
| 168 | - { |
|
| 169 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'enum(a,b)'); |
|
| 170 | - |
|
| 171 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 172 | - |
|
| 173 | - $this->assertSame(array( |
|
| 174 | - 'type' => 'string', |
|
| 175 | - 'enum' => array('a', 'b'), |
|
| 176 | - ), $object->toArray()); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 181 | - */ |
|
| 182 | - public function testConstructEnumWithDefault() |
|
| 183 | - { |
|
| 184 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'enum(a,b)=a'); |
|
| 185 | - |
|
| 186 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 187 | - |
|
| 188 | - $this->assertSame(array( |
|
| 189 | - 'type' => 'string', |
|
| 190 | - 'default' => 'a', |
|
| 191 | - 'enum' => array('a', 'b'), |
|
| 192 | - ), $object->toArray()); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 197 | - */ |
|
| 198 | - public function testConstructPattern() |
|
| 199 | - { |
|
| 200 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string([a-z])'); |
|
| 201 | - |
|
| 202 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 203 | - |
|
| 204 | - $this->assertSame(array( |
|
| 205 | - 'type' => 'string', |
|
| 206 | - 'pattern' => '[a-z]', |
|
| 207 | - ), $object->toArray()); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
| 212 | - */ |
|
| 213 | - public function testCommandDefaultNoValue() |
|
| 214 | - { |
|
| 215 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
| 216 | - |
|
| 217 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 218 | - |
|
| 219 | - $this->expectException('\SwaggerGen\Exception', "Empty string default"); |
|
| 220 | - $object->handleCommand('default', ''); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
| 225 | - */ |
|
| 226 | - public function testCommandDefault() |
|
| 227 | - { |
|
| 228 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
| 229 | - |
|
| 230 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 231 | - |
|
| 232 | - $object->handleCommand('default', 'word'); |
|
| 233 | - |
|
| 234 | - $this->assertSame(array( |
|
| 235 | - 'type' => 'string', |
|
| 236 | - 'default' => 'word', |
|
| 237 | - ), $object->toArray()); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
| 242 | - */ |
|
| 243 | - public function testCommandPattern() |
|
| 244 | - { |
|
| 245 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
| 246 | - |
|
| 247 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 248 | - |
|
| 249 | - $object->handleCommand('pattern', '[a-z]'); |
|
| 250 | - |
|
| 251 | - $this->assertSame(array( |
|
| 252 | - 'type' => 'string', |
|
| 253 | - 'pattern' => '[a-z]', |
|
| 254 | - ), $object->toArray()); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
| 259 | - */ |
|
| 260 | - public function testCommandEnumWhenRange() |
|
| 261 | - { |
|
| 262 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[0,]'); |
|
| 263 | - |
|
| 264 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 265 | - |
|
| 266 | - $this->expectException('\SwaggerGen\Exception', "Enumeration not allowed in ranged string: 'red green blue'"); |
|
| 267 | - |
|
| 268 | - $object->handleCommand('enum', 'red green blue'); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
| 273 | - */ |
|
| 274 | - public function testCommandEnum() |
|
| 275 | - { |
|
| 276 | - $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
| 277 | - |
|
| 278 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 279 | - |
|
| 280 | - $object->handleCommand('enum', 'red green blue'); |
|
| 281 | - |
|
| 282 | - $this->assertSame(array( |
|
| 283 | - 'type' => 'string', |
|
| 284 | - 'enum' => array('red', 'green', 'blue'), |
|
| 285 | - ), $object->toArray()); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - protected function setUp(): void |
|
| 289 | - { |
|
| 290 | - $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - protected function assertPreConditions(): void |
|
| 294 | - { |
|
| 295 | - $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
| 296 | - } |
|
| 9 | + protected $parent; |
|
| 10 | + |
|
| 11 | + /** |
|
| 12 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 13 | + */ |
|
| 14 | + public function testConstructNotAString() |
|
| 15 | + { |
|
| 16 | + $this->expectException('\SwaggerGen\Exception', "Not a string: 'wrong'"); |
|
| 17 | + |
|
| 18 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'wrong'); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 23 | + */ |
|
| 24 | + public function testConstructEmptyRange() |
|
| 25 | + { |
|
| 26 | + $this->expectException('\SwaggerGen\Exception', "Empty string range: 'string[,]=1'"); |
|
| 27 | + |
|
| 28 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[,]=1'); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 33 | + */ |
|
| 34 | + public function testConstructDefaultTooLongInclusive() |
|
| 35 | + { |
|
| 36 | + $this->expectException('\SwaggerGen\Exception', "Default string length beyond maximum: 'long'"); |
|
| 37 | + |
|
| 38 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[,3]=long'); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 43 | + */ |
|
| 44 | + public function testConstructDefaultTooLongExclusive() |
|
| 45 | + { |
|
| 46 | + $this->expectException('\SwaggerGen\Exception', "Default string length beyond maximum: 'long'"); |
|
| 47 | + |
|
| 48 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[,4>=long'); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 53 | + */ |
|
| 54 | + public function testConstructDefaultTooShortInclusive() |
|
| 55 | + { |
|
| 56 | + $this->expectException('\SwaggerGen\Exception', "Default string length beyond minimum: 'short'"); |
|
| 57 | + |
|
| 58 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[6,]=short'); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 63 | + */ |
|
| 64 | + public function testConstructDefaultTooShortExclusive() |
|
| 65 | + { |
|
| 66 | + $this->expectException('\SwaggerGen\Exception', "Default string length beyond minimum: 'short'"); |
|
| 67 | + |
|
| 68 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string<5,]=short'); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 73 | + */ |
|
| 74 | + public function testConstructString() |
|
| 75 | + { |
|
| 76 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
| 77 | + |
|
| 78 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 79 | + |
|
| 80 | + $this->assertSame(array( |
|
| 81 | + 'type' => 'string', |
|
| 82 | + ), $object->toArray()); |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 87 | + */ |
|
| 88 | + public function testConstructStringEmptyDefault() |
|
| 89 | + { |
|
| 90 | + $this->expectException('\SwaggerGen\Exception', "Unparseable string definition: 'string='"); |
|
| 91 | + |
|
| 92 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string= '); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 97 | + */ |
|
| 98 | + public function testConstructStringDefaultLengthInclusive() |
|
| 99 | + { |
|
| 100 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[4,4]=word'); |
|
| 101 | + |
|
| 102 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 103 | + |
|
| 104 | + $this->assertSame(array( |
|
| 105 | + 'type' => 'string', |
|
| 106 | + 'default' => 'word', |
|
| 107 | + 'minLength' => 4, |
|
| 108 | + 'maxLength' => 4, |
|
| 109 | + ), $object->toArray()); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 114 | + */ |
|
| 115 | + public function testConstructStringDefaultLengthExclusive() |
|
| 116 | + { |
|
| 117 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string<3,5>=word'); |
|
| 118 | + |
|
| 119 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 120 | + |
|
| 121 | + $this->assertSame(array( |
|
| 122 | + 'type' => 'string', |
|
| 123 | + 'default' => 'word', |
|
| 124 | + 'minLength' => 4, |
|
| 125 | + 'maxLength' => 4, |
|
| 126 | + ), $object->toArray()); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 131 | + */ |
|
| 132 | + public function testConstructBinary() |
|
| 133 | + { |
|
| 134 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'binary'); |
|
| 135 | + |
|
| 136 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 137 | + |
|
| 138 | + $this->assertSame(array( |
|
| 139 | + 'type' => 'string', |
|
| 140 | + 'format' => 'binary', |
|
| 141 | + ), $object->toArray()); |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 146 | + */ |
|
| 147 | + public function testConstructEnumRange() |
|
| 148 | + { |
|
| 149 | + $this->expectException('\SwaggerGen\Exception', "Range not allowed in enumeration definition: 'enum(a,b)[,]'"); |
|
| 150 | + |
|
| 151 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'enum(a,b)[,]'); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 156 | + */ |
|
| 157 | + public function testConstructEnumInvalidDefault() |
|
| 158 | + { |
|
| 159 | + $this->expectException('\SwaggerGen\Exception', "Invalid enum default: 'c'"); |
|
| 160 | + |
|
| 161 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'enum(a,b)=c'); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 166 | + */ |
|
| 167 | + public function testConstructEnum() |
|
| 168 | + { |
|
| 169 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'enum(a,b)'); |
|
| 170 | + |
|
| 171 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 172 | + |
|
| 173 | + $this->assertSame(array( |
|
| 174 | + 'type' => 'string', |
|
| 175 | + 'enum' => array('a', 'b'), |
|
| 176 | + ), $object->toArray()); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 181 | + */ |
|
| 182 | + public function testConstructEnumWithDefault() |
|
| 183 | + { |
|
| 184 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'enum(a,b)=a'); |
|
| 185 | + |
|
| 186 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 187 | + |
|
| 188 | + $this->assertSame(array( |
|
| 189 | + 'type' => 'string', |
|
| 190 | + 'default' => 'a', |
|
| 191 | + 'enum' => array('a', 'b'), |
|
| 192 | + ), $object->toArray()); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * @covers \SwaggerGen\Swagger\Type\StringType::__construct |
|
| 197 | + */ |
|
| 198 | + public function testConstructPattern() |
|
| 199 | + { |
|
| 200 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string([a-z])'); |
|
| 201 | + |
|
| 202 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 203 | + |
|
| 204 | + $this->assertSame(array( |
|
| 205 | + 'type' => 'string', |
|
| 206 | + 'pattern' => '[a-z]', |
|
| 207 | + ), $object->toArray()); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
| 212 | + */ |
|
| 213 | + public function testCommandDefaultNoValue() |
|
| 214 | + { |
|
| 215 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
| 216 | + |
|
| 217 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 218 | + |
|
| 219 | + $this->expectException('\SwaggerGen\Exception', "Empty string default"); |
|
| 220 | + $object->handleCommand('default', ''); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
| 225 | + */ |
|
| 226 | + public function testCommandDefault() |
|
| 227 | + { |
|
| 228 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
| 229 | + |
|
| 230 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 231 | + |
|
| 232 | + $object->handleCommand('default', 'word'); |
|
| 233 | + |
|
| 234 | + $this->assertSame(array( |
|
| 235 | + 'type' => 'string', |
|
| 236 | + 'default' => 'word', |
|
| 237 | + ), $object->toArray()); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
| 242 | + */ |
|
| 243 | + public function testCommandPattern() |
|
| 244 | + { |
|
| 245 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
| 246 | + |
|
| 247 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 248 | + |
|
| 249 | + $object->handleCommand('pattern', '[a-z]'); |
|
| 250 | + |
|
| 251 | + $this->assertSame(array( |
|
| 252 | + 'type' => 'string', |
|
| 253 | + 'pattern' => '[a-z]', |
|
| 254 | + ), $object->toArray()); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
| 259 | + */ |
|
| 260 | + public function testCommandEnumWhenRange() |
|
| 261 | + { |
|
| 262 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string[0,]'); |
|
| 263 | + |
|
| 264 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 265 | + |
|
| 266 | + $this->expectException('\SwaggerGen\Exception', "Enumeration not allowed in ranged string: 'red green blue'"); |
|
| 267 | + |
|
| 268 | + $object->handleCommand('enum', 'red green blue'); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * @covers \SwaggerGen\Swagger\Type\StringType->handleCommand |
|
| 273 | + */ |
|
| 274 | + public function testCommandEnum() |
|
| 275 | + { |
|
| 276 | + $object = new SwaggerGen\Swagger\Type\StringType($this->parent, 'string'); |
|
| 277 | + |
|
| 278 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\StringType', $object); |
|
| 279 | + |
|
| 280 | + $object->handleCommand('enum', 'red green blue'); |
|
| 281 | + |
|
| 282 | + $this->assertSame(array( |
|
| 283 | + 'type' => 'string', |
|
| 284 | + 'enum' => array('red', 'green', 'blue'), |
|
| 285 | + ), $object->toArray()); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + protected function setUp(): void |
|
| 289 | + { |
|
| 290 | + $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\AbstractObject'); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + protected function assertPreConditions(): void |
|
| 294 | + { |
|
| 295 | + $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
| 296 | + } |
|
| 297 | 297 | |
| 298 | 298 | } |
@@ -6,130 +6,130 @@ |
||
| 6 | 6 | class PropertyTest extends TestCase |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - protected $parent; |
|
| 10 | - |
|
| 11 | - /** |
|
| 12 | - * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
| 13 | - */ |
|
| 14 | - public function testConstructEmpty() |
|
| 15 | - { |
|
| 16 | - $this->expectException('\SwaggerGen\Exception', "Not a property: ''"); |
|
| 17 | - |
|
| 18 | - new SwaggerGen\Swagger\Type\Property($this->parent, ''); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
| 23 | - */ |
|
| 24 | - public function testConstructReference() |
|
| 25 | - { |
|
| 26 | - $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'Address'); |
|
| 27 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
| 28 | - |
|
| 29 | - $this->assertSame(array( |
|
| 30 | - '$ref' => '#/definitions/Address', |
|
| 31 | - ), $object->toArray()); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
| 36 | - */ |
|
| 37 | - public function testConstructReferences() |
|
| 38 | - { |
|
| 39 | - $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'array(Address)'); |
|
| 40 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
| 41 | - |
|
| 42 | - $this->assertSame(array( |
|
| 43 | - 'type' => 'array', |
|
| 44 | - 'items' => array( |
|
| 45 | - '$ref' => '#/definitions/Address', |
|
| 46 | - ), |
|
| 47 | - ), $object->toArray()); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
| 52 | - */ |
|
| 53 | - public function testConstructString() |
|
| 54 | - { |
|
| 55 | - $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'string'); |
|
| 56 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
| 57 | - |
|
| 58 | - $this->assertSame(array( |
|
| 59 | - 'type' => 'string', |
|
| 60 | - ), $object->toArray()); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
| 65 | - */ |
|
| 66 | - public function testConstructDescription() |
|
| 67 | - { |
|
| 68 | - $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'string', 'Some words here'); |
|
| 69 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
| 70 | - |
|
| 71 | - $this->assertSame(array( |
|
| 72 | - 'type' => 'string', |
|
| 73 | - 'description' => 'Some words here', |
|
| 74 | - ), $object->toArray()); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
| 79 | - */ |
|
| 80 | - public function testConstructReadOnly() |
|
| 81 | - { |
|
| 82 | - $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'string', 'Some words here', true); |
|
| 83 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
| 84 | - |
|
| 85 | - $this->assertSame(array( |
|
| 86 | - 'type' => 'string', |
|
| 87 | - 'description' => 'Some words here', |
|
| 88 | - 'readOnly' => true |
|
| 89 | - ), $object->toArray()); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
| 94 | - */ |
|
| 95 | - public function testConstructComplex() |
|
| 96 | - { |
|
| 97 | - $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'int[3,10>=6'); |
|
| 98 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
| 99 | - |
|
| 100 | - $this->assertSame(array( |
|
| 101 | - 'type' => 'integer', |
|
| 102 | - 'format' => 'int32', |
|
| 103 | - 'default' => 6, |
|
| 104 | - 'minimum' => 3, |
|
| 105 | - 'maximum' => 10, |
|
| 106 | - 'exclusiveMaximum' => true, |
|
| 107 | - ), $object->toArray()); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 112 | - */ |
|
| 113 | - public function testCommandPassing() |
|
| 114 | - { |
|
| 115 | - $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'string'); |
|
| 116 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
| 117 | - |
|
| 118 | - $object->handleCommand('default', 'good'); |
|
| 119 | - $this->assertSame(array( |
|
| 120 | - 'type' => 'string', |
|
| 121 | - 'default' => 'good', |
|
| 122 | - ), $object->toArray()); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - protected function setUp(): void |
|
| 126 | - { |
|
| 127 | - $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\Swagger'); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - protected function assertPreConditions(): void |
|
| 131 | - { |
|
| 132 | - $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
| 133 | - } |
|
| 9 | + protected $parent; |
|
| 10 | + |
|
| 11 | + /** |
|
| 12 | + * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
| 13 | + */ |
|
| 14 | + public function testConstructEmpty() |
|
| 15 | + { |
|
| 16 | + $this->expectException('\SwaggerGen\Exception', "Not a property: ''"); |
|
| 17 | + |
|
| 18 | + new SwaggerGen\Swagger\Type\Property($this->parent, ''); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
| 23 | + */ |
|
| 24 | + public function testConstructReference() |
|
| 25 | + { |
|
| 26 | + $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'Address'); |
|
| 27 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
| 28 | + |
|
| 29 | + $this->assertSame(array( |
|
| 30 | + '$ref' => '#/definitions/Address', |
|
| 31 | + ), $object->toArray()); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
| 36 | + */ |
|
| 37 | + public function testConstructReferences() |
|
| 38 | + { |
|
| 39 | + $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'array(Address)'); |
|
| 40 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
| 41 | + |
|
| 42 | + $this->assertSame(array( |
|
| 43 | + 'type' => 'array', |
|
| 44 | + 'items' => array( |
|
| 45 | + '$ref' => '#/definitions/Address', |
|
| 46 | + ), |
|
| 47 | + ), $object->toArray()); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
| 52 | + */ |
|
| 53 | + public function testConstructString() |
|
| 54 | + { |
|
| 55 | + $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'string'); |
|
| 56 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
| 57 | + |
|
| 58 | + $this->assertSame(array( |
|
| 59 | + 'type' => 'string', |
|
| 60 | + ), $object->toArray()); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
| 65 | + */ |
|
| 66 | + public function testConstructDescription() |
|
| 67 | + { |
|
| 68 | + $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'string', 'Some words here'); |
|
| 69 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
| 70 | + |
|
| 71 | + $this->assertSame(array( |
|
| 72 | + 'type' => 'string', |
|
| 73 | + 'description' => 'Some words here', |
|
| 74 | + ), $object->toArray()); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
| 79 | + */ |
|
| 80 | + public function testConstructReadOnly() |
|
| 81 | + { |
|
| 82 | + $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'string', 'Some words here', true); |
|
| 83 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
| 84 | + |
|
| 85 | + $this->assertSame(array( |
|
| 86 | + 'type' => 'string', |
|
| 87 | + 'description' => 'Some words here', |
|
| 88 | + 'readOnly' => true |
|
| 89 | + ), $object->toArray()); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @covers \SwaggerGen\Swagger\Type\PropertyType::__construct |
|
| 94 | + */ |
|
| 95 | + public function testConstructComplex() |
|
| 96 | + { |
|
| 97 | + $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'int[3,10>=6'); |
|
| 98 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
| 99 | + |
|
| 100 | + $this->assertSame(array( |
|
| 101 | + 'type' => 'integer', |
|
| 102 | + 'format' => 'int32', |
|
| 103 | + 'default' => 6, |
|
| 104 | + 'minimum' => 3, |
|
| 105 | + 'maximum' => 10, |
|
| 106 | + 'exclusiveMaximum' => true, |
|
| 107 | + ), $object->toArray()); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 112 | + */ |
|
| 113 | + public function testCommandPassing() |
|
| 114 | + { |
|
| 115 | + $object = new SwaggerGen\Swagger\Type\Property($this->parent, 'string'); |
|
| 116 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\Property', $object); |
|
| 117 | + |
|
| 118 | + $object->handleCommand('default', 'good'); |
|
| 119 | + $this->assertSame(array( |
|
| 120 | + 'type' => 'string', |
|
| 121 | + 'default' => 'good', |
|
| 122 | + ), $object->toArray()); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + protected function setUp(): void |
|
| 126 | + { |
|
| 127 | + $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\Swagger'); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + protected function assertPreConditions(): void |
|
| 131 | + { |
|
| 132 | + $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | 135 | } |
@@ -6,372 +6,372 @@ |
||
| 6 | 6 | class ArrayTypeTest extends TestCase |
| 7 | 7 | { |
| 8 | 8 | |
| 9 | - protected $parent; |
|
| 10 | - |
|
| 11 | - /** |
|
| 12 | - * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 13 | - */ |
|
| 14 | - public function testConstructNotAArray() |
|
| 15 | - { |
|
| 16 | - $this->expectException('\SwaggerGen\Exception', "Not an array: 'wrong'"); |
|
| 17 | - |
|
| 18 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'wrong'); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 23 | - */ |
|
| 24 | - public function testConstructInvalidDefault() |
|
| 25 | - { |
|
| 26 | - $this->expectException('\SwaggerGen\Exception', "Unparseable array definition: 'array=null'"); |
|
| 27 | - |
|
| 28 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array=null'); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 33 | - */ |
|
| 34 | - public function testConstructMultiLimit() |
|
| 35 | - { |
|
| 36 | - $this->expectException('\SwaggerGen\Exception', "Multi array only allowed on query or form parameter: 'multi'"); |
|
| 37 | - |
|
| 38 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'multi'); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 43 | - */ |
|
| 44 | - public function testConstructMultiOnFormParam() |
|
| 45 | - { |
|
| 46 | - $param = new \SwaggerGen\Swagger\Parameter($this->parent, 'form', 'multi foo'); |
|
| 47 | - |
|
| 48 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $param); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 53 | - */ |
|
| 54 | - public function testConstructEmptyRange() |
|
| 55 | - { |
|
| 56 | - $this->expectException('\SwaggerGen\Exception', "Empty array range: 'array[,]'"); |
|
| 57 | - |
|
| 58 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[,]'); |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 63 | - */ |
|
| 64 | - public function testConstructRangeStart() |
|
| 65 | - { |
|
| 66 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[0,]'); |
|
| 67 | - |
|
| 68 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 69 | - |
|
| 70 | - $this->assertSame(array( |
|
| 71 | - 'type' => 'array', |
|
| 72 | - 'minItems' => 0, |
|
| 73 | - ), $object->toArray()); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 78 | - */ |
|
| 79 | - public function testConstructRangeBoth() |
|
| 80 | - { |
|
| 81 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array<2,4]'); |
|
| 82 | - |
|
| 83 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 84 | - |
|
| 85 | - $this->assertSame(array( |
|
| 86 | - 'type' => 'array', |
|
| 87 | - 'minItems' => 3, |
|
| 88 | - 'maxItems' => 4, |
|
| 89 | - ), $object->toArray()); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 94 | - */ |
|
| 95 | - public function testConstructEmptyItems() |
|
| 96 | - { |
|
| 97 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array()'); |
|
| 98 | - |
|
| 99 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 100 | - |
|
| 101 | - $this->assertSame(array( |
|
| 102 | - 'type' => 'array', |
|
| 103 | - ), $object->toArray()); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 108 | - */ |
|
| 109 | - public function testConstructBadItems() |
|
| 110 | - { |
|
| 111 | - $this->expectException('\SwaggerGen\Exception', "Unparseable items definition: '1'"); |
|
| 112 | - |
|
| 113 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array(1)'); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 118 | - */ |
|
| 119 | - public function testConstructTypeItems() |
|
| 120 | - { |
|
| 121 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array(string)'); |
|
| 122 | - |
|
| 123 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 124 | - |
|
| 125 | - $this->assertSame(array( |
|
| 126 | - 'type' => 'array', |
|
| 127 | - 'items' => array( |
|
| 128 | - 'type' => 'string', |
|
| 129 | - ), |
|
| 130 | - ), $object->toArray()); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 135 | - */ |
|
| 136 | - public function testConstructBracketsTypeItems() |
|
| 137 | - { |
|
| 138 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, '[string]'); |
|
| 139 | - |
|
| 140 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 141 | - |
|
| 142 | - $this->assertSame(array( |
|
| 143 | - 'type' => 'array', |
|
| 144 | - 'items' => array( |
|
| 145 | - 'type' => 'string', |
|
| 146 | - ), |
|
| 147 | - ), $object->toArray()); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 152 | - */ |
|
| 153 | - public function testConstructTypeItemsPipes() |
|
| 154 | - { |
|
| 155 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'pipes(string)'); |
|
| 156 | - |
|
| 157 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 158 | - |
|
| 159 | - $this->assertSame(array( |
|
| 160 | - 'type' => 'array', |
|
| 161 | - 'items' => array( |
|
| 162 | - 'type' => 'string', |
|
| 163 | - ), |
|
| 164 | - 'collectionFormat' => 'pipes', |
|
| 165 | - ), $object->toArray()); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 170 | - */ |
|
| 171 | - public function testConstructReferenceItems() |
|
| 172 | - { |
|
| 173 | - $this->parent->handleCommand('model', 'Item'); |
|
| 174 | - |
|
| 175 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array(Item)'); |
|
| 176 | - |
|
| 177 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 178 | - |
|
| 179 | - $this->assertSame(array( |
|
| 180 | - 'type' => 'array', |
|
| 181 | - 'items' => array( |
|
| 182 | - '$ref' => '#/definitions/Item', |
|
| 183 | - ), |
|
| 184 | - ), $object->toArray()); |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 189 | - */ |
|
| 190 | - public function testCommandMinUpperBound() |
|
| 191 | - { |
|
| 192 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[3,5]'); |
|
| 193 | - |
|
| 194 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 195 | - |
|
| 196 | - $this->expectException('\SwaggerGen\Exception', "Minimum greater than maximum: '6'"); |
|
| 197 | - |
|
| 198 | - $object->handleCommand('min', '6'); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - /** |
|
| 202 | - * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 203 | - */ |
|
| 204 | - public function testCommandMinLowerBound() |
|
| 205 | - { |
|
| 206 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[3,5]'); |
|
| 207 | - |
|
| 208 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 209 | - |
|
| 210 | - $this->expectException('\SwaggerGen\Exception', "Minimum less than zero: '-1'"); |
|
| 211 | - |
|
| 212 | - $object->handleCommand('min', '-1'); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 217 | - */ |
|
| 218 | - public function testCommandMin() |
|
| 219 | - { |
|
| 220 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[3,5]'); |
|
| 221 | - |
|
| 222 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 223 | - |
|
| 224 | - $object->handleCommand('min', '4'); |
|
| 225 | - |
|
| 226 | - $this->assertSame(array( |
|
| 227 | - 'type' => 'array', |
|
| 228 | - 'minItems' => 4, |
|
| 229 | - 'maxItems' => 5, |
|
| 230 | - ), $object->toArray()); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 235 | - */ |
|
| 236 | - public function testCommandMaxLowerBound() |
|
| 237 | - { |
|
| 238 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[3,5]'); |
|
| 9 | + protected $parent; |
|
| 10 | + |
|
| 11 | + /** |
|
| 12 | + * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 13 | + */ |
|
| 14 | + public function testConstructNotAArray() |
|
| 15 | + { |
|
| 16 | + $this->expectException('\SwaggerGen\Exception', "Not an array: 'wrong'"); |
|
| 17 | + |
|
| 18 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'wrong'); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 23 | + */ |
|
| 24 | + public function testConstructInvalidDefault() |
|
| 25 | + { |
|
| 26 | + $this->expectException('\SwaggerGen\Exception', "Unparseable array definition: 'array=null'"); |
|
| 27 | + |
|
| 28 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array=null'); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 33 | + */ |
|
| 34 | + public function testConstructMultiLimit() |
|
| 35 | + { |
|
| 36 | + $this->expectException('\SwaggerGen\Exception', "Multi array only allowed on query or form parameter: 'multi'"); |
|
| 37 | + |
|
| 38 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'multi'); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 43 | + */ |
|
| 44 | + public function testConstructMultiOnFormParam() |
|
| 45 | + { |
|
| 46 | + $param = new \SwaggerGen\Swagger\Parameter($this->parent, 'form', 'multi foo'); |
|
| 47 | + |
|
| 48 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Parameter', $param); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 53 | + */ |
|
| 54 | + public function testConstructEmptyRange() |
|
| 55 | + { |
|
| 56 | + $this->expectException('\SwaggerGen\Exception', "Empty array range: 'array[,]'"); |
|
| 57 | + |
|
| 58 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[,]'); |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 63 | + */ |
|
| 64 | + public function testConstructRangeStart() |
|
| 65 | + { |
|
| 66 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[0,]'); |
|
| 67 | + |
|
| 68 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 69 | + |
|
| 70 | + $this->assertSame(array( |
|
| 71 | + 'type' => 'array', |
|
| 72 | + 'minItems' => 0, |
|
| 73 | + ), $object->toArray()); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 78 | + */ |
|
| 79 | + public function testConstructRangeBoth() |
|
| 80 | + { |
|
| 81 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array<2,4]'); |
|
| 82 | + |
|
| 83 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 84 | + |
|
| 85 | + $this->assertSame(array( |
|
| 86 | + 'type' => 'array', |
|
| 87 | + 'minItems' => 3, |
|
| 88 | + 'maxItems' => 4, |
|
| 89 | + ), $object->toArray()); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 94 | + */ |
|
| 95 | + public function testConstructEmptyItems() |
|
| 96 | + { |
|
| 97 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array()'); |
|
| 98 | + |
|
| 99 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 100 | + |
|
| 101 | + $this->assertSame(array( |
|
| 102 | + 'type' => 'array', |
|
| 103 | + ), $object->toArray()); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 108 | + */ |
|
| 109 | + public function testConstructBadItems() |
|
| 110 | + { |
|
| 111 | + $this->expectException('\SwaggerGen\Exception', "Unparseable items definition: '1'"); |
|
| 112 | + |
|
| 113 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array(1)'); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 118 | + */ |
|
| 119 | + public function testConstructTypeItems() |
|
| 120 | + { |
|
| 121 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array(string)'); |
|
| 122 | + |
|
| 123 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 124 | + |
|
| 125 | + $this->assertSame(array( |
|
| 126 | + 'type' => 'array', |
|
| 127 | + 'items' => array( |
|
| 128 | + 'type' => 'string', |
|
| 129 | + ), |
|
| 130 | + ), $object->toArray()); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 135 | + */ |
|
| 136 | + public function testConstructBracketsTypeItems() |
|
| 137 | + { |
|
| 138 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, '[string]'); |
|
| 139 | + |
|
| 140 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 141 | + |
|
| 142 | + $this->assertSame(array( |
|
| 143 | + 'type' => 'array', |
|
| 144 | + 'items' => array( |
|
| 145 | + 'type' => 'string', |
|
| 146 | + ), |
|
| 147 | + ), $object->toArray()); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 152 | + */ |
|
| 153 | + public function testConstructTypeItemsPipes() |
|
| 154 | + { |
|
| 155 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'pipes(string)'); |
|
| 156 | + |
|
| 157 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 158 | + |
|
| 159 | + $this->assertSame(array( |
|
| 160 | + 'type' => 'array', |
|
| 161 | + 'items' => array( |
|
| 162 | + 'type' => 'string', |
|
| 163 | + ), |
|
| 164 | + 'collectionFormat' => 'pipes', |
|
| 165 | + ), $object->toArray()); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @covers \SwaggerGen\Swagger\Type\ArrayType::__construct |
|
| 170 | + */ |
|
| 171 | + public function testConstructReferenceItems() |
|
| 172 | + { |
|
| 173 | + $this->parent->handleCommand('model', 'Item'); |
|
| 174 | + |
|
| 175 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array(Item)'); |
|
| 176 | + |
|
| 177 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 178 | + |
|
| 179 | + $this->assertSame(array( |
|
| 180 | + 'type' => 'array', |
|
| 181 | + 'items' => array( |
|
| 182 | + '$ref' => '#/definitions/Item', |
|
| 183 | + ), |
|
| 184 | + ), $object->toArray()); |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 189 | + */ |
|
| 190 | + public function testCommandMinUpperBound() |
|
| 191 | + { |
|
| 192 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[3,5]'); |
|
| 193 | + |
|
| 194 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 195 | + |
|
| 196 | + $this->expectException('\SwaggerGen\Exception', "Minimum greater than maximum: '6'"); |
|
| 197 | + |
|
| 198 | + $object->handleCommand('min', '6'); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + /** |
|
| 202 | + * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 203 | + */ |
|
| 204 | + public function testCommandMinLowerBound() |
|
| 205 | + { |
|
| 206 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[3,5]'); |
|
| 207 | + |
|
| 208 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 209 | + |
|
| 210 | + $this->expectException('\SwaggerGen\Exception', "Minimum less than zero: '-1'"); |
|
| 211 | + |
|
| 212 | + $object->handleCommand('min', '-1'); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 217 | + */ |
|
| 218 | + public function testCommandMin() |
|
| 219 | + { |
|
| 220 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[3,5]'); |
|
| 221 | + |
|
| 222 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 223 | + |
|
| 224 | + $object->handleCommand('min', '4'); |
|
| 225 | + |
|
| 226 | + $this->assertSame(array( |
|
| 227 | + 'type' => 'array', |
|
| 228 | + 'minItems' => 4, |
|
| 229 | + 'maxItems' => 5, |
|
| 230 | + ), $object->toArray()); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 235 | + */ |
|
| 236 | + public function testCommandMaxLowerBound() |
|
| 237 | + { |
|
| 238 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[3,5]'); |
|
| 239 | 239 | |
| 240 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 241 | - |
|
| 242 | - $this->expectException('\SwaggerGen\Exception', "Maximum less than minimum: '2'"); |
|
| 243 | - |
|
| 244 | - $object->handleCommand('max', '2'); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 249 | - */ |
|
| 250 | - public function testCommandMaxUpperBound() |
|
| 251 | - { |
|
| 252 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array'); |
|
| 253 | - |
|
| 254 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 240 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 241 | + |
|
| 242 | + $this->expectException('\SwaggerGen\Exception', "Maximum less than minimum: '2'"); |
|
| 243 | + |
|
| 244 | + $object->handleCommand('max', '2'); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 249 | + */ |
|
| 250 | + public function testCommandMaxUpperBound() |
|
| 251 | + { |
|
| 252 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array'); |
|
| 253 | + |
|
| 254 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 255 | 255 | |
| 256 | - $this->expectException('\SwaggerGen\Exception', "Maximum less than zero: '-1'"); |
|
| 256 | + $this->expectException('\SwaggerGen\Exception', "Maximum less than zero: '-1'"); |
|
| 257 | 257 | |
| 258 | - $object->handleCommand('max', '-1'); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 263 | - */ |
|
| 264 | - public function testCommandMax() |
|
| 265 | - { |
|
| 266 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[3,5]'); |
|
| 258 | + $object->handleCommand('max', '-1'); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 263 | + */ |
|
| 264 | + public function testCommandMax() |
|
| 265 | + { |
|
| 266 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[3,5]'); |
|
| 267 | 267 | |
| 268 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 269 | - |
|
| 270 | - $object->handleCommand('max', '4'); |
|
| 268 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 269 | + |
|
| 270 | + $object->handleCommand('max', '4'); |
|
| 271 | 271 | |
| 272 | - $this->assertSame(array( |
|
| 273 | - 'type' => 'array', |
|
| 274 | - 'minItems' => 3, |
|
| 275 | - 'maxItems' => 4, |
|
| 276 | - ), $object->toArray()); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 281 | - */ |
|
| 282 | - public function testCommandEmptyItems() |
|
| 283 | - { |
|
| 284 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[3,5]'); |
|
| 272 | + $this->assertSame(array( |
|
| 273 | + 'type' => 'array', |
|
| 274 | + 'minItems' => 3, |
|
| 275 | + 'maxItems' => 4, |
|
| 276 | + ), $object->toArray()); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 281 | + */ |
|
| 282 | + public function testCommandEmptyItems() |
|
| 283 | + { |
|
| 284 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[3,5]'); |
|
| 285 | 285 | |
| 286 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 287 | - |
|
| 288 | - $this->expectException('\SwaggerGen\Exception', "Empty items definition: ''"); |
|
| 286 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 287 | + |
|
| 288 | + $this->expectException('\SwaggerGen\Exception', "Empty items definition: ''"); |
|
| 289 | 289 | |
| 290 | - $object->handleCommand('items', ''); |
|
| 291 | - } |
|
| 290 | + $object->handleCommand('items', ''); |
|
| 291 | + } |
|
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 295 | - */ |
|
| 296 | - public function testCommandBadItems() |
|
| 297 | - { |
|
| 298 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[3,5]'); |
|
| 299 | - |
|
| 300 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 301 | - |
|
| 302 | - $this->expectException('\SwaggerGen\Exception', "Unparseable items definition: '1'"); |
|
| 303 | - |
|
| 304 | - $object->handleCommand('items', '1'); |
|
| 305 | - } |
|
| 293 | + /** |
|
| 294 | + * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 295 | + */ |
|
| 296 | + public function testCommandBadItems() |
|
| 297 | + { |
|
| 298 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array[3,5]'); |
|
| 299 | + |
|
| 300 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 301 | + |
|
| 302 | + $this->expectException('\SwaggerGen\Exception', "Unparseable items definition: '1'"); |
|
| 303 | + |
|
| 304 | + $object->handleCommand('items', '1'); |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - /** |
|
| 308 | - * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 309 | - */ |
|
| 310 | - public function testCommandTypeItems() |
|
| 311 | - { |
|
| 312 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array'); |
|
| 313 | - |
|
| 314 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 315 | - |
|
| 316 | - $object->handleCommand('items', 'string'); |
|
| 317 | - |
|
| 318 | - $this->assertSame(array( |
|
| 319 | - 'type' => 'array', |
|
| 320 | - 'items' => array( |
|
| 321 | - 'type' => 'string', |
|
| 322 | - ), |
|
| 323 | - ), $object->toArray()); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 328 | - */ |
|
| 329 | - public function testCommandReferenceItems() |
|
| 330 | - { |
|
| 331 | - $this->parent->handleCommand('model', 'Item'); |
|
| 332 | - |
|
| 333 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array'); |
|
| 334 | - |
|
| 335 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 336 | - |
|
| 337 | - $object->handleCommand('items', 'Item'); |
|
| 307 | + /** |
|
| 308 | + * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 309 | + */ |
|
| 310 | + public function testCommandTypeItems() |
|
| 311 | + { |
|
| 312 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array'); |
|
| 313 | + |
|
| 314 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 315 | + |
|
| 316 | + $object->handleCommand('items', 'string'); |
|
| 317 | + |
|
| 318 | + $this->assertSame(array( |
|
| 319 | + 'type' => 'array', |
|
| 320 | + 'items' => array( |
|
| 321 | + 'type' => 'string', |
|
| 322 | + ), |
|
| 323 | + ), $object->toArray()); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 328 | + */ |
|
| 329 | + public function testCommandReferenceItems() |
|
| 330 | + { |
|
| 331 | + $this->parent->handleCommand('model', 'Item'); |
|
| 332 | + |
|
| 333 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array'); |
|
| 334 | + |
|
| 335 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 336 | + |
|
| 337 | + $object->handleCommand('items', 'Item'); |
|
| 338 | 338 | |
| 339 | - $this->assertSame(array( |
|
| 340 | - 'type' => 'array', |
|
| 341 | - 'items' => array( |
|
| 342 | - '$ref' => '#/definitions/Item', |
|
| 343 | - ), |
|
| 344 | - ), $object->toArray()); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 349 | - */ |
|
| 350 | - public function testCommandPassing() |
|
| 351 | - { |
|
| 352 | - $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array(string)'); |
|
| 339 | + $this->assertSame(array( |
|
| 340 | + 'type' => 'array', |
|
| 341 | + 'items' => array( |
|
| 342 | + '$ref' => '#/definitions/Item', |
|
| 343 | + ), |
|
| 344 | + ), $object->toArray()); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * @covers \SwaggerGen\Swagger\Type\ArrayType->handleCommand |
|
| 349 | + */ |
|
| 350 | + public function testCommandPassing() |
|
| 351 | + { |
|
| 352 | + $object = new SwaggerGen\Swagger\Type\ArrayType($this->parent, 'array(string)'); |
|
| 353 | 353 | |
| 354 | - $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 355 | - |
|
| 356 | - $object->handleCommand('default', 'good'); |
|
| 357 | - |
|
| 358 | - $this->assertSame(array( |
|
| 359 | - 'type' => 'array', |
|
| 360 | - 'items' => array( |
|
| 361 | - 'type' => 'string', |
|
| 362 | - 'default' => 'good', |
|
| 363 | - ), |
|
| 364 | - ), $object->toArray()); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - protected function setUp(): void |
|
| 368 | - { |
|
| 369 | - $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\Swagger'); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - protected function assertPreConditions(): void |
|
| 373 | - { |
|
| 374 | - $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
| 375 | - } |
|
| 354 | + $this->assertInstanceOf('\SwaggerGen\Swagger\Type\ArrayType', $object); |
|
| 355 | + |
|
| 356 | + $object->handleCommand('default', 'good'); |
|
| 357 | + |
|
| 358 | + $this->assertSame(array( |
|
| 359 | + 'type' => 'array', |
|
| 360 | + 'items' => array( |
|
| 361 | + 'type' => 'string', |
|
| 362 | + 'default' => 'good', |
|
| 363 | + ), |
|
| 364 | + ), $object->toArray()); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + protected function setUp(): void |
|
| 368 | + { |
|
| 369 | + $this->parent = $this->getMockForAbstractClass('\SwaggerGen\Swagger\Swagger'); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + protected function assertPreConditions(): void |
|
| 373 | + { |
|
| 374 | + $this->assertInstanceOf('\SwaggerGen\Swagger\AbstractObject', $this->parent); |
|
| 375 | + } |
|
| 376 | 376 | |
| 377 | 377 | } |
@@ -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 | } |