Skip to content

Commit

Permalink
fix sorting in statuscommand + improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe Damen committed Feb 13, 2024
1 parent 54236f9 commit 837eef4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/Commands/StatusCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public function handle() : int
return collect($locale)->map(function ($internalLocale) use ($poeditorTranslations) {
$localTranslations = app(TranslationManager::class)->getTranslations($internalLocale);

$poeditorTranslations = collect($poeditorTranslations)->dot()->sort();
$localTranslations = collect($localTranslations)->dot()->sort();
$poeditorTranslations = collect($poeditorTranslations)->dot()->sortKeys();
$localTranslations = collect($localTranslations)->dot()->sortKeys();

if ($poeditorTranslations->toArray() === $localTranslations->toArray()) {
return true;
Expand All @@ -37,6 +37,7 @@ public function handle() : int
['Translation Key'],
$outdatedLocalTranslations->merge($outdatedPoeditorTranslations)
->keys()
->unique()
->map(fn ($key) => [$key])
->all()
);
Expand Down
14 changes: 11 additions & 3 deletions tests/StatusCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,16 @@ public function it_does_not_fail_if_translations_in_different_order()

$this->mockPoeditorDownload('en', [
'php-file' => [
'bar' => 'baz',
'baz' => 'bar',
'foo' => 'bar',
],
]);

$this->artisan('poeditor:status')
->expectsOutput('The translations for \'en\' do not match the ones on POEditor.')
->expectsOutput('All translations match the ones on POEditor!')
->doesntExpectOutput('The translations for \'en\' do not match the ones on POEditor.')
->doesntExpectOutput('The translations for \'nl\' do not match the ones on POEditor.')
->assertExitCode(1);
->assertExitCode(0);
}

/** @test */
Expand All @@ -100,5 +101,12 @@ public function it_fails_if_translations_do_not_match()
['php-file.nested.value'],
])
->assertExitCode(1);

$this->createPhpTranslationFile('en/php-file.php', ['foo' => 'bar', 'nested' => ['value' => 'nested values']]);

$this->artisan('poeditor:status')
->expectsOutput('All translations match the ones on POEditor!')
->doesntExpectOutput('The translations for \'en\' do not match the ones on POEditor.')
->assertExitCode(0);
}
}

0 comments on commit 837eef4

Please sign in to comment.