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