Skip to content

Commit e3f41ec

Browse files
Merge branch '6.2' into 6.3
* 6.2: [FrameworkBundle] Fix `debug:config` & `config:dump` in debug mode
2 parents 5e69e6d + 5678626 commit e3f41ec

File tree

4 files changed

+176
-71
lines changed

4 files changed

+176
-71
lines changed

Command/BuildDebugContainerTrait.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,14 @@ protected function getContainerBuilder(KernelInterface $kernel): ContainerBuilde
5050
$container->getCompilerPassConfig()->setAfterRemovingPasses([]);
5151
$container->compile();
5252
} else {
53-
(new XmlFileLoader($container = new ContainerBuilder(), new FileLocator()))->load($kernel->getContainer()->getParameter('debug.container.dump'));
53+
$buildContainer = \Closure::bind(function () {
54+
$containerBuilder = $this->getContainerBuilder();
55+
$this->prepareContainer($containerBuilder);
56+
57+
return $containerBuilder;
58+
}, $kernel, \get_class($kernel));
59+
$container = $buildContainer();
60+
(new XmlFileLoader($container, new FileLocator()))->load($kernel->getContainer()->getParameter('debug.container.dump'));
5461
$locatorPass = new ServiceLocatorTagPass();
5562
$locatorPass->process($container);
5663

Command/ConfigDebugCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ private function getConfigForExtension(ExtensionInterface $extension, ContainerB
194194

195195
// Fall back to default config if the extension has one
196196

197-
if (!$extension instanceof ConfigurationExtensionInterface) {
197+
if (!$extension instanceof ConfigurationExtensionInterface && !$extension instanceof ConfigurationInterface) {
198198
throw new \LogicException(sprintf('The extension with alias "%s" does not have configuration.', $extensionAlias));
199199
}
200200

201201
$configs = $container->getExtensionConfig($extensionAlias);
202-
$configuration = $extension->getConfiguration($configs, $container);
202+
$configuration = $extension instanceof ConfigurationInterface ? $extension : $extension->getConfiguration($configs, $container);
203203
$this->validateConfiguration($extension, $configuration);
204204

205205
return (new Processor())->processConfiguration($configuration, $configs);

Tests/Functional/ConfigDebugCommandTest.php

Lines changed: 110 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,36 +24,53 @@
2424
*/
2525
class ConfigDebugCommandTest extends AbstractWebTestCase
2626
{
27-
private $application;
28-
29-
protected function setUp(): void
27+
/**
28+
* @testWith [true]
29+
* [false]
30+
*/
31+
public function testDumpKernelExtension(bool $debug)
3032
{
31-
$kernel = static::createKernel(['test_case' => 'ConfigDump', 'root_config' => 'config.yml']);
32-
$this->application = new Application($kernel);
33-
$this->application->doRun(new ArrayInput([]), new NullOutput());
33+
$tester = $this->createCommandTester($debug);
34+
$ret = $tester->execute(['name' => 'foo']);
35+
36+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
37+
$this->assertStringContainsString('foo:', $tester->getDisplay());
38+
$this->assertStringContainsString(' foo: bar', $tester->getDisplay());
3439
}
3540

36-
public function testDumpBundleName()
41+
/**
42+
* @testWith [true]
43+
* [false]
44+
*/
45+
public function testDumpBundleName(bool $debug)
3746
{
38-
$tester = $this->createCommandTester();
47+
$tester = $this->createCommandTester($debug);
3948
$ret = $tester->execute(['name' => 'TestBundle']);
4049

4150
$this->assertSame(0, $ret, 'Returns 0 in case of success');
4251
$this->assertStringContainsString('custom: foo', $tester->getDisplay());
4352
}
4453

45-
public function testDumpBundleOption()
54+
/**
55+
* @testWith [true]
56+
* [false]
57+
*/
58+
public function testDumpBundleOption(bool $debug)
4659
{
47-
$tester = $this->createCommandTester();
60+
$tester = $this->createCommandTester($debug);
4861
$ret = $tester->execute(['name' => 'TestBundle', 'path' => 'custom']);
4962

5063
$this->assertSame(0, $ret, 'Returns 0 in case of success');
5164
$this->assertStringContainsString('foo', $tester->getDisplay());
5265
}
5366

54-
public function testDumpWithUnsupportedFormat()
67+
/**
68+
* @testWith [true]
69+
* [false]
70+
*/
71+
public function testDumpWithUnsupportedFormat(bool $debug)
5572
{
56-
$tester = $this->createCommandTester();
73+
$tester = $this->createCommandTester($debug);
5774

5875
$this->expectException(InvalidArgumentException::class);
5976
$this->expectExceptionMessage('Supported formats are "yaml", "json"');
@@ -64,19 +81,27 @@ public function testDumpWithUnsupportedFormat()
6481
]);
6582
}
6683

67-
public function testParametersValuesAreResolved()
84+
/**
85+
* @testWith [true]
86+
* [false]
87+
*/
88+
public function testParametersValuesAreResolved(bool $debug)
6889
{
69-
$tester = $this->createCommandTester();
90+
$tester = $this->createCommandTester($debug);
7091
$ret = $tester->execute(['name' => 'framework']);
7192

7293
$this->assertSame(0, $ret, 'Returns 0 in case of success');
7394
$this->assertStringContainsString("locale: '%env(LOCALE)%'", $tester->getDisplay());
7495
$this->assertStringContainsString('secret: test', $tester->getDisplay());
7596
}
7697

77-
public function testParametersValuesAreFullyResolved()
98+
/**
99+
* @testWith [true]
100+
* [false]
101+
*/
102+
public function testParametersValuesAreFullyResolved(bool $debug)
78103
{
79-
$tester = $this->createCommandTester();
104+
$tester = $this->createCommandTester($debug);
80105
$ret = $tester->execute(['name' => 'framework', '--resolve-env' => true]);
81106

82107
$this->assertSame(0, $ret, 'Returns 0 in case of success');
@@ -86,77 +111,105 @@ public function testParametersValuesAreFullyResolved()
86111
$this->assertStringContainsString('ide: '.($_ENV['SYMFONY_IDE'] ?? $_SERVER['SYMFONY_IDE'] ?? 'null'), $tester->getDisplay());
87112
}
88113

89-
public function testDefaultParameterValueIsResolvedIfConfigIsExisting()
114+
/**
115+
* @testWith [true]
116+
* [false]
117+
*/
118+
public function testDefaultParameterValueIsResolvedIfConfigIsExisting(bool $debug)
90119
{
91-
$tester = $this->createCommandTester();
120+
$tester = $this->createCommandTester($debug);
92121
$ret = $tester->execute(['name' => 'framework']);
93122

94123
$this->assertSame(0, $ret, 'Returns 0 in case of success');
95-
$kernelCacheDir = $this->application->getKernel()->getContainer()->getParameter('kernel.cache_dir');
124+
$kernelCacheDir = self::$kernel->getContainer()->getParameter('kernel.cache_dir');
96125
$this->assertStringContainsString(sprintf("dsn: 'file:%s/profiler'", $kernelCacheDir), $tester->getDisplay());
97126
}
98127

99-
public function testDumpExtensionConfigWithoutBundle()
128+
/**
129+
* @testWith [true]
130+
* [false]
131+
*/
132+
public function testDumpExtensionConfigWithoutBundle(bool $debug)
100133
{
101-
$tester = $this->createCommandTester();
134+
$tester = $this->createCommandTester($debug);
102135
$ret = $tester->execute(['name' => 'test_dump']);
103136

104137
$this->assertSame(0, $ret, 'Returns 0 in case of success');
105138
$this->assertStringContainsString('enabled: true', $tester->getDisplay());
106139
}
107140

108-
public function testDumpUndefinedBundleOption()
141+
/**
142+
* @testWith [true]
143+
* [false]
144+
*/
145+
public function testDumpUndefinedBundleOption(bool $debug)
109146
{
110-
$tester = $this->createCommandTester();
147+
$tester = $this->createCommandTester($debug);
111148
$tester->execute(['name' => 'TestBundle', 'path' => 'foo']);
112149

113150
$this->assertStringContainsString('Unable to find configuration for "test.foo"', $tester->getDisplay());
114151
}
115152

116-
public function testDumpWithPrefixedEnv()
153+
/**
154+
* @testWith [true]
155+
* [false]
156+
*/
157+
public function testDumpWithPrefixedEnv(bool $debug)
117158
{
118-
$tester = $this->createCommandTester();
159+
$tester = $this->createCommandTester($debug);
119160
$tester->execute(['name' => 'FrameworkBundle']);
120161

121162
$this->assertStringContainsString("cookie_httponly: '%env(bool:COOKIE_HTTPONLY)%'", $tester->getDisplay());
122163
}
123164

124-
public function testDumpFallsBackToDefaultConfigAndResolvesParameterValue()
165+
/**
166+
* @testWith [true]
167+
* [false]
168+
*/
169+
public function testDumpFallsBackToDefaultConfigAndResolvesParameterValue(bool $debug)
125170
{
126-
$tester = $this->createCommandTester();
171+
$tester = $this->createCommandTester($debug);
127172
$ret = $tester->execute(['name' => 'DefaultConfigTestBundle']);
128173

129174
$this->assertSame(0, $ret, 'Returns 0 in case of success');
130175
$this->assertStringContainsString('foo: bar', $tester->getDisplay());
131176
}
132177

133-
public function testDumpFallsBackToDefaultConfigAndResolvesEnvPlaceholder()
178+
/**
179+
* @testWith [true]
180+
* [false]
181+
*/
182+
public function testDumpFallsBackToDefaultConfigAndResolvesEnvPlaceholder(bool $debug)
134183
{
135-
$tester = $this->createCommandTester();
184+
$tester = $this->createCommandTester($debug);
136185
$ret = $tester->execute(['name' => 'DefaultConfigTestBundle']);
137186

138187
$this->assertSame(0, $ret, 'Returns 0 in case of success');
139188
$this->assertStringContainsString("baz: '%env(BAZ)%'", $tester->getDisplay());
140189
}
141190

142-
public function testDumpThrowsExceptionWhenDefaultConfigFallbackIsImpossible()
191+
/**
192+
* @testWith [true]
193+
* [false]
194+
*/
195+
public function testDumpThrowsExceptionWhenDefaultConfigFallbackIsImpossible(bool $debug)
143196
{
144197
$this->expectException(\LogicException::class);
145198
$this->expectExceptionMessage('The extension with alias "extension_without_config_test" does not have configuration.');
146199

147-
$tester = $this->createCommandTester();
200+
$tester = $this->createCommandTester($debug);
148201
$tester->execute(['name' => 'ExtensionWithoutConfigTestBundle']);
149202
}
150203

151204
/**
152205
* @dataProvider provideCompletionSuggestions
153206
*/
154-
public function testComplete(array $input, array $expectedSuggestions)
207+
public function testComplete(bool $debug, array $input, array $expectedSuggestions)
155208
{
156-
$this->application->add(new ConfigDebugCommand());
157-
158-
$tester = new CommandCompletionTester($this->application->get('debug:config'));
209+
$application = $this->createApplication($debug);
159210

211+
$application->add(new ConfigDebugCommand());
212+
$tester = new CommandCompletionTester($application->get('debug:config'));
160213
$suggestions = $tester->complete($input);
161214

162215
foreach ($expectedSuggestions as $expectedSuggestion) {
@@ -166,19 +219,35 @@ public function testComplete(array $input, array $expectedSuggestions)
166219

167220
public static function provideCompletionSuggestions(): \Generator
168221
{
169-
yield 'name' => [[''], ['default_config_test', 'extension_without_config_test', 'framework', 'test']];
222+
$name = ['default_config_test', 'extension_without_config_test', 'framework', 'test'];
223+
yield 'name, no debug' => [false, [''], $name];
224+
yield 'name, debug' => [true, [''], $name];
170225

171-
yield 'name (started CamelCase)' => [['Fra'], ['DefaultConfigTestBundle', 'ExtensionWithoutConfigTestBundle', 'FrameworkBundle', 'TestBundle']];
226+
$nameCamelCased = ['DefaultConfigTestBundle', 'ExtensionWithoutConfigTestBundle', 'FrameworkBundle', 'TestBundle'];
227+
yield 'name (started CamelCase), no debug' => [false, ['Fra'], $nameCamelCased];
228+
yield 'name (started CamelCase), debug' => [true, ['Fra'], $nameCamelCased];
172229

173-
yield 'name with existing path' => [['framework', ''], ['secret', 'router.resource', 'router.utf8', 'router.enabled', 'validation.enabled', 'default_locale']];
230+
$nameWithPath = ['secret', 'router.resource', 'router.utf8', 'router.enabled', 'validation.enabled', 'default_locale'];
231+
yield 'name with existing path, no debug' => [false, ['framework', ''], $nameWithPath];
232+
yield 'name with existing path, debug' => [true, ['framework', ''], $nameWithPath];
174233

175-
yield 'option --format' => [['--format', ''], ['yaml', 'json']];
234+
yield 'option --format, no debug' => [false, ['--format', ''], ['yaml', 'json']];
235+
yield 'option --format, debug' => [true, ['--format', ''], ['yaml', 'json']];
176236
}
177237

178-
private function createCommandTester(): CommandTester
238+
private function createCommandTester(bool $debug): CommandTester
179239
{
180-
$command = $this->application->find('debug:config');
240+
$command = $this->createApplication($debug)->find('debug:config');
181241

182242
return new CommandTester($command);
183243
}
244+
245+
private function createApplication(bool $debug): Application
246+
{
247+
$kernel = static::bootKernel(['debug' => $debug, 'test_case' => 'ConfigDump', 'root_config' => 'config.yml']);
248+
$application = new Application($kernel);
249+
$application->doRun(new ArrayInput([]), new NullOutput());
250+
251+
return $application;
252+
}
184253
}

0 commit comments

Comments
 (0)