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 testDefaultParameterValueIsResolvedIfConfigIsExisting ()
80
+ /**
81
+ * @testWith [true]
82
+ * [false]
83
+ */
84
+ public function testDefaultParameterValueIsResolvedIfConfigIsExisting (bool $ debug )
64
85
{
65
- $ tester = $ this ->createCommandTester ();
86
+ $ tester = $ this ->createCommandTester ($ debug );
66
87
$ ret = $ tester ->execute (['name ' => 'framework ' ]);
67
88
68
89
$ this ->assertSame (0 , $ ret , 'Returns 0 in case of success ' );
69
- $ kernelCacheDir = $ this -> application -> getKernel () ->getContainer ()->getParameter ('kernel.cache_dir ' );
90
+ $ kernelCacheDir = self :: $ kernel ->getContainer ()->getParameter ('kernel.cache_dir ' );
70
91
$ this ->assertStringContainsString (sprintf ("dsn: 'file:%s/profiler' " , $ kernelCacheDir ), $ tester ->getDisplay ());
71
92
}
72
93
73
- public function testDumpExtensionConfigWithoutBundle ()
94
+ /**
95
+ * @testWith [true]
96
+ * [false]
97
+ */
98
+ public function testDumpExtensionConfigWithoutBundle (bool $ debug )
74
99
{
75
- $ tester = $ this ->createCommandTester ();
100
+ $ tester = $ this ->createCommandTester ($ debug );
76
101
$ ret = $ tester ->execute (['name ' => 'test_dump ' ]);
77
102
78
103
$ this ->assertSame (0 , $ ret , 'Returns 0 in case of success ' );
79
104
$ this ->assertStringContainsString ('enabled: true ' , $ tester ->getDisplay ());
80
105
}
81
106
82
- public function testDumpUndefinedBundleOption ()
107
+ /**
108
+ * @testWith [true]
109
+ * [false]
110
+ */
111
+ public function testDumpUndefinedBundleOption (bool $ debug )
83
112
{
84
- $ tester = $ this ->createCommandTester ();
113
+ $ tester = $ this ->createCommandTester ($ debug );
85
114
$ tester ->execute (['name ' => 'TestBundle ' , 'path ' => 'foo ' ]);
86
115
87
116
$ this ->assertStringContainsString ('Unable to find configuration for "test.foo" ' , $ tester ->getDisplay ());
88
117
}
89
118
90
- public function testDumpWithPrefixedEnv ()
119
+ /**
120
+ * @testWith [true]
121
+ * [false]
122
+ */
123
+ public function testDumpWithPrefixedEnv (bool $ debug )
91
124
{
92
- $ tester = $ this ->createCommandTester ();
125
+ $ tester = $ this ->createCommandTester ($ debug );
93
126
$ tester ->execute (['name ' => 'FrameworkBundle ' ]);
94
127
95
128
$ this ->assertStringContainsString ("cookie_httponly: '%env(bool:COOKIE_HTTPONLY)%' " , $ tester ->getDisplay ());
96
129
}
97
130
98
- public function testDumpFallsBackToDefaultConfigAndResolvesParameterValue ()
131
+ /**
132
+ * @testWith [true]
133
+ * [false]
134
+ */
135
+ public function testDumpFallsBackToDefaultConfigAndResolvesParameterValue (bool $ debug )
99
136
{
100
- $ tester = $ this ->createCommandTester ();
137
+ $ tester = $ this ->createCommandTester ($ debug );
101
138
$ ret = $ tester ->execute (['name ' => 'DefaultConfigTestBundle ' ]);
102
139
103
140
$ this ->assertSame (0 , $ ret , 'Returns 0 in case of success ' );
104
141
$ this ->assertStringContainsString ('foo: bar ' , $ tester ->getDisplay ());
105
142
}
106
143
107
- public function testDumpFallsBackToDefaultConfigAndResolvesEnvPlaceholder ()
144
+ /**
145
+ * @testWith [true]
146
+ * [false]
147
+ */
148
+ public function testDumpFallsBackToDefaultConfigAndResolvesEnvPlaceholder (bool $ debug )
108
149
{
109
- $ tester = $ this ->createCommandTester ();
150
+ $ tester = $ this ->createCommandTester ($ debug );
110
151
$ ret = $ tester ->execute (['name ' => 'DefaultConfigTestBundle ' ]);
111
152
112
153
$ this ->assertSame (0 , $ ret , 'Returns 0 in case of success ' );
113
154
$ this ->assertStringContainsString ("baz: '%env(BAZ)%' " , $ tester ->getDisplay ());
114
155
}
115
156
116
- public function testDumpThrowsExceptionWhenDefaultConfigFallbackIsImpossible ()
157
+ /**
158
+ * @testWith [true]
159
+ * [false]
160
+ */
161
+ public function testDumpThrowsExceptionWhenDefaultConfigFallbackIsImpossible (bool $ debug )
117
162
{
118
163
$ this ->expectException (\LogicException::class);
119
164
$ this ->expectExceptionMessage ('The extension with alias "extension_without_config_test" does not have configuration. ' );
120
165
121
- $ tester = $ this ->createCommandTester ();
166
+ $ tester = $ this ->createCommandTester ($ debug );
122
167
$ tester ->execute (['name ' => 'ExtensionWithoutConfigTestBundle ' ]);
123
168
}
124
169
125
170
/**
126
171
* @dataProvider provideCompletionSuggestions
127
172
*/
128
- public function testComplete (array $ input , array $ expectedSuggestions )
173
+ public function testComplete (bool $ debug , array $ input , array $ expectedSuggestions )
129
174
{
130
- $ this ->application ->add (new ConfigDebugCommand ());
131
-
132
- $ tester = new CommandCompletionTester ($ this ->application ->get ('debug:config ' ));
175
+ $ application = $ this ->createApplication ($ debug );
133
176
177
+ $ application ->add (new ConfigDebugCommand ());
178
+ $ tester = new CommandCompletionTester ($ application ->get ('debug:config ' ));
134
179
$ suggestions = $ tester ->complete ($ input );
135
180
136
181
foreach ($ expectedSuggestions as $ expectedSuggestion ) {
@@ -140,17 +185,32 @@ public function testComplete(array $input, array $expectedSuggestions)
140
185
141
186
public static function provideCompletionSuggestions (): \Generator
142
187
{
143
- yield 'name ' => [['' ], ['default_config_test ' , 'extension_without_config_test ' , 'framework ' , 'test ' ]];
188
+ $ name = ['default_config_test ' , 'extension_without_config_test ' , 'framework ' , 'test ' ];
189
+ yield 'name, no debug ' => [false , ['' ], $ name ];
190
+ yield 'name, debug ' => [true , ['' ], $ name ];
144
191
145
- yield 'name (started CamelCase) ' => [['Fra ' ], ['DefaultConfigTestBundle ' , 'ExtensionWithoutConfigTestBundle ' , 'FrameworkBundle ' , 'TestBundle ' ]];
192
+ $ nameCamelCased = ['DefaultConfigTestBundle ' , 'ExtensionWithoutConfigTestBundle ' , 'FrameworkBundle ' , 'TestBundle ' ];
193
+ yield 'name (started CamelCase), no debug ' => [false , ['Fra ' ], $ nameCamelCased ];
194
+ yield 'name (started CamelCase), debug ' => [true , ['Fra ' ], $ nameCamelCased ];
146
195
147
- yield 'name with existing path ' => [['framework ' , '' ], ['secret ' , 'router.resource ' , 'router.utf8 ' , 'router.enabled ' , 'validation.enabled ' , 'default_locale ' ]];
196
+ $ nameWithPath = ['secret ' , 'router.resource ' , 'router.utf8 ' , 'router.enabled ' , 'validation.enabled ' , 'default_locale ' ];
197
+ yield 'name with existing path, no debug ' => [false , ['framework ' , '' ], $ nameWithPath ];
198
+ yield 'name with existing path, debug ' => [true , ['framework ' , '' ], $ nameWithPath ];
148
199
}
149
200
150
- private function createCommandTester (): CommandTester
201
+ private function createCommandTester (bool $ debug ): CommandTester
151
202
{
152
- $ command = $ this ->application ->find ('debug:config ' );
203
+ $ command = $ this ->createApplication ( $ debug ) ->find ('debug:config ' );
153
204
154
205
return new CommandTester ($ command );
155
206
}
207
+
208
+ private function createApplication (bool $ debug ): Application
209
+ {
210
+ $ kernel = static ::bootKernel (['debug ' => $ debug , 'test_case ' => 'ConfigDump ' , 'root_config ' => 'config.yml ' ]);
211
+ $ application = new Application ($ kernel );
212
+ $ application ->doRun (new ArrayInput ([]), new NullOutput ());
213
+
214
+ return $ application ;
215
+ }
156
216
}
0 commit comments