From 837eef45c2a114bcd572f7f22341a3f0bf1f6625 Mon Sep 17 00:00:00 2001 From: Philippe Damen Date: Tue, 13 Feb 2024 08:57:04 +0100 Subject: [PATCH] fix sorting in statuscommand + improve tests --- src/Commands/StatusCommand.php | 5 +++-- tests/StatusCommandTest.php | 14 +++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/Commands/StatusCommand.php b/src/Commands/StatusCommand.php index 7344bfb..3bd493e 100644 --- a/src/Commands/StatusCommand.php +++ b/src/Commands/StatusCommand.php @@ -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; @@ -37,6 +37,7 @@ public function handle() : int ['Translation Key'], $outdatedLocalTranslations->merge($outdatedPoeditorTranslations) ->keys() + ->unique() ->map(fn ($key) => [$key]) ->all() ); diff --git a/tests/StatusCommandTest.php b/tests/StatusCommandTest.php index 1096176..e167e45 100644 --- a/tests/StatusCommandTest.php +++ b/tests/StatusCommandTest.php @@ -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 */ @@ -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); } }