@@ -47,6 +47,12 @@ protected function configure()
4747 InputOption::VALUE_NONE ,
4848 "creates xml report for executed test "
4949 )
50+ // ->addOption(
51+ // 'no-ansi',
52+ // 'no-ansi',
53+ // InputOption::VALUE_NONE,
54+ // "Disable ANSI"
55+ // )
5056 ->addArgument (
5157 'name ' ,
5258 InputArgument::OPTIONAL | InputArgument::IS_ARRAY ,
@@ -168,6 +174,9 @@ private function runTests(array $tests, OutputInterface $output, InputInterface
168174 $ xml = ($ input ->getOption ('xml ' ))
169175 ? '--xml '
170176 : "" ;
177+ $ noAnsi = ($ input ->getOption ('no-ansi ' ))
178+ ? '--no-ansi '
179+ : "" ;
171180 if ($ this ->pauseEnabled ()) {
172181 $ codeceptionCommand = self ::CODECEPT_RUN_FUNCTIONAL ;
173182 } else {
@@ -196,7 +205,7 @@ private function runTests(array $tests, OutputInterface $output, InputInterface
196205 $ this ->returnCode = max ($ this ->returnCode , $ this ->codeceptRunTest ($ fullCommand , $ output ));
197206 } else {
198207 $ fullCommand = $ codeceptionCommand . $ testsDirectory . $ testName . ' --verbose --steps ' .$ xml ;
199- $ this ->returnCode = max ($ this ->returnCode , $ this ->executeTestCommand ($ fullCommand , $ output ));
208+ $ this ->returnCode = max ($ this ->returnCode , $ this ->executeTestCommand ($ fullCommand , $ output, $ noAnsi ));
200209 }
201210 if (!empty ($ xml )) {
202211 $ this ->movingXMLFileFromSourceToDestination ($ xml , $ testName , $ output );
@@ -259,14 +268,19 @@ private function runTestsInSuite(array $suitesConfig, OutputInterface $output, I
259268 *
260269 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
261270 */
262- private function executeTestCommand (string $ command , OutputInterface $ output )
271+ private function executeTestCommand (string $ command , OutputInterface $ output, $ noAnsi )
263272 {
264273 $ process = Process::fromShellCommandline ($ command );
265274 $ process ->setWorkingDirectory (TESTS_BP );
266275 $ process ->setIdleTimeout (600 );
267276 $ process ->setTimeout (0 );
268277
269- return $ process ->run (function ($ type , $ buffer ) use ($ output ) {
278+ 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+ }
270284 $ output ->write ($ buffer );
271285 });
272286 }
0 commit comments