Skip to content

Commit 3089558

Browse files
committed
Fix #28 for syncing missing nested fields
1 parent 08d487e commit 3089558

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/Commands/SyncCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private function fillMissingKeys(array $keys, $fileName, array $fileContent, $la
8181
{
8282
$missingKeys = [];
8383

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

8787
$this->output->writeln("\"<fg=yellow>{$fileName}.{$missingKey}.{$languageKey}</>\" was added.");

tests/SyncCommandTest.php

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,34 @@ public function testCommandOutputForFile()
3434
array_map('unlink', glob(__DIR__.'/views_temp/user/index.blade.php'));
3535
array_map('rmdir', glob(__DIR__.'/views_temp/user'));
3636
array_map('unlink', glob(__DIR__.'/views_temp/user.blade.php'));
37+
}
38+
39+
public function testCommandOutputForMissingSubKey()
40+
{
41+
array_map('unlink', glob(__DIR__.'/views_temp/user/index.blade.php'));
42+
array_map('rmdir', glob(__DIR__.'/views_temp/user'));
43+
array_map('unlink', glob(__DIR__.'/views_temp/user.blade.php'));
44+
45+
file_put_contents(__DIR__.'/views_temp/user.blade.php', '{{ trans(\'user.name.first\') }}');
46+
mkdir(__DIR__.'/views_temp/user');
47+
file_put_contents(__DIR__.'/views_temp/user/index.blade.php', "{{ trans('user.name.last') }}");
48+
49+
$this->createTempFiles([
50+
'en' => ['user' => "<?php\n return ['name' => ['middle' => 'middle', 'first' => 'old_value']];"],
51+
]);
52+
53+
$this->artisan('langman:sync');
54+
55+
$userENFile = (array) include $this->app['config']['langman.path'].'/en/user.php';
3756

38-
array_map('unlink', glob(__DIR__.'/app_temp/Http/Controllers/testController.php'));
39-
array_map('unlink', glob(__DIR__.'/app_temp/Jobs/testJob.php'));
40-
array_map('rmdir', glob(__DIR__.'/app_temp/Http/Controllers'));
41-
array_map('rmdir', glob(__DIR__.'/app_temp/Http'));
42-
array_map('rmdir', glob(__DIR__.'/app_temp/Jobs'));
57+
$this->assertArrayHasKey('name', $userENFile);
58+
$this->assertArrayHasKey('first', $userENFile['name']);
59+
$this->assertEquals('old_value', $userENFile['name']['first']);
60+
$this->assertArrayHasKey('last', $userENFile['name']);
61+
$this->assertArrayHasKey('middle', $userENFile['name']);
62+
63+
array_map('unlink', glob(__DIR__.'/views_temp/user/index.blade.php'));
64+
array_map('rmdir', glob(__DIR__.'/views_temp/user'));
65+
array_map('unlink', glob(__DIR__.'/views_temp/user.blade.php'));
4366
}
4467
}

0 commit comments

Comments
 (0)