Skip to content

Commit

Permalink
Fix #28 for syncing missing nested fields
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid committed Apr 17, 2016
1 parent 08d487e commit 3089558
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Commands/SyncCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ private function fillMissingKeys(array $keys, $fileName, array $fileContent, $la
{
$missingKeys = [];

foreach (array_diff($keys, array_keys($fileContent)) as $missingKey) {
foreach (array_diff($keys, array_keys(array_dot($fileContent))) as $missingKey) {
$missingKeys[$missingKey] = [$languageKey => ''];

$this->output->writeln("\"<fg=yellow>{$fileName}.{$missingKey}.{$languageKey}</>\" was added.");
Expand Down
33 changes: 28 additions & 5 deletions tests/SyncCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,34 @@ public function testCommandOutputForFile()
array_map('unlink', glob(__DIR__.'/views_temp/user/index.blade.php'));
array_map('rmdir', glob(__DIR__.'/views_temp/user'));
array_map('unlink', glob(__DIR__.'/views_temp/user.blade.php'));
}

public function testCommandOutputForMissingSubKey()
{
array_map('unlink', glob(__DIR__.'/views_temp/user/index.blade.php'));
array_map('rmdir', glob(__DIR__.'/views_temp/user'));
array_map('unlink', glob(__DIR__.'/views_temp/user.blade.php'));

file_put_contents(__DIR__.'/views_temp/user.blade.php', '{{ trans(\'user.name.first\') }}');
mkdir(__DIR__.'/views_temp/user');
file_put_contents(__DIR__.'/views_temp/user/index.blade.php', "{{ trans('user.name.last') }}");

$this->createTempFiles([
'en' => ['user' => "<?php\n return ['name' => ['middle' => 'middle', 'first' => 'old_value']];"],
]);

$this->artisan('langman:sync');

$userENFile = (array) include $this->app['config']['langman.path'].'/en/user.php';

array_map('unlink', glob(__DIR__.'/app_temp/Http/Controllers/testController.php'));
array_map('unlink', glob(__DIR__.'/app_temp/Jobs/testJob.php'));
array_map('rmdir', glob(__DIR__.'/app_temp/Http/Controllers'));
array_map('rmdir', glob(__DIR__.'/app_temp/Http'));
array_map('rmdir', glob(__DIR__.'/app_temp/Jobs'));
$this->assertArrayHasKey('name', $userENFile);
$this->assertArrayHasKey('first', $userENFile['name']);
$this->assertEquals('old_value', $userENFile['name']['first']);
$this->assertArrayHasKey('last', $userENFile['name']);
$this->assertArrayHasKey('middle', $userENFile['name']);

array_map('unlink', glob(__DIR__.'/views_temp/user/index.blade.php'));
array_map('rmdir', glob(__DIR__.'/views_temp/user'));
array_map('unlink', glob(__DIR__.'/views_temp/user.blade.php'));
}
}

0 comments on commit 3089558

Please sign in to comment.