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