@@ -47,6 +47,12 @@ protected function configure()
47
47
InputOption::VALUE_NONE ,
48
48
"creates xml report for executed test "
49
49
)
50
+ // ->addOption(
51
+ // 'no-ansi',
52
+ // 'no-ansi',
53
+ // InputOption::VALUE_NONE,
54
+ // "Disable ANSI"
55
+ // )
50
56
->addArgument (
51
57
'name ' ,
52
58
InputArgument::OPTIONAL | InputArgument::IS_ARRAY ,
@@ -168,6 +174,9 @@ private function runTests(array $tests, OutputInterface $output, InputInterface
168
174
$ xml = ($ input ->getOption ('xml ' ))
169
175
? '--xml '
170
176
: "" ;
177
+ $ noAnsi = ($ input ->getOption ('no-ansi ' ))
178
+ ? '--no-ansi '
179
+ : "" ;
171
180
if ($ this ->pauseEnabled ()) {
172
181
$ codeceptionCommand = self ::CODECEPT_RUN_FUNCTIONAL ;
173
182
} else {
@@ -196,7 +205,7 @@ private function runTests(array $tests, OutputInterface $output, InputInterface
196
205
$ this ->returnCode = max ($ this ->returnCode , $ this ->codeceptRunTest ($ fullCommand , $ output ));
197
206
} else {
198
207
$ 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 ));
200
209
}
201
210
if (!empty ($ xml )) {
202
211
$ this ->movingXMLFileFromSourceToDestination ($ xml , $ testName , $ output );
@@ -259,14 +268,19 @@ private function runTestsInSuite(array $suitesConfig, OutputInterface $output, I
259
268
*
260
269
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
261
270
*/
262
- private function executeTestCommand (string $ command , OutputInterface $ output )
271
+ private function executeTestCommand (string $ command , OutputInterface $ output, $ noAnsi )
263
272
{
264
273
$ process = Process::fromShellCommandline ($ command );
265
274
$ process ->setWorkingDirectory (TESTS_BP );
266
275
$ process ->setIdleTimeout (600 );
267
276
$ process ->setTimeout (0 );
268
277
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
+ }
270
284
$ output ->write ($ buffer );
271
285
});
272
286
}
0 commit comments