|
2 | 2 |
|
3 | 3 | namespace PHPModelGenerator\Tests\Objects;
|
4 | 4 |
|
| 5 | +use PHPModelGenerator\Exception\Arrays\InvalidItemException; |
| 6 | +use PHPModelGenerator\Exception\Arrays\MinItemsException; |
5 | 7 | use PHPModelGenerator\Exception\FileSystemException;
|
| 8 | +use PHPModelGenerator\Exception\Generic\InvalidTypeException; |
6 | 9 | use PHPModelGenerator\Exception\RenderException;
|
7 | 10 | use PHPModelGenerator\Exception\SchemaException;
|
8 | 11 | use PHPModelGenerator\Model\GeneratorConfiguration;
|
@@ -229,8 +232,66 @@ public function validRecursiveMultiTypeDataProvider(): array
|
229 | 232 | {
|
230 | 233 | return [
|
231 | 234 | 'string' => ['Test'],
|
232 |
| - # 'array' => [['Test1', 'Test2']], |
233 |
| - # 'nested array' => [[['Test1', 'Test2'], 'Test3']], |
| 235 | + 'array' => [['Test1', 'Test2']], |
| 236 | + 'nested array' => [[['Test1', 'Test2'], 'Test3']], |
| 237 | + ]; |
| 238 | + } |
| 239 | + |
| 240 | + /** |
| 241 | + * @dataProvider invalidRecursiveMultiTypeDataProvider |
| 242 | + */ |
| 243 | + public function testInvalidRecursiveMultiType($input, string $expectedException, string $exceptionMessage): void |
| 244 | + { |
| 245 | + $this->expectException($expectedException); |
| 246 | + $this->expectExceptionMessage($exceptionMessage); |
| 247 | + |
| 248 | + $className = $this->generateClassFromFile('RecursiveMultiTypeProperty.json'); |
| 249 | + |
| 250 | + new $className(['property' => $input]); |
| 251 | + } |
| 252 | + |
| 253 | + public function invalidRecursiveMultiTypeDataProvider(): array |
| 254 | + { |
| 255 | + return [ |
| 256 | + 'int' => [ |
| 257 | + 1, |
| 258 | + InvalidTypeException::class, |
| 259 | + 'Invalid type for property. Requires [string, array], got integer', |
| 260 | + ], |
| 261 | + 'invalid item in array' => [ |
| 262 | + ['Test1', 1], |
| 263 | + InvalidItemException::class, |
| 264 | + <<<ERROR |
| 265 | +Invalid items in array item of array property: |
| 266 | + - invalid item #1 |
| 267 | + * Invalid type for item of array property. Requires [string, array], got integer |
| 268 | +ERROR |
| 269 | + ], |
| 270 | + 'invalid array length' => [ |
| 271 | + [], |
| 272 | + MinItemsException::class, |
| 273 | + 'Array property must not contain less than 2 items', |
| 274 | + ], |
| 275 | + 'invalid item in nested array' => [ |
| 276 | + ['Test1', [3, 'Test3']], |
| 277 | + InvalidItemException::class, |
| 278 | + <<<ERROR |
| 279 | +Invalid items in array item of array property: |
| 280 | + - invalid item #1 |
| 281 | + * Invalid items in array item of array property: |
| 282 | + - invalid item #0 |
| 283 | + * Invalid type for item of array property. Requires [string, array], got integer |
| 284 | +ERROR |
| 285 | + ], |
| 286 | + 'invalid array length in nested array' => [ |
| 287 | + ['Test1', []], |
| 288 | + InvalidItemException::class, |
| 289 | + <<<ERROR |
| 290 | +Invalid items in array item of array property: |
| 291 | + - invalid item #1 |
| 292 | + * Array item of array property must not contain less than 2 items |
| 293 | +ERROR |
| 294 | + ], |
234 | 295 | ];
|
235 | 296 | }
|
236 | 297 | }
|
0 commit comments