Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit df13bd9

Browse files
committed
Fix CR issues
1 parent 058f9f0 commit df13bd9

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

src/Symfony/Bundle/FrameworkBundle/Command/ConfigDebugCommand.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function configure()
4646
new InputArgument('name', InputArgument::OPTIONAL, 'The bundle name or the extension alias'),
4747
new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),
4848
new InputOption('resolve-env', null, InputOption::VALUE_NONE, 'Display resolved environment variable values instead of placeholders'),
49-
new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (yaml or json)', 'yaml'),
49+
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), class_exists(Yaml::class) ? 'yaml' : 'json'),
5050
])
5151
->setHelp(<<<'EOF'
5252
The <info>%command.name%</info> command dumps the current configuration for an
@@ -57,9 +57,8 @@ protected function configure()
5757
<info>php %command.full_name% framework</info>
5858
<info>php %command.full_name% FrameworkBundle</info>
5959
60-
With the <info>--format</info> option specifies the format of the configuration,
60+
The <info>--format</info> option specifies the format of the configuration,
6161
this is either <comment>yaml</comment> or <comment>json</comment>.
62-
When the option is not provided, <comment>yaml</comment> is used.
6362
6463
<info>php %command.full_name% FrameworkBundle --format=json</info>
6564
@@ -102,7 +101,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
102101
$format = $input->getOption('format');
103102

104103
if ('yaml' === $format && !class_exists(Yaml::class)) {
105-
$errorIo->error('Setting the "format" option to "yaml" requires the Symfony Yaml component. Try running "composer install symfony/yaml" or use "--format=json" instead.');
104+
$errorIo->error('The "yaml" format requires the installation of the Yaml component. Install it with "composer require symfony/yaml", or choose another format by specifying "--format=json".');
106105

107106
return 1;
108107
}
@@ -142,8 +141,8 @@ private function convertToFormat(mixed $config, string $format): string
142141
{
143142
return match ($format) {
144143
'yaml' => Yaml::dump($config, 10),
145-
'json' => json_encode($config, \JSON_PRETTY_PRINT),
146-
default => throw new InvalidArgumentException('Only the yaml and json formats are supported.'),
144+
'json' => json_encode($config, \JSON_PRETTY_PRINT|\JSON_UNESCAPED_SLASHES|\JSON_UNESCAPED_UNICODE),
145+
default => throw new InvalidArgumentException(sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
147146
};
148147
}
149148

src/Symfony/Bundle/FrameworkBundle/Tests/Functional/ConfigDebugCommandTest.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\Command\ConfigDebugCommand;
1515
use Symfony\Bundle\FrameworkBundle\Console\Application;
16+
use Symfony\Component\Console\Exception\InvalidArgumentException;
1617
use Symfony\Component\Console\Input\ArrayInput;
1718
use Symfony\Component\Console\Output\NullOutput;
1819
use Symfony\Component\Console\Tester\CommandCompletionTester;
@@ -55,14 +56,27 @@ public function testDumpAtPathWithFormat()
5556
$tester = $this->createCommandTester();
5657
$ret = $tester->execute([
5758
'name' => 'test',
58-
'path' => 'array',
59+
'path' => 'custom',
5960
'--format' => 'json',
6061
]);
6162

6263
$this->assertSame(1, $ret);
6364
$this->assertStringContainsString('[ERROR] The "path" option is only available for the "yaml" format.', $tester->getDisplay());
6465
}
6566

67+
public function testDumpWithUnsupportedFormat()
68+
{
69+
$tester = $this->createCommandTester();
70+
71+
$this->expectException(InvalidArgumentException::class);
72+
$this->expectExceptionMessage('Supported formats are "yaml", "json"');
73+
74+
$tester->execute([
75+
'name' => 'test',
76+
'--format' => 'xml',
77+
]);
78+
}
79+
6680
public function testParametersValuesAreResolved()
6781
{
6882
$tester = $this->createCommandTester();

0 commit comments

Comments
 (0)