Skip to content

Commit 1d75582

Browse files
committed
Adding a (nearly passing) fjson integration test
1 parent ec00458 commit 1d75582

File tree

8 files changed

+124
-11
lines changed

8 files changed

+124
-11
lines changed

src/BuildResult.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function getMetas(): Metas
5353
/**
5454
* Returns the JSON data generated for each file, keyed by the source filename.
5555
*
56-
* @return string[]
56+
* @return array[]
5757
*/
5858
public function getJsonResults(): array
5959
{

src/Generator/JsonGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function generateJson(): array
7373
$jsonFilename,
7474
json_encode($data, JSON_PRETTY_PRINT)
7575
);
76-
$fJsonFiles[$filename] = json_encode($data, JSON_PRETTY_PRINT);
76+
$fJsonFiles[$filename] = $data;
7777

7878
$progressBar->advance();
7979
}

tests/AbstractIntegrationTest.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,14 @@ class AbstractIntegrationTest extends TestCase
1111
{
1212
protected function createBuildConfig(string $sourceDir): BuildConfig
1313
{
14+
$filesystem = new Filesystem();
15+
$filesystem->remove(__DIR__.'/_output');
16+
1417
return (new BuildConfig())
1518
->setSymfonyVersion('4.0')
1619
->setContentDir($sourceDir)
1720
->disableBuildCache()
1821
->setOutputDir(__DIR__.'/_output')
1922
;
2023
}
21-
22-
/**
23-
* @after
24-
*/
25-
public function cleanUpOutput()
26-
{
27-
$filesystem = new Filesystem();
28-
$filesystem->remove(__DIR__.'/_output');
29-
}
3024
}

tests/JsonIntegrationTest.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Docs Builder package.
5+
* (c) Ryan Weaver <ryan@symfonycasts.com>
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
namespace SymfonyDocsBuilder\Tests;
11+
12+
use SymfonyDocsBuilder\DocBuilder;
13+
14+
class JsonIntegrationTest extends AbstractIntegrationTest
15+
{
16+
/**
17+
* @dataProvider getJsonTests
18+
*/
19+
public function testJsonGeneration(string $filename, array $expectedData)
20+
{
21+
$buildConfig = $this->createBuildConfig(__DIR__ . '/fixtures/source/json');
22+
$builder = new DocBuilder();
23+
$buildResult = $builder->build($buildConfig);
24+
$fJsons = $buildResult->getJsonResults();
25+
26+
$actualFileData = $fJsons[$filename];
27+
foreach ($expectedData as $key => $expectedKeyData) {
28+
$this->assertArrayHasKey($key, $actualFileData, sprintf('Missing key "%s" in file "%s"', $key, $filename));
29+
$this->assertSame($expectedData[$key], $actualFileData[$key], sprintf('Invalid data for key "%s" in file "%s"', $key, $filename));
30+
}
31+
}
32+
33+
public function getJsonTests()
34+
{
35+
yield 'index' => [
36+
'file' => 'index',
37+
'data' => [
38+
//'parents' => [],
39+
'prev' => null,
40+
'next' => [
41+
'link' => 'dashboards/',
42+
'title' => 'Dashboards'
43+
],
44+
'title' => 'JSON Generation Test',
45+
]
46+
];
47+
48+
yield 'dashboards' => [
49+
'file' => 'dashboards',
50+
'data' => [
51+
//'parents' => [],
52+
'prev' => [
53+
'title' => 'JSON Generation Test',
54+
'link' => 'index.html',
55+
],
56+
'next' => [
57+
'title' => 'CRUD',
58+
'link' => 'crud.html',
59+
],
60+
'title' => 'Dashboards',
61+
]
62+
];
63+
64+
yield 'crud' => [
65+
'file' => 'crud',
66+
'data' => [
67+
//'parents' => [],
68+
'prev' => [
69+
'title' => 'Dashboards',
70+
'link' => 'dashboards.html',
71+
],
72+
'next' => [
73+
'title' => 'Design',
74+
'link' => 'design.html',
75+
],
76+
'title' => 'CRUD',
77+
]
78+
];
79+
80+
yield 'design' => [
81+
'file' => 'design',
82+
'data' => [
83+
//'parents' => [],
84+
'prev' => [
85+
'title' => 'CRUD',
86+
'link' => 'crud.html',
87+
],
88+
'next' => null,
89+
'title' => 'Design',
90+
]
91+
];
92+
}
93+
}

tests/fixtures/source/json/crud.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CRUD
2+
====
3+
4+
CRUD stands for: "create, read, update, delete".
5+
6+
Or it might be: "Crazy runner's utter delight" (which would
7+
be, of course, a warm spring morning).
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Dashboards
2+
==========
3+
4+
A file about dashboards... probably the one in an admin area... but
5+
maybe also the ones found in a car!

tests/fixtures/source/json/design.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Design
2+
======
3+
4+
Something that should not be left to most programmers
5+
to try to do.

tests/fixtures/source/json/index.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
JSON Generation Test
2+
====================
3+
4+
.. toctree::
5+
:maxdepth: 1
6+
7+
dashboards
8+
crud
9+
design

0 commit comments

Comments
 (0)