Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3a9f7c3

Browse filesBrowse files
committed
[FrameworkBundle][TranslationDebug] return exit code on failure
1 parent 5d8580b commit 3a9f7c3
Copy full SHA for 3a9f7c3

File tree

2 files changed

+36
-9
lines changed
Filter options

2 files changed

+36
-9
lines changed

‎src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Command/TranslationDebugCommand.php
+16-1Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@
3838
*/
3939
class TranslationDebugCommand extends Command
4040
{
41+
const EXIT_CODE_GENERAL_ERROR = 1;
42+
const EXIT_CODE_MISSING = 2;
43+
const EXIT_CODE_UNUSED = 4;
44+
const EXIT_CODE_FALLBACK = 8;
4145
const MESSAGE_MISSING = 0;
4246
const MESSAGE_UNUSED = 1;
4347
const MESSAGE_EQUALS_FALLBACK = 2;
@@ -123,6 +127,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
123127

124128
$locale = $input->getArgument('locale');
125129
$domain = $input->getOption('domain');
130+
131+
$exitCode = 0;
132+
126133
/** @var KernelInterface $kernel */
127134
$kernel = $this->getApplication()->getKernel();
128135

@@ -189,7 +196,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
189196

190197
$io->getErrorStyle()->warning($outputMessage);
191198

192-
return;
199+
return self::EXIT_CODE_GENERAL_ERROR;
193200
}
194201

195202
// Load the fallback catalogues
@@ -210,9 +217,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
210217
if ($extractedCatalogue->defines($messageId, $domain)) {
211218
if (!$currentCatalogue->defines($messageId, $domain)) {
212219
$states[] = self::MESSAGE_MISSING;
220+
221+
$exitCode = $exitCode | self::EXIT_CODE_MISSING;
213222
}
214223
} elseif ($currentCatalogue->defines($messageId, $domain)) {
215224
$states[] = self::MESSAGE_UNUSED;
225+
226+
$exitCode = $exitCode | self::EXIT_CODE_UNUSED;
216227
}
217228

218229
if (!\in_array(self::MESSAGE_UNUSED, $states) && true === $input->getOption('only-unused')
@@ -224,6 +235,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
224235
if ($fallbackCatalogue->defines($messageId, $domain) && $value === $fallbackCatalogue->get($messageId, $domain)) {
225236
$states[] = self::MESSAGE_EQUALS_FALLBACK;
226237

238+
$exitCode = $exitCode | self::EXIT_CODE_FALLBACK;
239+
227240
break;
228241
}
229242
}
@@ -238,6 +251,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
238251
}
239252

240253
$io->table($headers, $rows);
254+
255+
return $exitCode;
241256
}
242257

243258
private function formatState($state): string

‎src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Bundle/FrameworkBundle/Tests/Command/TranslationDebugCommandTest.php
+20-8Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,48 @@ class TranslationDebugCommandTest extends TestCase
2626
public function testDebugMissingMessages()
2727
{
2828
$tester = $this->createCommandTester(['foo' => 'foo']);
29-
$tester->execute(['locale' => 'en', 'bundle' => 'foo']);
29+
$res = $tester->execute(['locale' => 'en', 'bundle' => 'foo']);
3030

3131
$this->assertRegExp('/missing/', $tester->getDisplay());
32+
$this->assertEquals(TranslationDebugCommand::EXIT_CODE_MISSING, $res);
3233
}
3334

3435
public function testDebugUnusedMessages()
3536
{
3637
$tester = $this->createCommandTester([], ['foo' => 'foo']);
37-
$tester->execute(['locale' => 'en', 'bundle' => 'foo']);
38+
$res = $tester->execute(['locale' => 'en', 'bundle' => 'foo']);
3839

3940
$this->assertRegExp('/unused/', $tester->getDisplay());
41+
$this->assertEquals(TranslationDebugCommand::EXIT_CODE_UNUSED, $res);
4042
}
4143

4244
public function testDebugFallbackMessages()
4345
{
44-
$tester = $this->createCommandTester([], ['foo' => 'foo']);
45-
$tester->execute(['locale' => 'fr', 'bundle' => 'foo']);
46+
$tester = $this->createCommandTester(['foo' => 'foo'], ['foo' => 'foo']);
47+
$res = $tester->execute(['locale' => 'fr', 'bundle' => 'foo']);
4648

4749
$this->assertRegExp('/fallback/', $tester->getDisplay());
50+
$this->assertEquals(TranslationDebugCommand::EXIT_CODE_FALLBACK, $res);
4851
}
4952

5053
public function testNoDefinedMessages()
5154
{
5255
$tester = $this->createCommandTester();
53-
$tester->execute(['locale' => 'fr', 'bundle' => 'test']);
56+
$res = $tester->execute(['locale' => 'fr', 'bundle' => 'test']);
5457

5558
$this->assertRegExp('/No defined or extracted messages for locale "fr"/', $tester->getDisplay());
59+
$this->assertEquals(TranslationDebugCommand::EXIT_CODE_GENERAL_ERROR, $res);
5660
}
5761

5862
public function testDebugDefaultDirectory()
5963
{
6064
$tester = $this->createCommandTester(['foo' => 'foo'], ['bar' => 'bar']);
61-
$tester->execute(['locale' => 'en']);
65+
$res = $tester->execute(['locale' => 'en']);
66+
$expectedExitStatus = TranslationDebugCommand::EXIT_CODE_MISSING | TranslationDebugCommand::EXIT_CODE_UNUSED;
6267

6368
$this->assertRegExp('/missing/', $tester->getDisplay());
6469
$this->assertRegExp('/unused/', $tester->getDisplay());
70+
$this->assertEquals($expectedExitStatus, $res);
6571
}
6672

6773
public function testDebugDefaultRootDirectory()
@@ -72,11 +78,14 @@ public function testDebugDefaultRootDirectory()
7278
$this->fs->mkdir($this->translationDir.'/translations');
7379
$this->fs->mkdir($this->translationDir.'/templates');
7480

81+
$expectedExitStatus = TranslationDebugCommand::EXIT_CODE_MISSING | TranslationDebugCommand::EXIT_CODE_UNUSED;
82+
7583
$tester = $this->createCommandTester(['foo' => 'foo'], ['bar' => 'bar'], null, [$this->translationDir.'/trans'], [$this->translationDir.'/views']);
76-
$tester->execute(['locale' => 'en']);
84+
$res = $tester->execute(['locale' => 'en']);
7785

7886
$this->assertRegExp('/missing/', $tester->getDisplay());
7987
$this->assertRegExp('/unused/', $tester->getDisplay());
88+
$this->assertEquals($expectedExitStatus, $res);
8089
}
8190

8291
public function testDebugCustomDirectory()
@@ -89,11 +98,14 @@ public function testDebugCustomDirectory()
8998
->with($this->equalTo($this->translationDir.'/customDir'))
9099
->willThrowException(new \InvalidArgumentException());
91100

101+
$expectedExitStatus = TranslationDebugCommand::EXIT_CODE_MISSING | TranslationDebugCommand::EXIT_CODE_UNUSED;
102+
92103
$tester = $this->createCommandTester(['foo' => 'foo'], ['bar' => 'bar'], $kernel);
93-
$tester->execute(['locale' => 'en', 'bundle' => $this->translationDir.'/customDir']);
104+
$res = $tester->execute(['locale' => 'en', 'bundle' => $this->translationDir.'/customDir']);
94105

95106
$this->assertRegExp('/missing/', $tester->getDisplay());
96107
$this->assertRegExp('/unused/', $tester->getDisplay());
108+
$this->assertEquals($expectedExitStatus, $res);
97109
}
98110

99111
/**

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.