8000 Added support for multiple files or directories in XliffLintCommand · symfony/symfony@d329ebe · GitHub
[go: up one dir, main page]

Skip to content
Sign in

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 d329ebe

Browse files
committed
Added support for multiple files or directories in XliffLintCommand
1 parent 00e5cd9 commit d329ebe

File tree

5 files changed

+36
-17
lines changed

5 files changed

+36
-17
lines changed

src/Symfony/Bundle/FrameworkBundle/Tests/Command/XliffLintCommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function testLintFilesFromBundleDirectory()
6464
{
6565
$tester = $this->createCommandTester($this->getKernelAwareApplicationMock());
6666
$tester->execute(
67-
array('filename' => '@AppBundle/Resources'),
67+
array('filename' => array('@AppBundle/Resources')),
6868
array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false)
6969
);
7070

src/Symfony/Bundle/FrameworkBundle/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"symfony/security-csrf": "~3.4|~4.0",
4848
"symfony/serializer": "^4.1",
4949
"symfony/stopwatch": "~3.4|~4.0",
50-
"symfony/translation": "~4.2",
50+
"symfony/translation": "^4.2",
5151
"symfony/templating": "~3.4|~4.0",
5252
"symfony/validator": "^4.1",
5353
"symfony/var-dumper": "~3.4|~4.0",
@@ -71,7 +71,7 @@
7171
"symfony/property-info": "<3.4",
7272
"symfony/serializer": "<4.1",
7373
"symfony/stopwatch": "<3.4",
74-
"symfony/translation": "<4.2",
74+
"symfony/translation": "<=4.2",
7575
"symfony/twig-bridge": "<4.1.1",
7676
"symfony/validator": "<4.1",
7777
"symfony/workflow": "<4.1"

src/Symfony/Component/Translation/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ CHANGELOG
88
* deprecated `TranslatorInterface` in favor of `Symfony\Contracts\Translation\TranslatorInterface`
99
* deprecated `MessageSelector`, `Interval` and `PluralizationRules`; use `IdentityTranslator` instead
1010
* Added `IntlMessageFormatter` and `FallbackMessageFormatter`
11+
* added support for multiple files and directories in `XliffLintCommand`
1112

1213
4.1.0
1314
-----

src/Symfony/Component/Translation/Command/XliffLintCommand.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Console\Command\Command;
1515
use Symfony\Component\Console\Exception\RuntimeException;
16+
use Symfony\Component\Console\Input\InputArgument;
1617
use Symfony\Component\Console\Input\InputInterface;
1718
use Symfony\Component\Console\Input\InputOption;
1819
use Symfony\Component\Console\Output\OutputInterface;
@@ -52,7 +53,7 @@ protected function configure()
5253
{
5354
$this
5455
->setDescription('Lints a XLIFF file and outputs encountered errors')
55-
->addArgument('filename', null, 'A file or a directory or STDIN')
56+
->addArgument('filename', InputArgument::IS_ARRAY, 'A file or a directory or STDIN')
5657
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format', 'txt')
5758
->setHelp(<<<EOF
5859
The <info>%command.name%</info> command lints a XLIFF file and outputs to STDOUT
@@ -79,25 +80,27 @@ protected function configure()
7980
protected function execute(InputInterface $input, OutputInterface $output)
8081
{
8182
$io = new SymfonyStyle($input, $output);
82-
$filename = $input->getArgument('filename');
83+
$filenames = $input->getArgument('filename');
8384
$this->format = $input->getOption('format');
8485
$this->displayCorrectFiles = $output->isVerbose();
8586

86-
if (!$filename) {
87+
if (0 === \count($filenames)) {
8788
if (!$stdin = $this->getStdin()) {
8889
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
8990
}
9091

9192
return $this->display($io, array($this->validate($stdin)));
9293
}
9394

94-
if (!$this->isReadable($filename)) {
95-
throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
96-
}
97-
9895
$filesInfo = array();
99-
foreach ($this->getFiles($filename) as $file) {
100-
$filesInfo[] = $this->validate(file_get_contents($file), $file);
96+
foreach ($filenames as $filename) {
97+
if (!$this->isReadable($filename)) {
98+
throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
99+
}
100+
101+
foreach ($this->getFiles($filename) as $file) {
102+
$filesInfo[] = $this->validate(file_get_contents($file), $file);
103+
}
101104
}
102105

103106
return $this->display($io, $filesInfo);

src/Symfony/Component/Translation/Tests/Command/XliffLintCommandTest.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,22 @@ public function testLintCorrectFile()
3232
$filename = $this->createFile();
3333

3434
$tester->execute(
35-
array('filename' => $filename),
35+
array('filename' => array($filename)),
36+
array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false)
37+
);
38+
39+
$this->assertEquals(0, $tester->getStatusCode(), 'Returns 0 in case of success');
40+
$this->assertContains('OK', trim($tester->getDisplay()));
41+
}
42+
43+
public function testLintCorrectFiles()
44+
{
45+
$tester = $this->createCommandTester();
46+
$filename1 = $this->createFile();
47+
$filename2 = $this->createFile();
48+
49+
$tester->execute(
50+
array('filename' => array($filename1, $filename2)),
3651
array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false)
3752
);
3853

@@ -49,7 +64,7 @@ public function testStrictFilenames($requireStrictFileNames, $fileNamePattern, $
4964
$filename = $this->createFile('note', $targetLanguage, $fileNamePattern);
5065

5166
$tester->execute(
52-
array('filename' => $filename),
67+
array('filename' => array($filename)),
5368
array('verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false)
5469
);
5570

@@ -62,7 +77,7 @@ public function testLintIncorrectXmlSyntax()
6277
$tester = $this->createCommandTester();
6378
$filename = $this->createFile('note <target>');
6479

65-
$tester->execute(array('filename' => $filename), array('decorated' => false));
80+
$tester->execute(array('filename' => array($filename)), array('decorated' => false));
6681

6782
$this->assertEquals(1, $tester->getStatusCode(), 'Returns 1 in case of error');
6883
$this->assertContains('Opening and ending tag mismatch: target line 6 and source', trim($tester->getDisplay()));
@@ -73,7 +88,7 @@ public function testLintIncorrectTargetLanguage()
7388
$tester = $this->createCommandTester();
7489
$filename = $this->createFile('note', 'es');
7590

76-
$tester->execute(array('filename' => $filename), array('decorated' => false));
91+
$tester->execute(array('filename' => array($filename)), array('decorated' => false));
7792

7893
$this->assertEquals(1, $tester->getStatusCode(), 'Returns 1 in case of error');
7994
$this->assertContains('There is a mismatch between the language included in the file name ("messages.en.xlf") and the "es" value used in the "target-language" attribute of the file.', trim($tester->getDisplay()));
@@ -88,7 +103,7 @@ public function testLintFileNotReadable()
88103
$filename = $this->createFile();
89104
unlink($filename);
90105

91-
$tester->execute(array('filename' => $filename), array('decorated' => false));
106+
$tester->execute(array('filename' => array($filename)), array('decorated' => false));
92107
}
93108

94109
public function testGetHelp()

0 commit comments

Comments
 (0)
0