@@ -46,14 +46,7 @@ protected function configure()
4646 'xml ' ,
4747 InputOption::VALUE_NONE ,
4848 "creates xml report for executed test "
49- )
50- // ->addOption(
51- // 'no-ansi',
52- // 'no-ansi',
53- // InputOption::VALUE_NONE,
54- // "Disable ANSI"
55- // )
56- ->addArgument (
49+ )->addArgument (
5750 'name ' ,
5851 InputArgument::OPTIONAL | InputArgument::IS_ARRAY ,
5952 "name of tests to generate and execute "
@@ -134,7 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
134127 '--debug ' => $ debug ,
135128 '--allow-skipped ' => $ allowSkipped ,
136129 '-v ' => $ verbose ,
137- ''
130+ ''
138131 ];
139132 $ command ->run (new ArrayInput ($ args ), $ output );
140133
@@ -171,12 +164,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
171164 */
172165 private function runTests (array $ tests , OutputInterface $ output , InputInterface $ input )
173166 {
174- $ xml = ($ input ->getOption ('xml ' ))
175- ? '--xml '
176- : "" ;
177- $ noAnsi = ($ input ->getOption ('no-ansi ' ))
178- ? '--no-ansi '
179- : "" ;
167+ $ xml = ($ input ->getOption ('xml ' )) ? '--xml ' : "" ;
168+ $ noAnsi = ($ input ->getOption ('no-ansi ' )) ? '--no-ansi ' : "" ;
180169 if ($ this ->pauseEnabled ()) {
181170 $ codeceptionCommand = self ::CODECEPT_RUN_FUNCTIONAL ;
182171 } else {
@@ -226,9 +215,8 @@ private function runTests(array $tests, OutputInterface $output, InputInterface
226215 */
227216 private function runTestsInSuite (array $ suitesConfig , OutputInterface $ output , InputInterface $ input )
228217 {
229- $ xml = ($ input ->getOption ('xml ' ))
230- ? '--xml '
231- : "" ;
218+ $ xml = ($ input ->getOption ('xml ' )) ? '--xml ' : "" ;
219+ $ noAnsi = ($ input ->getOption ('no-ansi ' )) ? '--no-ansi ' : "" ;
232220 if ($ this ->pauseEnabled ()) {
233221 $ codeceptionCommand = self ::CODECEPT_RUN_FUNCTIONAL . '--verbose --steps --debug ' .$ xml ;
234222 } else {
@@ -249,7 +237,7 @@ private function runTestsInSuite(array $suitesConfig, OutputInterface $output, I
249237 }
250238 $ this ->returnCode = max ($ this ->returnCode , $ this ->codeceptRunTest ($ fullCommand , $ output ));
251239 } else {
252- $ this ->returnCode = max ($ this ->returnCode , $ this ->executeTestCommand ($ fullCommand , $ output ));
240+ $ this ->returnCode = max ($ this ->returnCode , $ this ->executeTestCommand ($ fullCommand , $ output, $ noAnsi ));
253241 }
254242 if (!empty ($ xml )) {
255243 $ this ->movingXMLFileFromSourceToDestination ($ xml , $ suite , $ output );
@@ -276,12 +264,23 @@ private function executeTestCommand(string $command, OutputInterface $output, $n
276264 $ process ->setTimeout (0 );
277265
278266 return $ process ->run (function ($ type , $ buffer ) use ($ output , $ noAnsi ) {
279- if ($ noAnsi != "" ) {
280- $ pattern = "/ \x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[m|K]/ " ;
281- // Use preg_replace to remove ANSI escape codes from the string
282- $ buffer = preg_replace ($ pattern , '' , $ buffer );
283- }
267+ $ buffer = $ this ->disableAnsiColorCodes ($ buffer , $ noAnsi );
284268 $ output ->write ($ buffer );
285269 });
286270 }
271+
272+ /**
273+ * @param string $buffer
274+ * @param string $noAnsi
275+ * @return string
276+ */
277+ private function disableAnsiColorCodes ($ buffer , $ noAnsi ) :string
278+ {
279+ if (empty ($ noAnsi )) {
280+ return $ buffer ;
281+ }
282+ $ pattern = "/ \x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[m|K]/ " ;
283+ // Use preg_replace to remove ANSI escape codes from the string
284+ return preg_replace ($ pattern , '' , $ buffer );
285+ }
287286}
0 commit comments