22
33use 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}
0 commit comments