Skip to content

Commit 78c4131

Browse files
committed
Multiple file output tests
1 parent 343b6c0 commit 78c4131

File tree

12 files changed

+1229
-426
lines changed

12 files changed

+1229
-426
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"illuminate/support": "~5.1.0|~5.2.0|~5.3.0|~5.4.0|~5.5.0|~5.6.0|~5.7.0|~5.8.0|~6.0|~7.0"
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "~4.7"
21+
"phpunit/phpunit": "~4.7",
22+
"orchestra/testbench": "3.1.*"
2223
},
2324
"autoload": {
2425
"psr-4": {

composer.lock

Lines changed: 1100 additions & 416 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/MultiFileGeneratorTest.php

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,79 @@
22

33
use MartinLindhe\VueInternationalizationGenerator\Generator;
44

5-
class MultiFileGeneratorTest extends \PHPUnit_Framework_TestCase
5+
6+
class MultiFileGeneratorTest extends \Orchestra\Testbench\TestCase
67
{
78
private $config = [];
89

9-
private function evaluateMultiOutput($input, $expected, $format = 'es6', $withVendor = false)
10+
protected function getEnvironmentSetUp($app)
11+
{
12+
$app->setBasePath(realpath(__DIR__ . '/..'));
13+
}
14+
15+
private function genOutDir()
16+
{
17+
return '/tests/output/' . sha1(microtime(true) . mt_rand()) . '/';
18+
}
19+
20+
private function destroyTempFiles($dir)
21+
{
22+
$files = new RecursiveIteratorIterator(
23+
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
24+
RecursiveIteratorIterator::CHILD_FIRST
25+
);
26+
27+
foreach ($files as $fileinfo) {
28+
$todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
29+
$todo($fileinfo->getRealPath());
30+
}
31+
32+
rmdir($dir);
33+
}
34+
35+
private function evaluateMultiOutput($input, $expected, $format = 'es6', $multiLocales = false)
1036
{
11-
$this->assertEquals(
12-
file_get_contents(__DIR__ . '/result/' . $expected),
13-
(new Generator($this->config))->generateMultiple(__DIR__ . '/input/' . $input, $format, $withVendor));
37+
$this->config['jsPath'] = $this->genOutDir();
38+
$outDir = base_path() . $this->config['jsPath'];
39+
$this->config['langPath'] = '/tests/input/' . $input;
1440

41+
$out = (new Generator($this->config))->generateMultiple(__DIR__ . '/input/' . $input, 'es6', $multiLocales);
42+
$this->config = [];
43+
44+
$expected = new RecursiveDirectoryIterator(base_path() . '/tests/result/' . $expected, FilesystemIterator::SKIP_DOTS);
45+
46+
$expectedFiles = [];
47+
48+
foreach($expected as $path => $file) {
49+
$resultFile = $outDir . $file->getFilename();
50+
$expectedFiles[] = $resultFile . PHP_EOL;
51+
$this->assertEquals(
52+
file_get_contents($path),
53+
file_get_contents($resultFile),
54+
"File $resultFile doesn't match expected $path."
55+
);
56+
}
57+
asort($expectedFiles); // RDI is unordered
58+
$this->assertEquals(implode($expectedFiles), $out);
59+
60+
$this->destroyTempFiles($outDir);
1561
$this->config = [];
1662
}
1763

1864
public function testBasic()
1965
{
20-
$input = 'basic';
21-
$out = (new Generator($this->config))->generateMultiple(__DIR__ . '/input/' . $input);
22-
dd($out);
66+
$this->evaluateMultiOutput('basic', 'basic');
67+
}
68+
69+
public function testBasicMulti()
70+
{
71+
// FIXME code skips json files
72+
$this->evaluateMultiOutput('multiple', 'multi_file');
73+
}
74+
75+
public function testMultiLocale()
76+
{
77+
// FIXME code skips json files
78+
$this->evaluateMultiOutput('multiple', 'multi_locale', 'es6', true);
2379
}
2480
}

tests/SingleFileGeneratorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use MartinLindhe\VueInternationalizationGenerator\Generator;
44

5-
class SingleFileGeneratorTest extends \PHPUnit_Framework_TestCase
5+
class SingleFileGeneratorTest extends \Orchestra\Testbench\TestCase
66
{
77
private $config = [];
88

tests/input/multiple/sv.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"Documentation": "Dokumentation"
3+
}

tests/output/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Ignore everything in this directory
2+
*
3+
# Except this file
4+
!.gitignore

tests/result/basic/help.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
"en": {
3+
"yes": "yes",
4+
"no": "no"
5+
},
6+
"sv": {
7+
"yes": "ja",
8+
"no": "nej"
9+
}
10+
}

tests/result/basic_multi_in.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default {
1010
}
1111
},
1212
"sv": {
13+
"Documentation": "Dokumentation",
1314
"help": {
1415
"yes": "ja",
1516
"no": "nej"

tests/result/multi_file/help.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
"en": {
3+
"yes": "yes",
4+
"no": "no"
5+
},
6+
"sv": {
7+
"yes": "ja",
8+
"no": "nej"
9+
}
10+
}

tests/result/multi_file/main.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default {
2+
"en": {
3+
"up": "up",
4+
"down": "down"
5+
},
6+
"sv": {
7+
"up": "upp",
8+
"down": "ner"
9+
}
10+
}

0 commit comments

Comments
 (0)