|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | use cebe\openapi\Reader; |
| 4 | +use cebe\openapi\spec\OpenApi; |
| 5 | +use cebe\openapi\spec\SecurityRequirements; |
| 6 | +use cebe\openapi\Writer; |
4 | 7 |
|
5 | 8 | // https://github.com/cebe/php-openapi/issues/238 |
6 | 9 | class Issue238Test extends \PHPUnit\Framework\TestCase |
7 | 10 | { |
8 | | - public function test238AddSupportForEmptySecurityRequirementObjectInSecurityRequirement() |
| 11 | + public function test238AddSupportForEmptySecurityRequirementObjectInSecurityRequirementRead() |
9 | 12 | { |
10 | 13 | $openapi = Reader::readFromYamlFile(dirname(dirname(__DIR__)).'/data/issue/238/spec.yml'); |
11 | 14 | $this->assertInstanceOf(\cebe\openapi\SpecObjectInterface::class, $openapi); |
12 | 15 | $this->assertInstanceOf(\cebe\openapi\spec\SecurityRequirements::class, $openapi->paths->getPath('/path-secured')->getOperations()['get']->security); |
13 | | - $this->assertSame($openapi->paths->getPath('/path-secured')->getOperations()['get']->security->getSerializableData(), [[]]); |
| 16 | + $this->assertSame(json_decode(json_encode($openapi->paths->getPath('/path-secured')->getOperations()['get']->security->getSerializableData()), true), [[]]); |
14 | 17 |
|
15 | 18 | // return; # TODO |
16 | 19 | // $openapi = Reader::readFromJsonFile(__DIR__.'/data/issue/238/spec.json'); |
17 | 20 | // $this->assertInstanceOf(\cebe\openapi\SpecObjectInterface::class, $openapi); |
18 | 21 | } |
| 22 | + |
| 23 | + public function test238AddSupportForEmptySecurityRequirementObjectInSecurityRequirementWrite() |
| 24 | + { |
| 25 | + $openapi = $this->createOpenAPI([ |
| 26 | + 'security' => new SecurityRequirements([ |
| 27 | + [] |
| 28 | + ]), |
| 29 | + ]); |
| 30 | + |
| 31 | + $yaml = Writer::writeToYaml($openapi); |
| 32 | + |
| 33 | + $this->assertEquals(preg_replace('~\R~', "\n", <<<YAML |
| 34 | +openapi: 3.0.0 |
| 35 | +info: |
| 36 | + title: 'Test API' |
| 37 | + version: 1.0.0 |
| 38 | +paths: { } |
| 39 | +security: |
| 40 | + - { } |
| 41 | +
|
| 42 | +YAML |
| 43 | + ), |
| 44 | + $yaml |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + private function createOpenAPI($merge = []) |
| 49 | + { |
| 50 | + return new OpenApi(array_merge([ |
| 51 | + 'openapi' => '3.0.0', |
| 52 | + 'info' => [ |
| 53 | + 'title' => 'Test API', |
| 54 | + 'version' => '1.0.0', |
| 55 | + ], |
| 56 | + 'paths' => [], |
| 57 | + ], $merge)); |
| 58 | + } |
19 | 59 | } |
0 commit comments