@@ -40,7 +40,7 @@ public function itMustHaveAnArrayContainingOnlyOpenAPIVersions(): void
4040 #[Test]
4141 public function itCannotReadFilesItCannotFind (): void
4242 {
43- $ filePath = vfsStream::setup ()->url () . '/open-api ' ;
43+ $ filePath = vfsStream::setup ()->url () . '/openapi ' ;
4444
4545 self ::assertFalse (file_exists ($ filePath ));
4646
@@ -72,7 +72,21 @@ public static function provideMinimalOpenAPIAsArray(): Generator
7272
7373 #[Test]
7474 #[DataProvider('provideMinimalOpenAPIAsArray ' )]
75- public function itCannotSupportUnspecifiedOpenAPIVersions (array $ openAPIArray ): void
75+ public function itCannotSupportUnspecifiedOpenAPIVersionsFromAbsoluteFilePath (array $ openAPIArray ): void
76+ {
77+
78+ $ filePath = vfsStream::setup ()->url () . '/openapi ' ;
79+ file_put_contents ($ filePath , json_encode ($ openAPIArray ));
80+
81+ self ::expectExceptionObject (CannotSupport::unsupportedVersion ($ openAPIArray ['openapi ' ]));
82+
83+ (new Reader ([OpenAPIVersion::Version_3_1]))
84+ ->readFromAbsoluteFilePath ($ filePath , FileFormat::Json);
85+ }
86+
87+ #[Test]
88+ #[DataProvider('provideMinimalOpenAPIAsArray ' )]
89+ public function itCannotSupportUnspecifiedOpenAPIVersionsFromString (array $ openAPIArray ): void
7690 {
7791 self ::expectExceptionObject (CannotSupport::unsupportedVersion ($ openAPIArray ['openapi ' ]));
7892
@@ -82,7 +96,20 @@ public function itCannotSupportUnspecifiedOpenAPIVersions(array $openAPIArray):
8296
8397 #[Test]
8498 #[DataProvider('provideMinimalOpenAPIAsArray ' )]
85- public function itCanSupportSpecifiedOpenAPIVersions (array $ openAPIArray ): void
99+ public function itCanSupportSpecifiedOpenAPIVersionsFromAbsoluteFilePath (array $ openAPIArray ): void
100+ {
101+ $ filePath = vfsStream::setup ()->url () . '/openapi ' ;
102+ file_put_contents ($ filePath , json_encode ($ openAPIArray ));
103+
104+ $ openAPIObject = (new Reader ([OpenAPIVersion::Version_3_0]))
105+ ->readFromAbsoluteFilePath ($ filePath , FileFormat::Json);
106+
107+ self ::assertInstanceOf (CebeSpec \OpenApi::class, $ openAPIObject );
108+ }
109+
110+ #[Test]
111+ #[DataProvider('provideMinimalOpenAPIAsArray ' )]
112+ public function itCanSupportSpecifiedOpenAPIVersionsFromString (array $ openAPIArray ): void
86113 {
87114 $ openAPIObject = (new Reader ([OpenAPIVersion::Version_3_0]))
88115 ->readFromString (json_encode ($ openAPIArray ), FileFormat::Json);
@@ -107,6 +134,10 @@ public static function provideInvalidFormatting(): Generator
107134 yield 'Empty string to be interpreted as yaml ' => ['' , FileFormat::Yaml];
108135 yield 'Invalid json format ' => ['{openapi: ", ' , FileFormat::Json];
109136 yield 'Invalid yaml format ' => ['---openapi: ",- title: "invalid" ' , FileFormat::Yaml];
137+ yield 'info is a string rather than an array ' => [
138+ json_encode (['openapi ' => '3.0.0 ' , 'info ' => 'hold on what is this? ' , 'paths ' => []]),
139+ FileFormat::Json
140+ ];
110141 }
111142
112143 #[Test]
@@ -179,7 +210,22 @@ public static function provideInvalidOpenAPIs(): Generator
179210
180211 #[Test]
181212 #[DataProvider('provideInvalidOpenAPIs ' )]
182- public function itWillNotProcessInvalidOpenAPI (string $ openAPIString , InvalidOpenAPI $ expectedException ): void
213+ public function itWillNotProcessInvalidOpenAPIFromAbsoluteFilePath (
214+ string $ openAPIString ,
215+ InvalidOpenAPI $ expectedException
216+ ): void {
217+ $ filePath = vfsStream::setup ()->url () . '/openapi.json ' ;
218+ file_put_contents ($ filePath , $ openAPIString );
219+
220+ self ::expectExceptionObject ($ expectedException );
221+
222+ (new Reader ([OpenAPIVersion::Version_3_0]))
223+ ->readFromAbsoluteFilePath ($ filePath , FileFormat::Json);
224+ }
225+
226+ #[Test]
227+ #[DataProvider('provideInvalidOpenAPIs ' )]
228+ public function itWillNotProcessInvalidOpenAPIFromString (string $ openAPIString , InvalidOpenAPI $ expectedException ): void
183229 {
184230 self ::expectExceptionObject ($ expectedException );
185231
0 commit comments