@@ -46,8 +46,7 @@ protected function configure()
4646 'xml ' ,
4747 InputOption::VALUE_NONE ,
4848 "creates xml report for executed test "
49- )
50- ->addArgument (
49+ )->addArgument (
5150 'name ' ,
5251 InputArgument::OPTIONAL | InputArgument::IS_ARRAY ,
5352 "name of tests to generate and execute "
@@ -128,7 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
128127 '--debug ' => $ debug ,
129128 '--allow-skipped ' => $ allowSkipped ,
130129 '-v ' => $ verbose ,
131- ''
130+ ''
132131 ];
133132 $ command ->run (new ArrayInput ($ args ), $ output );
134133
@@ -165,9 +164,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
165164 */
166165 private function runTests (array $ tests , OutputInterface $ output , InputInterface $ input )
167166 {
168- $ xml = ($ input ->getOption ('xml ' ))
169- ? '--xml '
170- : "" ;
167+ $ xml = ($ input ->getOption ('xml ' )) ? '--xml ' : "" ;
168+ $ noAnsi = ($ input ->getOption ('no-ansi ' )) ? '--no-ansi ' : "" ;
171169 if ($ this ->pauseEnabled ()) {
172170 $ codeceptionCommand = self ::CODECEPT_RUN_FUNCTIONAL ;
173171 } else {
@@ -196,7 +194,7 @@ private function runTests(array $tests, OutputInterface $output, InputInterface
196194 $ this ->returnCode = max ($ this ->returnCode , $ this ->codeceptRunTest ($ fullCommand , $ output ));
197195 } else {
198196 $ fullCommand = $ codeceptionCommand . $ testsDirectory . $ testName . ' --verbose --steps ' .$ xml ;
199- $ this ->returnCode = max ($ this ->returnCode , $ this ->executeTestCommand ($ fullCommand , $ output ));
197+ $ this ->returnCode = max ($ this ->returnCode , $ this ->executeTestCommand ($ fullCommand , $ output, $ noAnsi ));
200198 }
201199 if (!empty ($ xml )) {
202200 $ this ->movingXMLFileFromSourceToDestination ($ xml , $ testName , $ output );
@@ -217,9 +215,8 @@ private function runTests(array $tests, OutputInterface $output, InputInterface
217215 */
218216 private function runTestsInSuite (array $ suitesConfig , OutputInterface $ output , InputInterface $ input )
219217 {
220- $ xml = ($ input ->getOption ('xml ' ))
221- ? '--xml '
222- : "" ;
218+ $ xml = ($ input ->getOption ('xml ' )) ? '--xml ' : "" ;
219+ $ noAnsi = ($ input ->getOption ('no-ansi ' )) ? '--no-ansi ' : "" ;
223220 if ($ this ->pauseEnabled ()) {
224221 $ codeceptionCommand = self ::CODECEPT_RUN_FUNCTIONAL . '--verbose --steps --debug ' .$ xml ;
225222 } else {
@@ -240,7 +237,7 @@ private function runTestsInSuite(array $suitesConfig, OutputInterface $output, I
240237 }
241238 $ this ->returnCode = max ($ this ->returnCode , $ this ->codeceptRunTest ($ fullCommand , $ output ));
242239 } else {
243- $ this ->returnCode = max ($ this ->returnCode , $ this ->executeTestCommand ($ fullCommand , $ output ));
240+ $ this ->returnCode = max ($ this ->returnCode , $ this ->executeTestCommand ($ fullCommand , $ output, $ noAnsi ));
244241 }
245242 if (!empty ($ xml )) {
246243 $ this ->movingXMLFileFromSourceToDestination ($ xml , $ suite , $ output );
@@ -259,15 +256,31 @@ private function runTestsInSuite(array $suitesConfig, OutputInterface $output, I
259256 *
260257 * @SuppressWarnings(PHPMD.UnusedFormalParameter)
261258 */
262- private function executeTestCommand (string $ command , OutputInterface $ output )
259+ private function executeTestCommand (string $ command , OutputInterface $ output, $ noAnsi )
263260 {
264261 $ process = Process::fromShellCommandline ($ command );
265262 $ process ->setWorkingDirectory (TESTS_BP );
266263 $ process ->setIdleTimeout (600 );
267264 $ process ->setTimeout (0 );
268265
269- return $ process ->run (function ($ type , $ buffer ) use ($ output ) {
266+ return $ process ->run (function ($ type , $ buffer ) use ($ output , $ noAnsi ) {
267+ $ buffer = $ this ->disableAnsiColorCodes ($ buffer , $ noAnsi );
270268 $ output ->write ($ buffer );
271269 });
272270 }
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+ }
273286}
0 commit comments