|
15 | 15 | */
|
16 | 16 | final class GenerateComponentRequestBodyCommandTest extends TestCase
|
17 | 17 | {
|
18 |
| - public function testRequestBodyGeneration(): void |
| 18 | + public function testRequestBodyGenerationFromObject(): void |
19 | 19 | {
|
20 | 20 | $kernel = new AppKernelTest('test', true);
|
21 | 21 | $application = new Application($kernel);
|
@@ -46,4 +46,58 @@ public function testRequestBodyGeneration(): void
|
46 | 46 | $this->assertArrayHasKey('required', $arrayFromYaml['documentation']['components']['requestBodies']['DummyObject']['content']['application/json']['schema']);
|
47 | 47 | $this->assertArrayHasKey('properties', $arrayFromYaml['documentation']['components']['requestBodies']['DummyObject']['content']['application/json']['schema']);
|
48 | 48 | }
|
| 49 | + |
| 50 | + public function testRequestBodyGenerationFromType(): void |
| 51 | + { |
| 52 | + $kernel = new AppKernelTest('test', true); |
| 53 | + $application = new Application($kernel); |
| 54 | + $kernel->boot(); |
| 55 | + |
| 56 | + $command = $application->find('apidocbundle:component:body'); |
| 57 | + $commandTester = new CommandTester($command); |
| 58 | + $commandTester->execute([ |
| 59 | + 'class' => 'Ehyiah\\ApiDocBundle\\Tests\\Dummy\\DummyType', |
| 60 | + ]); |
| 61 | + |
| 62 | + $commandTester->assertCommandIsSuccessful(); |
| 63 | + |
| 64 | + $output = $commandTester->getDisplay(); |
| 65 | + $this->assertStringContainsString('File generated', $output); |
| 66 | + |
| 67 | + $filePath = $kernel->getProjectDir() . '/var/Swagger/requestBodies/DummyType.yaml'; |
| 68 | + $arrayFromYaml = Yaml::parseFile($filePath); |
| 69 | + |
| 70 | + $this->assertIsArray($arrayFromYaml); |
| 71 | + $this->assertArrayHasKey('documentation', $arrayFromYaml); |
| 72 | + $this->assertArrayHasKey('components', $arrayFromYaml['documentation']); |
| 73 | + $this->assertArrayHasKey('requestBodies', $arrayFromYaml['documentation']['components']); |
| 74 | + $this->assertArrayHasKey('DummyType', $arrayFromYaml['documentation']['components']['requestBodies']); |
| 75 | + $this->assertArrayHasKey('required', $arrayFromYaml['documentation']['components']['requestBodies']['DummyType']); |
| 76 | + $this->assertArrayHasKey('content', $arrayFromYaml['documentation']['components']['requestBodies']['DummyType']); |
| 77 | + $this->assertArrayHasKey('application/json', $arrayFromYaml['documentation']['components']['requestBodies']['DummyType']['content']); |
| 78 | + $this->assertArrayHasKey('schema', $arrayFromYaml['documentation']['components']['requestBodies']['DummyType']['content']['application/json']); |
| 79 | + $this->assertArrayHasKey('properties', $arrayFromYaml['documentation']['components']['requestBodies']['DummyType']['content']['application/json']['schema']); |
| 80 | + |
| 81 | + $properties = $arrayFromYaml['documentation']['components']['requestBodies']['DummyType']['content']['application/json']['schema']['properties']; |
| 82 | + $this->assertArrayHasKey('textField', $properties); |
| 83 | + $this->assertEquals('string', $properties['textField']['type']); |
| 84 | + $this->assertArrayHasKey('NumberField', $properties); |
| 85 | + $this->assertEquals('number', $properties['NumberField']['type']); |
| 86 | + $this->assertArrayHasKey('integerField', $properties); |
| 87 | + $this->assertEquals('integer', $properties['integerField']['type']); |
| 88 | + $this->assertArrayHasKey('dateField', $properties); |
| 89 | + $this->assertEquals('string', $properties['dateField']['type']); |
| 90 | + $this->assertEquals('date', $properties['dateField']['format']); |
| 91 | + $this->assertArrayHasKey('datetimeField', $properties); |
| 92 | + $this->assertEquals('string', $properties['datetimeField']['type']); |
| 93 | + $this->assertEquals('date-time', $properties['datetimeField']['format']); |
| 94 | + $this->assertArrayHasKey('choiceMultipleField', $properties); |
| 95 | + $this->assertEquals('array', $properties['choiceMultipleField']['type']); |
| 96 | + $this->assertArrayHasKey('enum', $properties['choiceMultipleField']); |
| 97 | + $this->assertArrayHasKey('choiceNotMultipleField', $properties); |
| 98 | + $this->assertEquals('string', $properties['choiceNotMultipleField']['type']); |
| 99 | + $this->assertArrayHasKey('enum', $properties['choiceNotMultipleField']); |
| 100 | + $this->assertArrayHasKey('collectionField', $properties); |
| 101 | + $this->assertEquals('array', $properties['collectionField']['type']); |
| 102 | + } |
49 | 103 | }
|
0 commit comments