10000 [FrameworkBundle] Fix exit codes in debug:translation command by gndk · Pull Request #45787 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[FrameworkBundle] Fix exit codes in debug:translation command #45787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$locale = $input->getArgument('locale');
$domain = $input->getOption('domain');

$exitCode = 0;
$exitCode = self::SUCCESS;

/** @var KernelInterface $kernel */
$kernel = $this->getApplication()->getKernel();
Expand Down Expand Up @@ -219,16 +219,21 @@ protected function execute(InputInterface $input, OutputInterface $output): int
if (!$currentCatalogue->defines($messageId, $domain)) {
$states[] = self::MESSAGE_MISSING;

$exitCode = $exitCode | self::EXIT_CODE_MISSING;
if (!$input->getOption('only-unused')) {
$exitCode = $exitCode | self::EXIT_CODE_MISSING;
}
}
} elseif ($currentCatalogue->defines($messageId, $domain)) {
$states[] = self::MESSAGE_UNUSED;

$exitCode = $exitCode | self::EXIT_CODE_UNUSED;
if (!$input->getOption('only-missing')) {
$exitCode = $exitCode | self::EXIT_CODE_UNUSED;
}
}

if (!\in_array(self::MESSAGE_UNUSED, $states) && true === $input->getOption('only-unused')
|| !\in_array(self::MESSAGE_MISSING, $states) && true === $input->getOption('only-missing')) {
if (!\in_array(self::MESSAGE_UNUSED, $states) && $input->getOption('only-unused')
|| !\in_array(self::MESSAGE_MISSING, $states) && $input->getOption('only-missing')
) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Bundle\FrameworkBundle\Command\TranslationDebugCommand;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\FrameworkBundle\Tests\Functional\Bundle\ExtensionWithoutConfigTestBundle\ExtensionWithoutConfigTestBundle;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandCompletionTester;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\Container;
Expand All @@ -36,7 +37,7 @@ public function testDebugMissingMessages()
$res = $tester->execute(['locale' => 'en', 'bundle' => 'foo']);

$this->assertMatchesRegularExpression('/missing/', $tester->getDisplay());
$this->assertEquals(TranslationDebugCommand::EXIT_CODE_MISSING, $res);
$this->assertSame(TranslationDebugCommand::EXIT_CODE_MISSING, $res);
}

public function testDebugUnusedMessages()
Expand All @@ -45,7 +46,7 @@ public function testDebugUnusedMessages()
$res = $tester->execute(['locale' => 'en', 'bundle' => 'foo']);

$this->assertMatchesRegularExpression('/unused/', $tester->getDisplay());
$this->assertEquals(TranslationDebugCommand::EXIT_CODE_UNUSED, $res);
$this->assertSame(TranslationDebugCommand::EXIT_CODE_UNUSED, $res);
}

public function testDebugFallbackMessages()
Expand All @@ -54,7 +55,7 @@ public function testDebugFallbackMessages()
$res = $tester->execute(['locale' => 'fr', 'bundle' => 'foo']);

$this->assertMatchesRegularExpression('/fallback/', $tester->getDisplay());
$this->assertEquals(TranslationDebugCommand::EXIT_CODE_FALLBACK, $res);
$this->assertSame(TranslationDebugCommand::EXIT_CODE_FALLBACK, $res);
}

public function testNoDefinedMessages()
Expand All @@ -63,7 +64,7 @@ public function testNoDefinedMessages()
$res = $tester->execute(['locale' => 'fr', 'bundle' => 'test']);

$this->assertMatchesRegularExpression('/No defined or extracted messages for locale "fr"/', $tester->getDisplay());
$this->assertEquals(TranslationDebugCommand::EXIT_CODE_GENERAL_ERROR, $res);
$this->assertSame(TranslationDebugCommand::EXIT_CODE_GENERAL_ERROR, $res);
}

public function testDebugDefaultDirectory()
Expand All @@ -74,7 +75,7 @@ public function testDebugDefaultDirectory()

$this->assertMatchesRegularExpression('/missing/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/unused/', $tester->getDisplay());
$this->assertEquals($expectedExitStatus, $res);
$this->assertSame($expectedExitStatus, $res);
}

public function testDebugDefaultRootDirectory()
Expand All @@ -92,7 +93,7 @@ public function testDebugDefaultRootDirectory()

$this->assertMatchesRegularExpression('/missing/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/unused/', $tester->getDisplay());
$this->assertEquals($expectedExitStatus, $res);
$this->assertSame($expectedExitStatus, $res);
}

public function testDebugCustomDirectory()
Expand All @@ -112,7 +113,7 @@ public function testDebugCustomDirectory()

$this->assertMatchesRegularExpression('/missing/', $tester->getDisplay());
$this->assertMatchesRegularExpression('/unused/', $tester->getDisplay());
$this->assertEquals($expectedExitStatus, $res);
$this->assertSame($expectedExitStatus, $res);
}

public function testDebugInvalidDirectory()
Expand All @@ -128,6 +129,22 @@ public function testDebugInvalidDirectory()
$tester->execute(['locale' => 'en', 'bundle' => 'dir']);
}

public function testNoErrorWithOnlyMissingOptionAndNoResults()
{
$tester = $this->createCommandTester([], ['foo' => 'foo']);
$res = $tester->execute(['locale' => 'en', '--only-missing' => true]);

$this->assertSame(Command::SUCCESS, $res);
}

public function testNoErrorWithOnlyUnusedOptionAndNoResults()
{
$tester = $this->createCommandTester(['foo' => 'foo']);
$res = $tester->execute(['locale' => 'en', '--only-unused' => true]);

$this->assertSame(Command::SUCCESS, $res);
}

protected function setUp(): void
{
$this->fs = new Filesystem();
Expand Down
0