Skip to content

Commit

Permalink
WIP fixing windows build, #90
Browse files Browse the repository at this point in the history
  • Loading branch information
cebe committed Dec 23, 2020
1 parent f77a472 commit 97f6b7a
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions tests/spec/ReferenceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,20 @@ public function testResolveCyclicReferenceInDocument()
$this->assertSame($openapi->components->examples['frog-example'], $refExample);
}

public function testResolveFile()
private function createFileUri($file)
{
$file = __DIR__ . '/data/reference/base.yaml';
if (stripos(PHP_OS, 'WIN') === 0) {
$yaml = str_replace('##ABSOLUTEPATH##', 'file:///' . strtr(dirname($file), [' ' => '%20', '\\' => '/']), file_get_contents($file));
throw new \Exception($yaml);
return 'file:///' . strtr($file, [' ' => '%20', '\\' => '/']);
} else {
$yaml = str_replace('##ABSOLUTEPATH##', 'file://' . dirname($file), file_get_contents($file));
return 'file://' . $file;
}
}

public function testResolveFile()
{
$file = __DIR__ . '/data/reference/base.yaml';
$yaml = str_replace('##ABSOLUTEPATH##', $this->createFileUri(dirname($file)), file_get_contents($file));

/** @var $openapi OpenApi */
$openapi = Reader::readFromYaml($yaml);

Expand Down Expand Up @@ -296,7 +301,7 @@ enum:

YAML;
$openapi = Reader::readFromYaml($schema);
$openapi->resolveReferences(new \cebe\openapi\ReferenceContext($openapi, 'file://' . __DIR__ . '/data/reference/definitions.yaml'));
$openapi->resolveReferences(new \cebe\openapi\ReferenceContext($openapi, $this->createFileUri(__DIR__ . '/data/reference/definitions.yaml')));

$this->assertTrue(isset($openapi->components->schemas['Pet']));
$this->assertEquals(['One', 'Two'], $openapi->components->schemas['Pet']->properties['typeA']->enum);
Expand Down Expand Up @@ -377,7 +382,7 @@ public function testTransitiveReferenceToFile()
YAML;

$openapi = Reader::readFromYaml($schema);
$openapi->resolveReferences(new \cebe\openapi\ReferenceContext($openapi, 'file://' . __DIR__ . '/data/reference/definitions.yaml'));
$openapi->resolveReferences(new \cebe\openapi\ReferenceContext($openapi, $this->createFileUri(__DIR__ . '/data/reference/definitions.yaml')));

$this->assertTrue(isset($openapi->components->schemas['Dog']));
$this->assertEquals('object', $openapi->components->schemas['Dog']->type);
Expand Down

0 comments on commit 97f6b7a

Please sign in to comment.