|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace DoclerLabs\ApiClientGenerator\Test\Functional\Input; |
| 6 | + |
| 7 | +use DoclerLabs\ApiClientGenerator\Input\Parser; |
| 8 | +use DoclerLabs\ApiClientGenerator\ServiceProvider; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | +use Pimple\Container; |
| 11 | + |
| 12 | +/** |
| 13 | + * @covers \DoclerLabs\ApiClientGenerator\Input\Parser |
| 14 | + */ |
| 15 | +class SpecificationTest extends TestCase |
| 16 | +{ |
| 17 | + protected Parser $sut; |
| 18 | + |
| 19 | + /** |
| 20 | + * @dataProvider contentTypesTestProvider |
| 21 | + */ |
| 22 | + public function testAllContentTypesArrayPopulatedCorrectly(array $data, array $expectedResult): void |
| 23 | + { |
| 24 | + $specification = $this->sut->parse($data, '/openapi.yaml'); |
| 25 | + static::assertSame($specification->getAllContentTypes(), $expectedResult); |
| 26 | + } |
| 27 | + |
| 28 | + public function contentTypesTestProvider(): array |
| 29 | + { |
| 30 | + return [ |
| 31 | + 'No serializers required' => [ |
| 32 | + [ |
| 33 | + 'openapi' => '3.0.0', |
| 34 | + 'info' => [ |
| 35 | + 'title' => 'Sample API', |
| 36 | + 'version' => '1.0.0', |
| 37 | + ], |
| 38 | + 'paths' => [ |
| 39 | + '/users/{userId}' => [ |
| 40 | + 'parameters' => [ |
| 41 | + [ |
| 42 | + 'in' => 'path', |
| 43 | + 'required' => true, |
| 44 | + 'name' => 'userId', |
| 45 | + 'schema' => [ |
| 46 | + 'type' => 'integer', |
| 47 | + ], |
| 48 | + ], |
| 49 | + ], |
| 50 | + 'delete' => [ |
| 51 | + 'operationId' => 'deleteUser', |
| 52 | + 'responses' => [ |
| 53 | + '204' => [ |
| 54 | + 'description' => 'OK', |
| 55 | + ], |
| 56 | + ], |
| 57 | + ], |
| 58 | + ], |
| 59 | + ], |
| 60 | + ], |
| 61 | + [], |
| 62 | + ], |
| 63 | + 'Serializer specified in request' => [ |
| 64 | + [ |
| 65 | + 'openapi' => '3.0.0', |
| 66 | + 'info' => [ |
| 67 | + 'title' => 'Sample API', |
| 68 | + 'version' => '1.0.0', |
| 69 | + ], |
| 70 | + 'paths' => [ |
| 71 | + '/users' => [ |
| 72 | + 'post' => [ |
| 73 | + 'operationId' => 'createUser', |
| 74 | + 'requestBody' => [ |
| 75 | + 'required' => true, |
| 76 | + 'content' => [ |
| 77 | + 'application/x-www-form-urlencoded' => [ |
| 78 | + 'schema' => [ |
| 79 | + 'type' => 'object', |
| 80 | + 'properties' => [ |
| 81 | + 'name' => [ |
| 82 | + 'type' => 'string', |
| 83 | + ], |
| 84 | + ], |
| 85 | + ], |
| 86 | + ], |
| 87 | + 'application/xml' => [ |
| 88 | + 'schema' => [ |
| 89 | + 'type' => 'object', |
| 90 | + 'properties' => [ |
| 91 | + 'name' => [ |
| 92 | + 'type' => 'string', |
| 93 | + ], |
| 94 | + ], |
| 95 | + ], |
| 96 | + ], |
| 97 | + ], |
| 98 | + ], |
| 99 | + 'responses' => [ |
| 100 | + '201' => [ |
| 101 | + 'description' => 'Created', |
| 102 | + ], |
| 103 | + ], |
| 104 | + ], |
| 105 | + ], |
| 106 | + ], |
| 107 | + ], |
| 108 | + [ |
| 109 | + 'application/xml', |
| 110 | + 'application/x-www-form-urlencoded', |
| 111 | + ], |
| 112 | + ], |
| 113 | + 'Serializer specified in response' => [ |
| 114 | + [ |
| 115 | + 'openapi' => '3.0.0', |
| 116 | + 'info' => [ |
| 117 | + 'title' => 'Sample API', |
| 118 | + 'version' => '1.0.0', |
| 119 | + ], |
| 120 | + 'paths' => [ |
| 121 | + '/users' => [ |
| 122 | + 'get' => [ |
| 123 | + 'operationId' => 'createUser', |
| 124 | + 'responses' => [ |
| 125 | + '200' => [ |
| 126 | + 'description' => 'Array of users', |
| 127 | + 'content' => [ |
| 128 | + 'application/json' => [ |
| 129 | + 'schema' => [ |
| 130 | + 'type' => 'object', |
| 131 | + 'properties' => [ |
| 132 | + 'name' => [ |
| 133 | + 'type' => 'string', |
| 134 | + ], |
| 135 | + ], |
| 136 | + ], |
| 137 | + ], |
| 138 | + 'application/xml' => [ |
| 139 | + 'schema' => [ |
| 140 | + 'type' => 'object', |
| 141 | + 'properties' => [ |
| 142 | + 'name' => [ |
| 143 | + 'type' => 'string', |
| 144 | + ], |
| 145 | + ], |
| 146 | + ], |
| 147 | + ], |
| 148 | + ], |
| 149 | + ], |
| 150 | + ], |
| 151 | + ], |
| 152 | + ], |
| 153 | + ], |
| 154 | + ], |
| 155 | + [ |
| 156 | + 'application/xml', |
| 157 | + 'application/json', |
| 158 | + ], |
| 159 | + ], |
| 160 | + 'Serializer specified in request and response' => [ |
| 161 | + [ |
| 162 | + 'openapi' => '3.0.0', |
| 163 | + 'info' => [ |
| 164 | + 'title' => 'Sample API', |
| 165 | + 'version' => '1.0.0', |
| 166 | + ], |
| 167 | + 'paths' => [ |
| 168 | + '/users/{userId}' => [ |
| 169 | + 'parameters' => [ |
| 170 | + [ |
| 171 | + 'in' => 'path', |
| 172 | + 'required' => true, |
| 173 | + 'name' => 'userId', |
| 174 | + 'schema' => [ |
| 175 | + 'type' => 'integer', |
| 176 | + ], |
| 177 | + ], |
| 178 | + ], |
| 179 | + 'patch' => [ |
| 180 | + 'operationId' => 'createUser', |
| 181 | + 'requestBody' => [ |
| 182 | + 'required' => true, |
| 183 | + 'content' => [ |
| 184 | + 'application/x-www-form-urlencoded' => [ |
| 185 | + 'schema' => [ |
| 186 | + 'type' => 'object', |
| 187 | + 'properties' => [ |
| 188 | + 'name' => [ |
| 189 | + 'type' => 'string', |
| 190 | + ], |
| 191 | + ], |
| 192 | + ], |
| 193 | + ], |
| 194 | + 'application/xml' => [ |
| 195 | + 'schema' => [ |
| 196 | + 'type' => 'object', |
| 197 | + 'properties' => [ |
| 198 | + 'name' => [ |
| 199 | + 'type' => 'string', |
| 200 | + ], |
| 201 | + ], |
| 202 | + ], |
| 203 | + ], |
| 204 | + ], |
| 205 | + ], |
| 206 | + 'responses' => [ |
| 207 | + '200' => [ |
| 208 | + 'description' => 'Modified user', |
| 209 | + 'content' => [ |
| 210 | + 'application/json' => [ |
| 211 | + 'schema' => [ |
| 212 | + 'type' => 'object', |
| 213 | + 'properties' => [ |
| 214 | + 'name' => [ |
| 215 | + 'type' => 'string', |
| 216 | + ], |
| 217 | + ], |
| 218 | + ], |
| 219 | + ], |
| 220 | + ], |
| 221 | + ], |
| 222 | + ], |
| 223 | + ], |
| 224 | + ], |
| 225 | + ], |
| 226 | + ], |
| 227 | + [ |
| 228 | + 'application/xml', |
| 229 | + 'application/x-www-form-urlencoded', |
| 230 | + 'application/json', |
| 231 | + ], |
| 232 | + ] |
| 233 | + ]; |
| 234 | + } |
| 235 | + |
| 236 | + protected function setUp(): void |
| 237 | + { |
| 238 | + $container = new Container(); |
| 239 | + $container->register(new ServiceProvider()); |
| 240 | + |
| 241 | + set_error_handler( |
| 242 | + static function (int $code, string $message) { |
| 243 | + }, |
| 244 | + E_USER_WARNING |
| 245 | + ); |
| 246 | + |
| 247 | + $this->sut = $container[Parser::class]; |
| 248 | + } |
| 249 | +} |
0 commit comments