Skip to content

Commit d0c8227

Browse files
committed
Add tests for JSON read + write
1 parent 864fb05 commit d0c8227

File tree

1 file changed

+81
-3
lines changed

1 file changed

+81
-3
lines changed

tests/issues/238/Issue238Test.php

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,62 @@ public function test238AddSupportForEmptySecurityRequirementObjectInSecurityRequ
1515
$this->assertInstanceOf(\cebe\openapi\spec\SecurityRequirements::class, $openapi->paths->getPath('/path-secured')->getOperations()['get']->security);
1616
$this->assertSame(json_decode(json_encode($openapi->paths->getPath('/path-secured')->getOperations()['get']->security->getSerializableData()), true), [[]]);
1717

18-
// return; # TODO
19-
// $openapi = Reader::readFromJsonFile(__DIR__.'/data/issue/238/spec.json');
20-
// $this->assertInstanceOf(\cebe\openapi\SpecObjectInterface::class, $openapi);
18+
$openapiJson = Reader::readFromJson(<<<JSON
19+
{
20+
"openapi": "3.0.0",
21+
"info": {
22+
"title": "Secured API",
23+
"version": "1.0.0"
24+
},
25+
"paths": {
26+
"/global-secured": {
27+
"get": {
28+
"responses": {
29+
"200": {
30+
"description": "OK"
31+
}
32+
}
33+
}
34+
},
35+
"/path-secured": {
36+
"get": {
37+
"security": [
38+
{}
39+
],
40+
"responses": {
41+
"200": {
42+
"description": "OK"
43+
}
44+
}
45+
}
46+
}
47+
},
48+
"components": {
49+
"securitySchemes": {
50+
"ApiKeyAuth": {
51+
"type": "apiKey",
52+
"in": "header",
53+
"name": "X-API-Key"
54+
},
55+
"BearerAuth": {
56+
"type": "http",
57+
"scheme": "bearer"
58+
}
59+
}
60+
},
61+
"security": [
62+
{
63+
"ApiKeyAuth": []
64+
}
65+
]
66+
}
67+
68+
JSON
69+
);
70+
71+
$this->assertInstanceOf(\cebe\openapi\SpecObjectInterface::class, $openapiJson);
72+
$this->assertInstanceOf(\cebe\openapi\spec\SecurityRequirements::class, $openapiJson->paths->getPath('/path-secured')->getOperations()['get']->security);
73+
$this->assertSame(json_decode(json_encode($openapiJson->paths->getPath('/path-secured')->getOperations()['get']->security->getSerializableData()), true), [[]]);
2174
}
2275

2376
public function test238AddSupportForEmptySecurityRequirementObjectInSecurityRequirementWrite()
@@ -43,6 +96,31 @@ public function test238AddSupportForEmptySecurityRequirementObjectInSecurityRequ
4396
),
4497
$yaml
4598
);
99+
100+
$openapiJson = $this->createOpenAPI([
101+
'security' => new SecurityRequirements([
102+
[]
103+
]),
104+
]);
105+
106+
$json = Writer::writeToJson($openapiJson);
107+
108+
$this->assertEquals(preg_replace('~\R~', "\n", <<<JSON
109+
{
110+
"openapi": "3.0.0",
111+
"info": {
112+
"title": "Test API",
113+
"version": "1.0.0"
114+
},
115+
"paths": {},
116+
"security": [
117+
{}
118+
]
119+
}
120+
JSON
121+
),
122+
$json
123+
);
46124
}
47125

48126
private function createOpenAPI($merge = [])

0 commit comments

Comments
 (0)