Skip to content

Commit

Permalink
Generate static file with specification (#10)
Browse files Browse the repository at this point in the history
* Generate static file with specification

* Fix code style

* Fix phpstan errors

* Tests

Co-authored-by: Yevgeniy Vaskevich <[email protected]>
  • Loading branch information
wbrframe and Yevgeniy Vaskevich authored Aug 24, 2022
1 parent bdad46b commit 0dd2b50
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Generator/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,13 @@ public function generate(): void
);

$filePath = $this->docsFolder.'index.html';
$filePathSpecification = $this->docsFolder.'specification.json';

$fs = new Filesystem();
$fs->dumpFile($filePath, $docs);

/** @var string $swaggerConfigAsJson */
$swaggerConfigAsJson = json_encode($swaggerConfig, \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES | \JSON_PRETTY_PRINT | \JSON_THROW_ON_ERROR);
$fs->dumpFile($filePathSpecification, $swaggerConfigAsJson);
}
}
12 changes: 11 additions & 1 deletion Tests/Generator/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ final class GeneratorTest extends TestCase
private string $docsFolder = __DIR__.'/Fixtures/';

private string $docsFile = __DIR__.'/Fixtures/index.html';
private string $specificationFile = __DIR__.'/Fixtures/specification.json';

/** @var Environment|MockObject */
private Environment|MockObject $twig;
Expand All @@ -41,6 +42,7 @@ protected function setUp(): void
$this->parser = $this->createMock(ConfigParser::class);
$this->filesystem = new Filesystem();
$this->filesystem->dumpFile($this->docsFile, '');
$this->filesystem->dumpFile($this->specificationFile, '');

$this->generator = new Generator($this->twig, $this->parser, $this->docsFolder);
}
Expand All @@ -54,11 +56,12 @@ protected function tearDown(): void
);

$this->filesystem->remove($this->docsFile);
$this->filesystem->remove($this->specificationFile);
}

public function testGenerate(): void
{
$swaggerConfig = ['open api config'];
$swaggerConfig = ['open api config' => 'value'];

$this->parser
->expects(self::once())
Expand All @@ -76,6 +79,13 @@ public function testGenerate(): void

$this->generator->generate();

$swaggerConfigAsJson = <<<'EOT'
{
"open api config": "value"
}
EOT;

self::assertStringEqualsFile($this->docsFolder.'index.html', $docs);
self::assertStringEqualsFile($this->docsFolder.'specification.json', $swaggerConfigAsJson);
}
}

0 comments on commit 0dd2b50

Please sign in to comment.