1919use Symfony \Component \Console \Completion \CompletionSuggestions ;
2020use Symfony \Component \Console \Completion \Output \BashCompletionOutput ;
2121use Symfony \Component \Console \Input \InputArgument ;
22+ use Symfony \Component \Console \Input \InputOption ;
2223use Symfony \Component \Console \Output \OutputInterface ;
2324use Symfony \Component \Console \Tester \CommandTester ;
2425
@@ -34,6 +35,8 @@ protected function setUp(): void
3435
3536 $ this ->application = new Application ();
3637 $ this ->application ->add (new CompleteCommandTest_HelloCommand ());
38+ $ this ->application ->getDefinition ()
39+ ->addOption (new InputOption ('global-option ' , null , InputOption::VALUE_REQUIRED , suggestedValues: ['foo ' , 'bar ' , 'baz ' ]));
3740
3841 $ this ->command ->setApplication ($ this ->application );
3942 $ this ->tester = new CommandTester ($ this ->command );
@@ -119,10 +122,12 @@ public function testCompleteCommandInputDefinition(array $input, array $suggesti
119122
120123 public static function provideCompleteCommandInputDefinitionInputs ()
121124 {
122- yield 'definition ' => [['bin/console ' , 'hello ' , '- ' ], ['--help ' , '--quiet ' , '--verbose ' , '--version ' , '--ansi ' , '--no-ansi ' , '--no-interaction ' ]];
125+ yield 'definition ' => [['bin/console ' , 'hello ' , '- ' ], ['--help ' , '--quiet ' , '--verbose ' , '--version ' , '--ansi ' , '--no-ansi ' , '--no-interaction ' , ' --global-option ' ]];
123126 yield 'custom ' => [['bin/console ' , 'hello ' ], ['Fabien ' , 'Robin ' , 'Wouter ' ]];
124- yield 'definition-aliased ' => [['bin/console ' , 'ahoy ' , '- ' ], ['--help ' , '--quiet ' , '--verbose ' , '--version ' , '--ansi ' , '--no-ansi ' , '--no-interaction ' ]];
127+ yield 'definition-aliased ' => [['bin/console ' , 'ahoy ' , '- ' ], ['--help ' , '--quiet ' , '--verbose ' , '--version ' , '--ansi ' , '--no-ansi ' , '--no-interaction ' , ' --global-option ' ]];
125128 yield 'custom-aliased ' => [['bin/console ' , 'ahoy ' ], ['Fabien ' , 'Robin ' , 'Wouter ' ]];
129+ yield 'global-option-values ' => [['bin/console ' , '--global-option ' ], ['foo ' , 'bar ' , 'baz ' ]];
130+ yield 'global-option-with-command-values ' => [['bin/console ' , 'ahoy ' , '--global-option ' ], ['foo ' , 'bar ' , 'baz ' ]];
126131 }
127132
128133 private function execute (array $ input )
@@ -147,6 +152,10 @@ public function complete(CompletionInput $input, CompletionSuggestions $suggesti
147152 {
148153 if ($ input ->mustSuggestArgumentValuesFor ('name ' )) {
149154 $ suggestions ->suggestValues (['Fabien ' , 'Robin ' , 'Wouter ' ]);
155+
156+ return ;
150157 }
158+
159+ parent ::complete ($ input , $ suggestions );
151160 }
152161}
0 commit comments