Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitd35c88f

Browse files
committed
Added support for multiple files or directories in LintCommand
1 parent00e5cd9 commitd35c88f

File tree

5 files changed

+42
-21
lines changed

5 files changed

+42
-21
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testLintCorrectFile()
3636
$filename =$this->createFile('foo: bar');
3737

3838
$tester->execute(
39-
array('filename' =>$filename),
39+
array('filename' =>array($filename)),
4040
array('verbosity' => OutputInterface::VERBOSITY_VERBOSE,'decorated' =>false)
4141
);
4242

@@ -52,7 +52,7 @@ public function testLintIncorrectFile()
5252
$tester =$this->createCommandTester();
5353
$filename =$this->createFile($incorrectContent);
5454

55-
$tester->execute(array('filename' =>$filename),array('decorated' =>false));
55+
$tester->execute(array('filename' =>array($filename)),array('decorated' =>false));
5656

5757
$this->assertEquals(1,$tester->getStatusCode(),'Returns 1 in case of error');
5858
$this->assertContains('Unable to parse at line 3 (near "bar").',trim($tester->getDisplay()));
@@ -67,7 +67,7 @@ public function testLintFileNotReadable()
6767
$filename =$this->createFile('');
6868
unlink($filename);
6969

70-
$tester->execute(array('filename' =>$filename),array('decorated' =>false));
70+
$tester->execute(array('filename' =>array($filename)),array('decorated' =>false));
7171
}
7272

7373
publicfunctiontestGetHelp()
@@ -103,7 +103,7 @@ public function testLintFilesFromBundleDirectory()
103103
{
104104
$tester =$this->createCommandTester($this->getKernelAwareApplicationMock());
105105
$tester->execute(
106-
array('filename' =>'@AppBundle/Resources'),
106+
array('filename' =>array('@AppBundle/Resources')),
107107
array('verbosity' => OutputInterface::VERBOSITY_VERBOSE,'decorated' =>false)
108108
);
109109

‎src/Symfony/Bundle/FrameworkBundle/composer.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"symfony/validator":"^4.1",
5353
"symfony/var-dumper":"~3.4|~4.0",
5454
"symfony/workflow":"^4.1",
55-
"symfony/yaml":"~3.4|~4.0",
55+
"symfony/yaml":"^4.2",
5656
"symfony/property-info":"~3.4|~4.0",
5757
"symfony/lock":"~3.4|~4.0",
5858
"symfony/web-link":"~3.4|~4.0",
@@ -73,6 +73,7 @@
7373
"symfony/stopwatch":"<3.4",
7474
"symfony/translation":"<4.2",
7575
"symfony/twig-bridge":"<4.1.1",
76+
"symfony/yaml":"<=4.2",
7677
"symfony/validator":"<4.1",
7778
"symfony/workflow":"<4.1"
7879
},

‎src/Symfony/Component/Yaml/CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.2.0
5+
-----
6+
7+
* added support for multiple files or directories in`LintCommand`
8+
49
4.0.0
510
-----
611

‎src/Symfony/Component/Yaml/Command/LintCommand.php‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
useSymfony\Component\Console\Command\Command;
1515
useSymfony\Component\Console\Exception\InvalidArgumentException;
1616
useSymfony\Component\Console\Exception\RuntimeException;
17+
useSymfony\Component\Console\Input\InputArgument;
1718
useSymfony\Component\Console\Input\InputInterface;
1819
useSymfony\Component\Console\Input\InputOption;
1920
useSymfony\Component\Console\Output\OutputInterface;
@@ -53,7 +54,7 @@ protected function configure()
5354
{
5455
$this
5556
->setDescription('Lints a file and outputs encountered errors')
56-
->addArgument('filename',null,'A file or a directory or STDIN')
57+
->addArgument('filename',InputArgument::IS_ARRAY,'A file or a directory or STDIN')
5758
->addOption('format',null, InputOption::VALUE_REQUIRED,'The output format','txt')
5859
->addOption('parse-tags',null, InputOption::VALUE_NONE,'Parse custom tags')
5960
->setHelp(<<<EOF
@@ -81,26 +82,28 @@ protected function configure()
8182
protectedfunctionexecute(InputInterface$input,OutputInterface$output)
8283
{
8384
$io =newSymfonyStyle($input,$output);
84-
$filename =$input->getArgument('filename');
85+
$filenames =$input->getArgument('filename');
8586
$this->format =$input->getOption('format');
8687
$this->displayCorrectFiles =$output->isVerbose();
8788
$flags =$input->getOption('parse-tags') ? Yaml::PARSE_CUSTOM_TAGS :0;
8889

89-
if (!$filename) {
90+
if (0 ===\count($filenames)) {
9091
if (!$stdin =$this->getStdin()) {
9192
thrownewRuntimeException('Please provide a filename or pipe file content to STDIN.');
9293
}
9394

9495
return$this->display($io,array($this->validate($stdin,$flags)));
9596
}
9697

97-
if (!$this->isReadable($filename)) {
98-
thrownewRuntimeException(sprintf('File or directory "%s" is not readable.',$filename));
99-
}
100-
10198
$filesInfo =array();
102-
foreach ($this->getFiles($filename)as$file) {
103-
$filesInfo[] =$this->validate(file_get_contents($file),$flags,$file);
99+
foreach ($filenamesas$filename) {
100+
if (!$this->isReadable($filename)) {
101+
thrownewRuntimeException(sprintf('File or directory "%s" is not readable.',$filename));
102+
}
103+
104+
foreach ($this->getFiles($filename)as$file) {
105+
$filesInfo[] =$this->validate(file_get_contents($file),$flags,$file);
106+
}
104107
}
105108

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

‎src/Symfony/Component/Yaml/Tests/Command/LintCommandTest.php‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,19 @@ public function testLintCorrectFile()
3131
$tester =$this->createCommandTester();
3232
$filename =$this->createFile('foo: bar');
3333

34-
$ret =$tester->execute(array('filename' =>$filename),array('verbosity' => OutputInterface::VERBOSITY_VERBOSE,'decorated' =>false));
34+
$ret =$tester->execute(array('filename' =>array($filename)),array('verbosity' => OutputInterface::VERBOSITY_VERBOSE,'decorated' =>false));
35+
36+
$this->assertEquals(0,$ret,'Returns 0 in case of success');
37+
$this->assertRegExp('/^\/\/ OK in /',trim($tester->getDisplay()));
38+
}
39+
40+
publicfunctiontestLintCorrectFiles()
41+
{
42+
$tester =$this->createCommandTester();
43+
$filename1 =$this->createFile('foo: bar');
44+
$filename2 =$this->createFile('bar: baz');
45+
46+
$ret =$tester->execute(array('filename' =>array($filename1,$filename2)),array('verbosity' => OutputInterface::VERBOSITY_VERBOSE,'decorated' =>false));
3547

3648
$this->assertEquals(0,$ret,'Returns 0 in case of success');
3749
$this->assertRegExp('/^\/\/ OK in /',trim($tester->getDisplay()));
@@ -45,7 +57,7 @@ public function testLintIncorrectFile()
4557
$tester =$this->createCommandTester();
4658
$filename =$this->createFile($incorrectContent);
4759

48-
$ret =$tester->execute(array('filename' =>$filename),array('decorated' =>false));
60+
$ret =$tester->execute(array('filename' =>array($filename)),array('decorated' =>false));
4961

5062
$this->assertEquals(1,$ret,'Returns 1 in case of error');
5163
$this->assertContains('Unable to parse at line 3 (near "bar").',trim($tester->getDisplay()));
@@ -56,7 +68,7 @@ public function testConstantAsKey()
5668
$yaml =<<<YAML
5769
!php/const 'Symfony\Component\Yaml\Tests\Command\Foo::TEST': bar
5870
YAML;
59-
$ret =$this->createCommandTester()->execute(array('filename' =>$this->createFile($yaml)),array('verbosity' => OutputInterface::VERBOSITY_VERBOSE,'decorated' =>false));
71+
$ret =$this->createCommandTester()->execute(array('filename' =>array($this->createFile($yaml))),array('verbosity' => OutputInterface::VERBOSITY_VERBOSE,'decorated' =>false));
6072
$this->assertSame(0,$ret,'lint:yaml exits with code 0 in case of success');
6173
}
6274

@@ -65,7 +77,7 @@ public function testCustomTags()
6577
$yaml =<<<YAML
6678
foo: !my_tag {foo: bar}
6779
YAML;
68-
$ret =$this->createCommandTester()->execute(array('filename' =>$this->createFile($yaml),'--parse-tags' =>true),array('verbosity' => OutputInterface::VERBOSITY_VERBOSE,'decorated' =>false));
80+
$ret =$this->createCommandTester()->execute(array('filename' =>array($this->createFile($yaml)),'--parse-tags' =>true),array('verbosity' => OutputInterface::VERBOSITY_VERBOSE,'decorated' =>false));
6981
$this->assertSame(0,$ret,'lint:yaml exits with code 0 in case of success');
7082
}
7183

@@ -74,7 +86,7 @@ public function testCustomTagsError()
7486
$yaml =<<<YAML
7587
foo: !my_tag {foo: bar}
7688
YAML;
77-
$ret =$this->createCommandTester()->execute(array('filename' =>$this->createFile($yaml)),array('verbosity' => OutputInterface::VERBOSITY_VERBOSE,'decorated' =>false));
89+
$ret =$this->createCommandTester()->execute(array('filename' =>array($this->createFile($yaml))),array('verbosity' => OutputInterface::VERBOSITY_VERBOSE,'decorated' =>false));
7890
$this->assertSame(1,$ret,'lint:yaml exits with code 1 in case of error');
7991
}
8092

@@ -87,7 +99,7 @@ public function testLintFileNotReadable()
8799
$filename =$this->createFile('');
88100
unlink($filename);
89101

90-
$ret =$tester->execute(array('filename' =>$filename),array('decorated' =>false));
102+
$tester->execute(array('filename' =>array($filename)),array('decorated' =>false));
91103
}
92104

93105
/**
@@ -135,5 +147,5 @@ protected function tearDown()
135147

136148
class Foo
137149
{
138-
constTEST ='foo';
150+
publicconstTEST ='foo';
139151
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp