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