10000 [FrameworkBundle] Fix `debug:config` & `config:dump` in debug mode · symfony/symfony@73871a7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 73871a7

Browse files
committed
[FrameworkBundle] Fix debug:config & config:dump in debug mode
1 parent b4128fd commit 73871a7

File tree

4 files changed

+158
-66
lines changed

4 files changed

+158
-66
lines changed

src/Symfony/Bundle/FrameworkBundle/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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ private function getCo B41A nfigForExtension(ExtensionInterface $extension, ContainerB
176176

177177
// Fall back to default config if the extension has one
178178

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

183183
$configs = $container->getExtensionConfig($extensionAlias);
184-
$configuration = $extension->getConfiguration($configs, $container);
184+
$configuration = $extension instanceof ConfigurationInterface ? $extension : $extension->getConfiguration($configs, $container);
185185
$this->validateConfiguration($extension, $configuration);
186186

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

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

Lines changed: 91 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,114 +23,154 @@
2323
*/
2424
class ConfigDebugCommandTest extends AbstractWebTestCase
2525
{
26-
private $application;
27-
28-
protected function setUp(): void
26+
/**
27+
* @dataProvider provideDebugValues
28+
*/
29+
public function testDumpKernelExtension(bool $debug)
2930
{
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());
31+
$tester = $this->createCommandTester($debug);
32+
$ret = $tester->execute(['name' => 'foo']);
33+
34+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
35+
$this->assertStringContainsString('foo:', $tester->getDisplay());
36+
$this->assertStringContainsString(' foo: bar', $tester->getDisplay());
3337
}
3438

35-
public function testDumpBundleName()
39+
/**
40+
* @dataProvider provideDebugValues
41+
*/
42+
public function testDumpBundleName(bool $debug)
3643
{
37-
$tester = $this->createCommandTester();
44+
$tester = $this->createCommandTester($debug);
3845
$ret = $tester->execute(['name' => 'TestBundle']);
3946

4047
$this->assertSame(0, $ret, 'Returns 0 in case of success');
4148
$this->assertStringContainsString('custom: foo', $tester->getDisplay());
4249
}
4350

44-
public function testDumpBundleOption()
51+
/**
52+
* @dataProvider provideDebugValues
53+
*/
54+
public function testDumpBundleOption(bool $debug)
4555
{
46-
$tester = $this->createCommandTester();
56+
$tester = $this->createCommandTester($debug);
4757
$ret = $tester->execute(['name' => 'TestBundle', 'path' => 'custom']);
4858

4959
$this->assertSame(0, $ret, 'Returns 0 in case of success');
5060
$this->assertStringContainsString('foo', $tester->getDisplay());
5161
}
5262

53-
public function testParametersValuesAreResolved()
63+
/**
64+
* @dataProvider provideDebugValues
65+
*/
66+
public function testParametersValuesAreResolved(bool $debug)
5467
{
55-
$tester = $this->createCommandTester();
68+
$tester = $this->createCommandTester($debug);
5669
$ret = $tester->execute(['name' => 'framework']);
5770

5871
$this->assertSame(0, $ret, 'Returns 0 in case of success');
5972
$this->assertStringContainsString("locale: '%env(LOCALE)%'", $tester->getDisplay());
6073
$this->assertStringContainsString('secret: test', $tester->getDisplay());
6174
}
6275

63-
public function testDefaultParameterValueIsResolvedIfConfigIsExisting()
76+
/**
77+
* @dataProvider provideDebugValues
78+
*/
79+
public function testDefaultParameterValueIsResolvedIfConfigIsExisting(bool $debug)
6480
{
65-
$tester = $this->createCommandTester();
81+
$tester = $this->createCommandTester($debug);
6682
$ret = $tester->execute(['name' => 'framework']);
6783

6884
$this->assertSame(0, $ret, 'Returns 0 in case of success');
69-
$kernelCacheDir = $this->application->getKernel()->getContainer()->getParameter('kernel.cache_dir');
85+
$kernelCacheDir = self::$kernel->getContainer()->getParameter('kernel.cache_dir');
7086
$this->assertStringContainsString(sprintf("dsn: 'file:%s/profiler'", $kernelCacheDir), $tester->getDisplay());
7187
}
7288

73-
public function testDumpExtensionConfigWithoutBundle()
89+
/**
90+
* @dataProvider provideDebugValues
91+
*/
92+
public function testDumpExtensionConfigWithoutBundle(bool $debug)
7493
{
75-
$tester = $this->createCommandTester();
94+
$tester = $this->createCommandTester($debug);
7695
$ret = $tester->execute(['name' => 'test_dump']);
7796

7897
$this->assertSame(0, $ret, 'Returns 0 in case of success');
7998
$this->assertStringContainsString('enabled: true', $tester->getDisplay());
8099
}
81100

82-
public function testDumpUndefinedBundleOption()
101+
/**
102+
* @dataProvider provideDebugValues
103+
*/
104+
public function testDumpUndefinedBundleOption(bool $debug)
83105
{
84-
$tester = $this->createCommandTester();
106+
$tester = $this->createCommandTester($debug);
85107
$tester->execute(['name' => 'TestBundle', 'path' => 'foo']);
86108

87109
$this->assertStringContainsString('Unable to find configuration for "test.foo"', $tester->getDisplay());
88110
}
89111

90-
public function testDumpWithPrefixedEnv()
112+
/**
113+
* @dataProvider provideDebugValues
114+
*/
115+
public function testDumpWithPrefixedEnv(bool $debug)
91116
{
92-
$tester = $this->createCommandTester();
117+
$tester = $this->createCommandTester($debug);
93118
$tester->execute(['name' => 'FrameworkBundle']);
94119

95120
$this->assertStringContainsString("cookie_httponly: '%env(bool:COOKIE_HTTPONLY)%'", $tester->getDisplay());
96121
}
97122

98-
public function testDumpFallsBackToDefaultConfigAndResolvesParameterValue()
123+
/**
124+
* @dataProvider provideDebugValues
125+
*/
126+
public function testDumpFallsBackToDefaultConfigAndResolvesParameterValue(bool $debug)
99127
{
100-
$tester = $this->createCommandTester();
128+
$tester = $this->createCommandTester($debug);
101129
$ret = $tester->execute(['name' => 'DefaultConfigTestBundle']);
102130

103131
$this->assertSame(0, $ret, 'Returns 0 in case of success');
104132
$this->assertStringContainsString('foo: bar', $tester->getDisplay());
105133
}
106134

107-
public function testDumpFallsBackToDefaultConfigAndResolvesEnvPlaceholder()
135+
/**
136+
* @dataProvider provideDebugValues
137+
*/
138+
public function testDumpFallsBackToDefaultConfigAndResolvesEnvPlaceholder(bool $debug)
108139
{
109-
$tester = $this->createCommandTester();
140+
$tester = $this->createCommandTester($debug);
110141
$ret = $tester->execute(['name' => 'DefaultConfigTestBundle']);
111142

112143
$this->assertSame(0, $ret, 'Returns 0 in case of success');
113144
$this->assertStringContainsString("baz: '%env(BAZ)%'", $tester->getDisplay());
114145
}
115146

116-
public function testDumpThrowsExceptionWhenDefaultConfigFallbackIsImpossible()
147+
/**
148+
* @dataProvider provideDebugValues
149+
*/
150+
public function testDumpThrowsExceptionWhenDefaultConfigFallbackIsImpossible(bool $debug)
117151
{
118152
$this->expectException(\LogicException::class);
119153
$this->expectExceptionMessage('The extension with alias "extension_without_config_test" does not have configuration.');
120154

121-
$tester = $this->createCommandTester();
155+
$tester = $this->createCommandTester($debug);
122156
$tester->execute(['name' => 'ExtensionWithoutConfigTestBundle']);
123157
}
124158

159+
public static function provideDebugValues(): iterable
160+
{
161+
yield [true];
162+
yield [false];
163+
}
164+
125165
/**
126166
* @dataProvider provideCompletionSuggestions
127167
*/
128-
public function testComplete(array $input, array $expectedSuggestions)
168+
public function testComplete(bool $debug, array $input, array $expectedSuggestions)
129169
{
130-
$this->application->add(new ConfigDebugCommand());
131-
132-
$tester = new CommandCompletionTester($this->application->get('debug:config'));
170+
$application = $this->createApplication($debug);
133171

172+
$application->add(new ConfigDebugCommand());
173+
$tester = new CommandCompletionTester($application->get('debug:config'));
134174
$suggestions = $tester->complete($input);
135175

136176
foreach ($expectedSuggestions as $expectedSuggestion) {
@@ -140,17 +180,32 @@ public function testComplete(array $input, array $expectedSuggestions)
140180

141181
public static function provideCompletionSuggestions(): \Generator
142182
{
143-
yield 'name' => [[''], ['default_config_test', 'extension_without_config_test', 'framework', 'test']];
183+
$name = ['default_config_test', 'extension_without_config_test', 'framework', 'test'];
184+
yield 'name, no debug' => [false, [''], $name];
185+
yield 'name, debug' => [true, [''], $name];
144186

145-
yield 'name (started CamelCase)' => [['Fra'], ['DefaultConfigTestBundle', 'ExtensionWithoutConfigTestBundle', 'FrameworkBundle', 'TestBundle']];
187+
$nameCamelCased = ['DefaultConfigTestBundle', 'ExtensionWithoutConfigTestBundle', 'FrameworkBundle', 'TestBundle'];
188+
yield 'name (started CamelCase), no debug' => [false, ['Fra'], $nameCamelCased];
189+
yield 'name (started CamelCase), debug' => [true, ['Fra'], $nameCamelCased];
146190

147-
yield 'name with existing path' => [['framework', ''], ['secret', 'router.resource', 'router.utf8', 'router.enabled', 'validation.enabled', 'default_locale']];
191+
$nameWithPath = ['secret', 'router.resource', 'router.utf8', 'router.enabled', 'validation.enabled', 'default_locale'];
192+
yield 'name with existing path, no debug' => [false, ['framework', ''], $nameWithPath];
193+
yield 'name with existing path, debug' => [true, ['framework', ''], $nameWithPath];
148194
}
149195

150-
private function createCommandTester(): CommandTester
196+
private function createCommandTester(bool $debug): CommandTester
151197
{
152-
$command = $this->application->find('debug:config');
198+
$command = $this->createApplication($debug)->find('debug:config');
153199

154200
return new CommandTester($command);
155201
}
202+
203+
private function createApplication(bool $debug): Application
204+
{
205+
$kernel = static::bootKernel(['debug' => $debug, 'test_case' => 'ConfigDump', 'root_config' => 'config.yml']);
206+
$application = new Application($kernel);
207+
$application->doRun(new ArrayInput([]), new NullOutput());
208+
209+
return $application;
210+
}
156211
}

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

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,45 +23,50 @@
2323
*/
2424
class ConfigDumpReferenceCommandTest extends AbstractWebTestCase
2525
{
26-
private $application;
27-
28-
protected function setUp(): void
29-
{
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());
33-
}
34-
35-
public function testDumpKernelExtension()
26+
/**
27+
* @dataProvider provideDebugValues
28+
*/
29+
public function testDumpKernelExtension(bool $debug)
3630
{
37-
$tester = $this->createCommandTester();
31+
$tester = $this->createCommandTester($debug);
3832
$ret = $tester->execute(['name' => 'foo']);
33+
34+
$this->assertSame(0, $ret, 'Returns 0 in case of success');
3935
$this->assertStringContainsString('foo:', $tester->getDisplay());
4036
$this->assertStringContainsString(' bar', $tester->getDisplay());
4137
}
4238

43-
public function testDumpBundleName()
39+
/**
40+
* @dataProvider provideDebugValues
41+
*/
42+
public function testDumpBundleName(bool $debug)
4443
{
45-
$tester = $this->createCommandTester();
44+
$tester = $this->createCommandTester($debug);
4645
$ret = $tester->execute(['name' => 'TestBundle']);
4746

4847
$this->assertSame(0, $ret, 'Returns 0 in case of success');
4948
$this->assertStringContainsString('test:', $tester->getDisplay());
5049
$this->assertStringContainsString(' custom:', $tester->getDisplay());
5150
}
5251

53-
public function testDumpExtensionConfigWithoutBundle()
52+
/**
53+
* @dataProvider provideDebugValues
54+
*/
55+
public function testDumpExtensionConfigWithoutBundle(bool $debug)
5456
{
55-
$tester = $this->createCommandTester();
57+
$tester = $this->createCommandTester($debug);
5658
$ret = $tester->execute(['name' => 'test_dump']);
5759

5860
$this->assertSame(0, $ret, 'Returns 0 in case of success');
5961
$this->assertStringContainsString('enabled: true', $tester->getDisplay());
6062
}
6163

62-
public function testDumpAtPath()
64+
/**
65+
* @dataProvider provideDebugValues
66+
*/
67+
public function testDumpAtPath(bool $debug)
6368
{
64-
$tester = $this->createCommandTester();
69+
$tester = $this->createCommandTester($debug);
6570
$ret = $tester->execute([
6671
'name' => 'test',
6772
'path' => 'array',
@@ -79,9 +84,12 @@ public function testDumpAtPath()
7984
, $tester->getDisplay(true));
8085
}
8186

82-
public function testDumpAtPathXml()
87+
/**
88+
* @dataProvider provideDebugValues
89+
*/
90+
public function testDumpAtPathXml(bool $debug)
8391
{
84-
$tester = $this->createCommandTester();
92+
$tester = $this->createCommandTester($debug);
8593
$ret = $tester->execute([
8694
'name' => 'test',
8795
'path' => 'array',
@@ -92,27 +100,49 @@ public function testDumpAtPathXml()
92100
$this->assertStringContainsString('[ERROR] The "path" option is only available for the "yaml" format.', $tester->getDisplay());
93101
}
94102

103+
public static function provideDebugValues(): iterable
104+
{
105+
yield [true];
106+
yield [false];
107+
}
108+
95109
/**
96110
* @dataProvider provideCompletionSuggestions
97111
*/
98-
public function testComplete(array $input, array $expectedSuggestions)
112+
public function testComplete(bool $debug, array $input, array $expectedSuggestions)
99113
{
100-
$this->application->add(new ConfigDumpReferenceCommand());
101-
$tester = new CommandCompletionTester($this->application->get('config:dump-reference'));
102-
$suggestions = $tester->complete($input, 2);
114+
$application = $this->createApplication($debug);
115+
116+
$application->add(new ConfigDumpReferenceCommand());
117+
$tester = new CommandCompletionTester($application->get('config:dump-reference'));
118+
$suggestions = $tester->complete($input);
103119
$this->assertSame($expectedSuggestions, $suggestions);
104120
}
105121

106122
public static function provideCompletionSuggestions(): iterable
107123
{
108-
yield 'name' => [[''], ['DefaultConfigTestBundle', 'default_config_test', 'ExtensionWithoutConfigTestBundle', 'extension_without_config_test', 'FrameworkBundle', 'framework', 'TestBundle', 'test']];
109-
yield 'option --format' => [['--format', ''], ['yaml', 'xml']];
124+
$name = ['DefaultConfigTestBundle', 'default_config_test', 'ExtensionWithoutConfigTestBundle', 'extension_without_config_test', 'FrameworkBundle', 'framework', 'TestBundle', 'test'];
125+
yield 'name, no debug' => [false, [''], $name];
126+
yield 'name, debug' => [true, [''], $name];
127+
128+
$optionFormat = ['yaml', 'xml'];
129+
yield 'option --format, no debug' => [false, ['--format', ''], $optionFormat];
130+
yield 'option --format, debug' => [true, ['--format', ''], $optionFormat];
110131
}
111132

112-
private function createCommandTester(): CommandTester
133+
private function createCommandTester(bool $debug): CommandTester
113134
{
114-
$command = $this->application->find('config:dump-reference');
135+
$command = $this->createApplication($debug)->find('config:dump-reference');
115136

116137
return new CommandTester($command);
117138
}
139+
140+
private function createApplication(bool $debug): Application
141+
{
142+
$kernel = static::createKernel(['debug' => $debug, 'test_case' => 'ConfigDump', 'root_config' => 'config.yml']);
143+
$application = new Application($kernel);
144+
$application->doRun(new ArrayInput([]), new NullOutput());
145+
146+
return $application;
147+
}
118148
}

0 commit comments

Comments
 (0)
0