Skip to content

Commit 5678626

Browse files
Merge branch '5.4' into 6.2
* 5.4: [FrameworkBundle] Fix `debug:config` & `config:dump` in debug mode
2 parents 2a15e11 + 095bfb7 commit 5678626

File tree

4 files changed

+168
-68
lines changed

4 files changed

+168
-68
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
@@ -167,12 +167,12 @@ private function getConfigForExtension(ExtensionInterface $extension, ContainerB
167167

168168
// Fall back to default config if the extension has one
169169

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

174174
$configs = $container->getExtensionConfig($extensionAlias);
175-
$configuration = $extension->getConfiguration($configs, $container);
175+
$configuration = $extension instanceof ConfigurationInterface ? $extension : $extension->getConfiguration($configs, $container);
176176
$this->validateConfiguration($extension, $configuration);
177177

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

Tests/Functional/ConfigDebugCommandTest.php

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

35-
public function testDumpBundleName()
40+
/**
41+
* @testWith [true]
42+
* [false]
43+
*/
44+
public function testDumpBundleName(bool $debug)
3645
{
37-
$tester = $this->createCommandTester();
46+
$tester = $this->createCommandTester($debug);
3847
$ret = $tester->execute(['name' => 'TestBundle']);
3948

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

44-
public function testDumpBundleOption()
53+
/**
54+
* @testWith [true]
55+
* [false]
56+
*/
57+
public function testDumpBundleOption(bool $debug)
4558
{
46-
$tester = $this->createCommandTester();
59+
$tester = $this->createCommandTester($debug);
4760
$ret = $tester->execute(['name' => 'TestBundle', 'path' => 'custom']);
4861

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

53-
public function testParametersValuesAreResolved()
66+
/**
67+
* @testWith [true]
68+
* [false]
69+
*/
70+
public function testParametersValuesAreResolved(bool $debug)
5471
{
55-
$tester = $this->createCommandTester();
72+
$tester = $this->createCommandTester($debug);
5673
$ret = $tester->execute(['name' => 'framework']);
5774

5875
$this->assertSame(0, $ret, 'Returns 0 in case of success');
5976
$this->assertStringContainsString("locale: '%env(LOCALE)%'", $tester->getDisplay());
6077
$this->assertStringContainsString('secret: test', $tester->getDisplay());
6178
}
6279

63-
public function testParametersValuesAreFullyResolved()
80+
/**
81+
* @testWith [true]
82+
* [false]
83+
*/
84+
public function testParametersValuesAreFullyResolved(bool $debug)
6485
{
65-
$tester = $this->createCommandTester();
86+
$tester = $this->createCommandTester($debug);
6687
$ret = $tester->execute(['name' => 'framework', '--resolve-env' => true]);
6788

6889
$this->assertSame(0, $ret, 'Returns 0 in case of success');
@@ -72,77 +93,105 @@ public function testParametersValuesAreFullyResolved()
7293
$this->assertStringContainsString('ide: '.($_ENV['SYMFONY_IDE'] ?? $_SERVER['SYMFONY_IDE'] ?? 'null'), $tester->getDisplay());
7394
}
7495

75-
public function testDefaultParameterValueIsResolvedIfConfigIsExisting()
96+
/**
97+
* @testWith [true]
98+
* [false]
99+
*/
100+
public function testDefaultParameterValueIsResolvedIfConfigIsExisting(bool $debug)
76101
{
77-
$tester = $this->createCommandTester();
102+
$tester = $this->createCommandTester($debug);
78103
$ret = $tester->execute(['name' => 'framework']);
79104

80105
$this->assertSame(0, $ret, 'Returns 0 in case of success');
81-
$kernelCacheDir = $this->application->getKernel()->getContainer()->getParameter('kernel.cache_dir');
106+
$kernelCacheDir = self::$kernel->getContainer()->getParameter('kernel.cache_dir');
82107
$this->assertStringContainsString(sprintf("dsn: 'file:%s/profiler'", $kernelCacheDir), $tester->getDisplay());
83108
}
84109

85-
public function testDumpExtensionConfigWithoutBundle()
110+
/**
111+
* @testWith [true]
112+
* [false]
113+
*/
114+
public function testDumpExtensionConfigWithoutBundle(bool $debug)
86115
{
87-
$tester = $this->createCommandTester();
116+
$tester = $this->createCommandTester($debug);
88117
$ret = $tester->execute(['name' => 'test_dump']);
89118

90119
$this->assertSame(0, $ret, 'Returns 0 in case of success');
91120
$this->assertStringContainsString('enabled: true', $tester->getDisplay());
92121
}
93122

94-
public function testDumpUndefinedBundleOption()
123+
/**
124+
* @testWith [true]
125+
* [false]
126+
*/
127+
public function testDumpUndefinedBundleOption(bool $debug)
95128
{
96-
$tester = $this->createCommandTester();
129+
$tester = $this->createCommandTester($debug);
97130
$tester->execute(['name' => 'TestBundle', 'path' => 'foo']);
98131

99132
$this->assertStringContainsString('Unable to find configuration for "test.foo"', $tester->getDisplay());
100133
}
101134

102-
public function testDumpWithPrefixedEnv()
135+
/**
136+
* @testWith [true]
137+
* [false]
138+
*/
139+
public function testDumpWithPrefixedEnv(bool $debug)
103140
{
104-
$tester = $this->createCommandTester();
141+
$tester = $this->createCommandTester($debug);
105142
$tester->execute(['name' => 'FrameworkBundle']);
106143

107144
$this->assertStringContainsString("cookie_httponly: '%env(bool:COOKIE_HTTPONLY)%'", $tester->getDisplay());
108145
}
109146

110-
public function testDumpFallsBackToDefaultConfigAndResolvesParameterValue()
147+
/**
148+
* @testWith [true]
149+
* [false]
150+
*/
151+
public function testDumpFallsBackToDefaultConfigAndResolvesParameterValue(bool $debug)
111152
{
112-
$tester = $this->createCommandTester();
153+
$tester = $this->createCommandTester($debug);
113154
$ret = $tester->execute(['name' => 'DefaultConfigTestBundle']);
114155

115156
$this->assertSame(0, $ret, 'Returns 0 in case of success');
116157
$this->assertStringContainsString('foo: bar', $tester->getDisplay());
117158
}
118159

119-
public function testDumpFallsBackToDefaultConfigAndResolvesEnvPlaceholder()
160+
/**
161+
* @testWith [true]
162+
* [false]
163+
*/
164+
public function testDumpFallsBackToDefaultConfigAndResolvesEnvPlaceholder(bool $debug)
120165
{
121-
$tester = $this->createCommandTester();
166+
$tester = $this->createCommandTester($debug);
122167
$ret = $tester->execute(['name' => 'DefaultConfigTestBundle']);
123168

124169
$this->assertSame(0, $ret, 'Returns 0 in case of success');
125170
$this->assertStringContainsString("baz: '%env(BAZ)%'", $tester->getDisplay());
126171
}
127172

128-
public function testDumpThrowsExceptionWhenDefaultConfigFallbackIsImpossible()
173+
/**
174+
* @testWith [true]
175+
* [false]
176+
*/
177+
public function testDumpThrowsExceptionWhenDefaultConfigFallbackIsImpossible(bool $debug)
129178
{
130179
$this->expectException(\LogicException::class);
131180
$this->expectExceptionMessage('The extension with alias "extension_without_config_test" does not have configuration.');
132181

133-
$tester = $this->createCommandTester();
182+
$tester = $this->createCommandTester($debug);
134183
$tester->execute(['name' => 'ExtensionWithoutConfigTestBundle']);
135184
}
136185

137186
/**
138187
* @dataProvider provideCompletionSuggestions
139188
*/
140-
public function testComplete(array $input, array $expectedSuggestions)
189+
public function testComplete(bool $debug, array $input, array $expectedSuggestions)
141190
{
142-
$this->application->add(new ConfigDebugCommand());
143-
144-
$tester = new CommandCompletionTester($this->application->get('debug:config'));
191+
$application = $this->createApplication($debug);
145192

193+
$application->add(new ConfigDebugCommand());
194+
$tester = new CommandCompletionTester($application->get('debug:config'));
146195
$suggestions = $tester->complete($input);
147196

148197
foreach ($expectedSuggestions as $expectedSuggestion) {
@@ -152,17 +201,32 @@ public function testComplete(array $input, array $expectedSuggestions)
152201

153202
public static function provideCompletionSuggestions(): \Generator
154203
{
155-
yield 'name' => [[''], ['default_config_test', 'extension_without_config_test', 'framework', 'test']];
204+
$name = ['default_config_test', 'extension_without_config_test', 'framework', 'test'];
205+
yield 'name, no debug' => [false, [''], $name];
206+
yield 'name, debug' => [true, [''], $name];
156207

157-
yield 'name (started CamelCase)' => [['Fra'], ['DefaultConfigTestBundle', 'ExtensionWithoutConfigTestBundle', 'FrameworkBundle', 'TestBundle']];
208+
$nameCamelCased = ['DefaultConfigTestBundle', 'ExtensionWithoutConfigTestBundle', 'FrameworkBundle', 'TestBundle'];
209+
yield 'name (started CamelCase), no debug' => [false, ['Fra'], $nameCamelCased];
210+
yield 'name (started CamelCase), debug' => [true, ['Fra'], $nameCamelCased];
158211

159-
yield 'name with existing path' => [['framework', ''], ['secret', 'router.resource', 'router.utf8', 'router.enabled', 'validation.enabled', 'default_locale']];
212+
$nameWithPath = ['secret', 'router.resource', 'router.utf8', 'router.enabled', 'validation.enabled', 'default_locale'];
213+
yield 'name with existing path, no debug' => [false, ['framework', ''], $nameWithPath];
214+
yield 'name with existing path, debug' => [true, ['framework', ''], $nameWithPath];
160215
}
161216

162-
private function createCommandTester(): CommandTester
217+
private function createCommandTester(bool $debug): CommandTester
163218
{
164-
$command = $this->application->find('debug:config');
219+
$command = $this->createApplication($debug)->find('debug:config');
165220

166221
return new CommandTester($command);
167222
}
223+
224+
private function createApplication(bool $debug): Application
225+
{
226+
$kernel = static::bootKernel(['debug' => $debug, 'test_case' => 'ConfigDump', 'root_config' => 'config.yml']);
227+
$application = new Application($kernel);
228+
$application->doRun(new ArrayInput([]), new NullOutput());
229+
230+
return $application;
231+
}
168232
}

0 commit comments

Comments
 (0)