Skip to content

Commit 0dd2b50

Browse files
wbrframeYevgeniy Vaskevich
andauthored
Generate static file with specification (#10)
* Generate static file with specification * Fix code style * Fix phpstan errors * Tests Co-authored-by: Yevgeniy Vaskevich <evhenii.vaskevych@stfalcon.com>
1 parent bdad46b commit 0dd2b50

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

Generator/Generator.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ public function generate(): void
4545
);
4646

4747
$filePath = $this->docsFolder.'index.html';
48+
$filePathSpecification = $this->docsFolder.'specification.json';
4849

4950
$fs = new Filesystem();
5051
$fs->dumpFile($filePath, $docs);
52+
53+
/** @var string $swaggerConfigAsJson */
54+
$swaggerConfigAsJson = json_encode($swaggerConfig, \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES | \JSON_PRETTY_PRINT | \JSON_THROW_ON_ERROR);
55+
$fs->dumpFile($filePathSpecification, $swaggerConfigAsJson);
5156
}
5257
}

Tests/Generator/GeneratorTest.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ final class GeneratorTest extends TestCase
2424
private string $docsFolder = __DIR__.'/Fixtures/';
2525

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

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

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

5658
$this->filesystem->remove($this->docsFile);
59+
$this->filesystem->remove($this->specificationFile);
5760
}
5861

5962
public function testGenerate(): void
6063
{
61-
$swaggerConfig = ['open api config'];
64+
$swaggerConfig = ['open api config' => 'value'];
6265

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

7780
$this->generator->generate();
7881

82+
$swaggerConfigAsJson = <<<'EOT'
83+
{
84+
"open api config": "value"
85+
}
86+
EOT;
87+
7988
self::assertStringEqualsFile($this->docsFolder.'index.html', $docs);
89+
self::assertStringEqualsFile($this->docsFolder.'specification.json', $swaggerConfigAsJson);
8090
}
8191
}

0 commit comments

Comments
 (0)