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

Skip to content

Commit a3e8560

Browse files
Toflarfabpot
authored andcommitted
[FrameworkBundle] Fixed parsing new JSON output of debug:config not possible
1 parent 5b66f26 commit a3e8560

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected function configure(): void
4949
new InputArgument('name', InputArgument::OPTIONAL, 'The bundle name or the extension alias'),
5050
new InputArgument('path', InputArgument::OPTIONAL, 'The configuration option path'),
5151
new InputOption('resolve-env', null, InputOption::VALUE_NONE, 'Display resolved environment variable values instead of placeholders'),
52-
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), class_exists(Yaml::class) ? 'yaml' : 'json'),
52+
new InputOption('format', null, InputOption::VALUE_REQUIRED, sprintf('The output format ("%s")', implode('", "', $this->getAvailableFormatOptions())), class_exists(Yaml::class) ? 'txt' : 'json'),
5353
])
5454
->setHelp(<<<EOF
5555
The <info>%command.name%</info> command dumps the current configuration for an
@@ -97,16 +97,18 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9797

9898
$format = $input->getOption('format');
9999

100-
if ('yaml' === $format && !class_exists(Yaml::class)) {
101-
$errorIo->error('Setting the "format" option to "yaml" requires the Symfony Yaml component. Try running "composer install symfony/yaml" or use "--format=json" instead.');
100+
if (\in_array($format, ['txt', 'yml'], true) && !class_exists(Yaml::class)) {
101+
$errorIo->error('Setting the "format" option to "txt" or "yaml" requires the Symfony Yaml component. Try running "composer install symfony/yaml" or use "--format=json" instead.');
102102

103103
return 1;
104104
}
105105

106106
if (null === $path = $input->getArgument('path')) {
107-
$io->title(
108-
sprintf('Current configuration for %s', $name === $extensionAlias ? sprintf('extension with alias "%s"', $extensionAlias) : sprintf('"%s"', $name))
109-
);
107+
if ('txt' === $input->getOption('format')) {
108+
$io->title(
109+
sprintf('Current configuration for %s', $name === $extensionAlias ? sprintf('extension with alias "%s"', $extensionAlias) : sprintf('"%s"', $name))
110+
);
111+
}
110112

111113
$io->writeln($this->convertToFormat([$extensionAlias => $config], $format));
112114

@@ -131,7 +133,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
131133
private function convertToFormat(mixed $config, string $format): string
132134
{
133135
return match ($format) {
134-
'yaml' => Yaml::dump($config, 10),
136+
'txt', 'yaml' => Yaml::dump($config, 10),
135137
'json' => json_encode($config, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE),
136138
default => throw new InvalidArgumentException(sprintf('Supported formats are "%s".', implode('", "', $this->getAvailableFormatOptions()))),
137139
};
@@ -268,6 +270,6 @@ private static function buildPathsCompletion(array $paths, string $prefix = ''):
268270

269271
private function getAvailableFormatOptions(): array
270272
{
271-
return ['yaml', 'json'];
273+
return ['txt', 'yaml', 'json'];
272274
}
273275
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,19 @@ public function testDumpBundleOption(bool $debug)
8484
$this->assertStringContainsString('foo', $tester->getDisplay());
8585
}
8686

87+
/**
88+
* @testWith [true]
89+
* [false]
90+
*/
91+
public function testDumpWithoutTitleIsValidJson(bool $debug)
92+
{
93+
$tester = $this->createCommandTester($debug);
94+
$ret = $tester->execute(['name' => 'TestBundle', '--format' => 'json']);
95+
96+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
97+
$this->assertJson($tester->getDisplay());
98+
}
99+
87100
/**
88101
* @testWith [true]
89102
* [false]
@@ -93,7 +106,7 @@ public function testDumpWithUnsupportedFormat(bool $debug)
93106
$tester = $this->createCommandTester($debug);
94107

95108
$this->expectException(InvalidArgumentException::class);
96-
$this->expectExceptionMessage('Supported formats are "yaml", "json"');
109+
$this->expectExceptionMessage('Supported formats are "txt", "yaml", "json"');
97110

98111
$tester->execute([
99112
'name' => 'test',

0 commit comments

Comments
 (0)