55namespace Codeception \Module \Symfony ;
66
77use Symfony \Bundle \FrameworkBundle \Console \Application ;
8+ use Symfony \Component \Console \Output \OutputInterface ;
89use Symfony \Component \Console \Tester \CommandTester ;
910use Symfony \Component \HttpKernel \KernelInterface ;
1011
@@ -33,8 +34,10 @@ public function runSymfonyConsoleCommand(string $command, array $parameters = []
3334 $ commandTester = new CommandTester ($ consoleCommand );
3435 $ commandTester ->setInputs ($ consoleInputs );
3536
36- $ parameters = ['command ' => $ command ] + $ parameters ;
37- $ exitCode = $ commandTester ->execute ($ parameters );
37+ $ input = ['command ' => $ command ] + $ parameters ;
38+ $ options = $ this ->configureOptions ($ parameters );
39+
40+ $ exitCode = $ commandTester ->execute ($ input , $ options );
3841 $ output = $ commandTester ->getDisplay ();
3942
4043 $ this ->assertSame (
@@ -51,6 +54,49 @@ public function runSymfonyConsoleCommand(string $command, array $parameters = []
5154 return $ output ;
5255 }
5356
57+ private function configureOptions (array $ parameters ): array
58+ {
59+ $ options = [];
60+
61+ if (in_array ('--ansi ' , $ parameters , true )) {
62+ $ options ['decorated ' ] = true ;
63+ } elseif (in_array ('--no-ansi ' , $ parameters , true )) {
64+ $ options ['decorated ' ] = false ;
65+ }
66+
67+ if (in_array ('--no-interaction ' , $ parameters , true ) || in_array ('-n ' , $ parameters , true )) {
68+ $ options ['interactive ' ] = false ;
69+ }
70+
71+ if (in_array ('--quiet ' , $ parameters , true ) || in_array ('-q ' , $ parameters , true )) {
72+ $ options ['verbosity ' ] = OutputInterface::VERBOSITY_QUIET ;
73+ $ options ['interactive ' ] = false ;
74+ }
75+
76+ if (
77+ in_array ('-vvv ' , $ parameters , true ) ||
78+ in_array ('--verbose=3 ' , $ parameters , true ) ||
79+ (isset ($ parameters ["--verbose " ]) && $ parameters ["--verbose " ] === 3 )
80+ ) {
81+ $ options ['verbosity ' ] = OutputInterface::VERBOSITY_DEBUG ;
82+ } elseif (
83+ in_array ('-vv ' , $ parameters , true ) ||
84+ in_array ('--verbose=2 ' , $ parameters , true ) ||
85+ (isset ($ parameters ["--verbose " ]) && $ parameters ["--verbose " ] === 2 )
86+ ) {
87+ $ options ['verbosity ' ] = OutputInterface::VERBOSITY_VERY_VERBOSE ;
88+ } elseif (
89+ in_array ('-v ' , $ parameters , true ) ||
90+ in_array ('--verbose=1 ' , $ parameters , true ) ||
91+ in_array ('--verbose ' , $ parameters , true ) ||
92+ (isset ($ parameters ["--verbose " ]) && $ parameters ["--verbose " ] === 1 )
93+ ) {
94+ $ options ['verbosity ' ] = OutputInterface::VERBOSITY_VERBOSE ;
95+ }
96+
97+ return $ options ;
98+ }
99+
54100 protected function grabKernelService (): KernelInterface
55101 {
56102 return $ this ->grabService ('kernel ' );
0 commit comments