|
14 | 14 | use Symfony\Bundle\FrameworkBundle\Console\Application;
|
15 | 15 | use Symfony\Bundle\FrameworkBundle\Tests\Fixtures\BackslashClass;
|
16 | 16 | use Symfony\Component\Console\Tester\ApplicationTester;
|
| 17 | +use Symfony\Component\Console\Tester\CommandCompletionTester; |
17 | 18 |
|
18 | 19 | /**
|
19 | 20 | * @group functional
|
@@ -211,4 +212,68 @@ public function provideIgnoreBackslashWhenFindingService()
|
211 | 212 | ['\\'.BackslashClass::class],
|
212 | 213 | ];
|
213 | 214 | }
|
| 215 | + |
| 216 | + /** |
| 217 | + * @dataProvider provideCompletionSuggestions |
| 218 | + */ |
| 219 | + public function testComplete(array $input, array $expectedSuggestions, array $notExpectedSuggestions = []) |
| 220 | + { |
| 221 | + static::bootKernel(['test_case' => 'ContainerDebug', 'root_config' => 'config.yml', 'debug' => true]); |
| 222 | + |
| 223 | + $application = new Application(static::$kernel); |
| 224 | + $tester = new CommandCompletionTester($application->find('debug:container')); |
| 225 | + $suggestions = $tester->complete($input); |
| 226 | + |
| 227 | + foreach ($expectedSuggestions as $expectedSuggestion) { |
| 228 | + $this->assertContains($expectedSuggestion, $suggestions); |
| 229 | + } |
| 230 | + foreach ($notExpectedSuggestions as $notExpectedSuggestion) { |
| 231 | + $this->assertNotContains($notExpectedSuggestion, $suggestions); |
| 232 | + } |
| 233 | + } |
| 234 | + |
| 235 | + public function provideCompletionSuggestions() |
| 236 | + { |
| 237 | + $serviceId = 'console.command.container_debug'; |
| 238 | + $hiddenServiceId = '.console.command.container_debug.lazy'; |
| 239 | + $interfaceServiceId = 'Symfony\Component\HttpKernel\HttpKernelInterface'; |
| 240 | + |
| 241 | + yield 'name' => [ |
| 242 | + [''], |
| 243 | + [$serviceId, $interfaceServiceId], |
| 244 | + [$hiddenServiceId], |
| 245 | + ]; |
| 246 | + |
| 247 | + yield 'name (with hidden)' => [ |
| 248 | + ['--show-hidden', ''], |
| 249 | + [$serviceId, $interfaceServiceId, $hiddenServiceId], |
| 250 | + ]; |
| 251 | + |
| 252 | + yield 'name (with current value)' => [ |
| 253 | + ['--show-hidden', 'console'], |
| 254 | + [$serviceId, $hiddenServiceId], |
| 255 | + [$interfaceServiceId], |
| 256 | + ]; |
| 257 | + |
| 258 | + yield 'name (no suggestion with --tags)' => [ |
| 259 | + ['--tags', ''], |
| 260 | + [], |
| 261 | + [$serviceId, $interfaceServiceId, $hiddenServiceId], |
| 262 | + ]; |
| 263 | + |
| 264 | + yield 'option --tag' => [ |
| 265 | + ['--tag', ''], |
| 266 | + ['console.command'], |
| 267 | + ]; |
| 268 | + |
| 269 | + yield 'option --parameter' => [ |
| 270 | + ['--parameter', ''], |
| 271 | + ['kernel.debug'], |
| 272 | + ]; |
| 273 | + |
| 274 | + yield 'option --format' => [ |
| 275 | + ['--format', ''], |
| 276 | + ['txt', 'xml', 'json', 'md'], |
| 277 | + ]; |
| 278 | + } |
214 | 279 | }
|
0 commit comments