24
24
*/
25
25
class ConfigDebugCommandTest extends AbstractWebTestCase
26
26
{
27
- private $ application ;
28
-
29
- protected function setUp (): void
27
+ /**
28
+ * @testWith [true]
29
+ * [false]
30
+ */
31
+ public function testDumpKernelExtension (bool $ debug )
30
32
{
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 ());
34
39
}
35
40
36
- public function testDumpBundleName ()
41
+ /**
42
+ * @testWith [true]
43
+ * [false]
44
+ */
45
+ public function testDumpBundleName (bool $ debug )
37
46
{
38
- $ tester = $ this ->createCommandTester ();
47
+ $ tester = $ this ->createCommandTester ($ debug );
39
48
$ ret = $ tester ->execute (['name ' => 'TestBundle ' ]);
40
49
41
50
$ this ->assertSame (0 , $ ret , 'Returns 0 in case of success ' );
42
51
$ this ->assertStringContainsString ('custom: foo ' , $ tester ->getDisplay ());
43
52
}
44
53
45
- public function testDumpBundleOption ()
54
+ /**
55
+ * @testWith [true]
56
+ * [false]
57
+ */
58
+ public function testDumpBundleOption (bool $ debug )
46
59
{
47
- $ tester = $ this ->createCommandTester ();
60
+ $ tester = $ this ->createCommandTester ($ debug );
48
61
$ ret = $ tester ->execute (['name ' => 'TestBundle ' , 'path ' => 'custom ' ]);
49
62
50
63
$ this ->assertSame (0 , $ ret , 'Returns 0 in case of success ' );
51
64
$ this ->assertStringContainsString ('foo ' , $ tester ->getDisplay ());
52
65
}
53
66
54
- public function testDumpWithUnsupportedFormat ()
67
+ /**
68
+ * @testWith [true]
69
+ * [false]
70
+ */
71
+ public function testDumpWithUnsupportedFormat (bool $ debug )
55
72
{
56
- $ tester = $ this ->createCommandTester ();
73
+ $ tester = $ this ->createCommandTester ($ debug );
57
74
58
75
$ this ->expectException (InvalidArgumentException::class);
59
76
$ this ->expectExceptionMessage ('Supported formats are "yaml", "json" ' );
@@ -64,19 +81,27 @@ public function testDumpWithUnsupportedFormat()
64
81
]);
65
82
}
66
83
67
- public function testParametersValuesAreResolved ()
84
+ /**
85
+ * @testWith [true]
86
+ * [false]
87
+ */
88
+ public function testParametersValuesAreResolved (bool $ debug )
68
89
{
69
- $ tester = $ this ->createCommandTester ();
90
+ $ tester = $ this ->createCommandTester ($ debug );
70
91
$ ret = $ tester ->execute (['name ' => 'framework ' ]);
71
92
72
93
$ this ->assertSame (0 , $ ret , 'Returns 0 in case of success ' );
73
94
$ this ->assertStringContainsString ("locale: '%env(LOCALE)%' " , $ tester ->getDisplay ());
74
95
$ this ->assertStringContainsString ('secret: test ' , $ tester ->getDisplay ());
75
96
}
76
97
77
- public function testParametersValuesAreFullyResolved ()
98
+ /**
99
+ * @testWith [true]
100
+ * [false]
101
+ */
102
+ public function testParametersValuesAreFullyResolved (bool $ debug )
78
103
{
79
- $ tester = $ this ->createCommandTester ();
104
+ $ tester = $ this ->createCommandTester ($ debug );
80
105
$ ret = $ tester ->execute (['name ' => 'framework ' , '--resolve-env ' => true ]);
81
106
82
107
$ this ->assertSame (0 , $ ret , 'Returns 0 in case of success ' );
@@ -86,77 +111,105 @@ public function testParametersValuesAreFullyResolved()
86
111
$ this ->assertStringContainsString ('ide: ' .($ _ENV ['SYMFONY_IDE ' ] ?? $ _SERVER ['SYMFONY_IDE ' ] ?? 'null ' ), $ tester ->getDisplay ());
87
112
}
88
113
89
- public function testDefaultParameterValueIsResolvedIfConfigIsExisting ()
114
+ /**
115
+ * @testWith [true]
116
+ * [false]
117
+ */
118
+ public function testDefaultParameterValueIsResolvedIfConfigIsExisting (bool $ debug )
90
119
{
91
- $ tester = $ this ->createCommandTester ();
120
+ $ tester = $ this ->createCommandTester ($ debug );
92
121
$ ret = $ tester ->execute (['name ' => 'framework ' ]);
93
122
94
123
$ 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 ' );
96
125
$ this ->assertStringContainsString (sprintf ("dsn: 'file:%s/profiler' " , $ kernelCacheDir ), $ tester ->getDisplay ());
97
126
}
98
127
99
- public function testDumpExtensionConfigWithoutBundle ()
128
+ /**
129
+ * @testWith [true]
130
+ * [false]
131
+ */
132
+ public function testDumpExtensionConfigWithoutBundle (bool $ debug )
100
133
{
101
- $ tester = $ this ->createCommandTester ();
134
+ $ tester = $ this ->createCommandTester ($ debug );
102
135
$ ret = $ tester ->execute (['name ' => 'test_dump ' ]);
103
136
104
137
$ this ->assertSame (0 , $ ret , 'Returns 0 in case of success ' );
105
138
$ this ->assertStringContainsString ('enabled: true ' , $ tester ->getDisplay ());
106
139
}
107
140
108
- public function testDumpUndefinedBundleOption ()
141
+ /**
142
+ * @testWith [true]
143
+ * [false]
144
+ */
145
+ public function testDumpUndefinedBundleOption (bool $ debug )
109
146
{
110
- $ tester = $ this ->createCommandTester ();
147
+ $ tester = $ this ->createCommandTester ($ debug );
111
148
$ tester ->execute (['name ' => 'TestBundle ' , 'path ' => 'foo ' ]);
112
149
113
150
$ this ->assertStringContainsString ('Unable to find configuration for "test.foo" ' , $ tester ->getDisplay ());
114
151
}
115
152
116
- public function testDumpWithPrefixedEnv ()
153
+ /**
154
+ * @testWith [true]
155
+ * [false]
156
+ */
157
+ public function testDumpWithPrefixedEnv (bool $ debug )
117
158
{
118
- $ tester = $ this ->createCommandTester ();
159
+ $ tester = $ this ->createCommandTester ($ debug );
119
160
$ tester ->execute (['name ' => 'FrameworkBundle ' ]);
120
161
121
162
$ this ->assertStringContainsString ("cookie_httponly: '%env(bool:COOKIE_HTTPONLY)%' " , $ tester ->getDisplay ());
122
163
}
123
164
124
- public function testDumpFallsBackToDefaultConfigAndResolvesParameterValue ()
165
+ /**
166
+ * @testWith [true]
167
+ * [false]
168
+ */
169
+ public function testDumpFallsBackToDefaultConfigAndResolvesParameterValue (bool $ debug )
125
170
{
126
- $ tester = $ this ->createCommandTester ();
171
+ $ tester = $ this ->createCommandTester ($ debug );
127
172
$ ret = $ tester ->execute (['name ' => 'DefaultConfigTestBundle ' ]);
128
173
129
174
$ this ->assertSame (0 , $ ret , 'Returns 0 in case of success ' );
130
175
$ this ->assertStringContainsString ('foo: bar ' , $ tester ->getDisplay ());
131
176
}
132
177
133
- public function testDumpFallsBackToDefaultConfigAndResolvesEnvPlaceholder ()
178
+ /**
179
+ * @testWith [true]
180
+ * [false]
181
+ */
182
+ public function testDumpFallsBackToDefaultConfigAndResolvesEnvPlaceholder (bool $ debug )
134
183
{
135
- $ tester = $ this ->createCommandTester ();
184
+ $ tester = $ this ->createCommandTester ($ debug );
136
185
$ ret = $ tester ->execute (['name ' => 'DefaultConfigTestBundle ' ]);
137
186
138
187
$ this ->assertSame (0 , $ ret , 'Returns 0 in case of success ' );
139
188
$ this ->assertStringContainsString ("baz: '%env(BAZ)%' " , $ tester ->getDisplay ());
140
189
}
141
190
142
- public function testDumpThrowsExceptionWhenDefaultConfigFallbackIsImpossible ()
191
+ /**
192
+ * @testWith [true]
193
+ * [false]
194
+ */
195
+ public function testDumpThrowsExceptionWhenDefaultConfigFallbackIsImpossible (bool $ debug )
143
196
{
144
197
$ this ->expectException (\LogicException::class);
145
198
$ this ->expectExceptionMessage ('The extension with alias "extension_without_config_test" does not have configuration. ' );
146
199
147
- $ tester = $ this ->createCommandTester ();
200
+ $ tester = $ this ->createCommandTester ($ debug );
148
201
$ tester ->execute (['name ' => 'ExtensionWithoutConfigTestBundle ' ]);
149
202
}
150
203
151
204
/**
152
205
* @dataProvider provideCompletionSuggestions
153
206
*/
154
- public function testComplete (array $ input , array $ expectedSuggestions )
207
+ public function testComplete (bool $ debug , array $ input , array $ expectedSuggestions )
155
208
{
156
- $ this ->application ->add (new ConfigDebugCommand ());
157
-
158
- $ tester = new CommandCompletionTester ($ this ->application ->get ('debug:config ' ));
209
+ $ application = $ this ->createApplication ($ debug );
159
210
211
+ $ application ->add (new ConfigDebugCommand ());
212
+ $ tester = new CommandCompletionTester ($ application ->get ('debug:config ' ));
160
213
$ suggestions = $ tester ->complete ($ input );
161
214
162
215
foreach ($ expectedSuggestions as $ expectedSuggestion ) {
@@ -166,19 +219,35 @@ public function testComplete(array $input, array $expectedSuggestions)
166
219
167
220
public static function provideCompletionSuggestions (): \Generator
168
221
{
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 ];
170
225
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 ];
172
229
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 ];
174
233
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 ' ]];
176
236
}
177
237
178
- private function createCommandTester (): CommandTester
238
+ private function createCommandTester (bool $ debug ): CommandTester
179
239
{
180
- $ command = $ this ->application ->find ('debug:config ' );
240
+ $ command = $ this ->createApplication ( $ debug ) ->find ('debug:config ' );
181
241
182
242
return new CommandTester ($ command );
183
243
}
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
+ }
184
253
}
0 commit comments