@@ -136,15 +136,20 @@ public function testResolveCyclicReferenceInDocument()
136136 $ this ->assertSame ($ openapi ->components ->examples ['frog-example ' ], $ refExample );
137137 }
138138
139- public function testResolveFile ( )
139+ private function createFileUri ( $ file )
140140 {
141- $ file = __DIR__ . '/data/reference/base.yaml ' ;
142141 if (stripos (PHP_OS , 'WIN ' ) === 0 ) {
143- $ yaml = str_replace ('##ABSOLUTEPATH## ' , 'file:/// ' . strtr (dirname ($ file ), [' ' => '%20 ' , '\\' => '/ ' ]), file_get_contents ($ file ));
144- throw new \Exception ($ yaml );
142+ return 'file:/// ' . strtr ($ file , [' ' => '%20 ' , '\\' => '/ ' ]);
145143 } else {
146- $ yaml = str_replace ( ' ##ABSOLUTEPATH## ' , ' file:// ' . dirname ( $ file), file_get_contents ( $ file )) ;
144+ return ' file:// ' . $ file ;
147145 }
146+ }
147+
148+ public function testResolveFile ()
149+ {
150+ $ file = __DIR__ . '/data/reference/base.yaml ' ;
151+ $ yaml = str_replace ('##ABSOLUTEPATH## ' , $ this ->createFileUri (dirname ($ file )), file_get_contents ($ file ));
152+
148153 /** @var $openapi OpenApi */
149154 $ openapi = Reader::readFromYaml ($ yaml );
150155
@@ -296,7 +301,7 @@ enum:
296301
297302YAML;
298303 $ openapi = Reader::readFromYaml ($ schema );
299- $ openapi ->resolveReferences (new \cebe \openapi \ReferenceContext ($ openapi , ' file:// ' . __DIR__ . '/data/reference/definitions.yaml ' ));
304+ $ openapi ->resolveReferences (new \cebe \openapi \ReferenceContext ($ openapi , $ this -> createFileUri ( __DIR__ . '/data/reference/definitions.yaml ' ) ));
300305
301306 $ this ->assertTrue (isset ($ openapi ->components ->schemas ['Pet ' ]));
302307 $ this ->assertEquals (['One ' , 'Two ' ], $ openapi ->components ->schemas ['Pet ' ]->properties ['typeA ' ]->enum );
@@ -377,7 +382,7 @@ public function testTransitiveReferenceToFile()
377382YAML;
378383
379384 $ openapi = Reader::readFromYaml ($ schema );
380- $ openapi ->resolveReferences (new \cebe \openapi \ReferenceContext ($ openapi , ' file:// ' . __DIR__ . '/data/reference/definitions.yaml ' ));
385+ $ openapi ->resolveReferences (new \cebe \openapi \ReferenceContext ($ openapi , $ this -> createFileUri ( __DIR__ . '/data/reference/definitions.yaml ' ) ));
381386
382387 $ this ->assertTrue (isset ($ openapi ->components ->schemas ['Dog ' ]));
383388 $ this ->assertEquals ('object ' , $ openapi ->components ->schemas ['Dog ' ]->type );
0 commit comments