@@ -46,8 +46,7 @@ protected function configure()
46
46
'xml ' ,
47
47
InputOption::VALUE_NONE ,
48
48
"creates xml report for executed test "
49
- )
50
- ->addArgument (
49
+ )->addArgument (
51
50
'name ' ,
52
51
InputArgument::OPTIONAL | InputArgument::IS_ARRAY ,
53
52
"name of tests to generate and execute "
@@ -128,7 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
128
127
'--debug ' => $ debug ,
129
128
'--allow-skipped ' => $ allowSkipped ,
130
129
'-v ' => $ verbose ,
131
- ''
130
+ ''
132
131
];
133
132
$ command ->run (new ArrayInput ($ args ), $ output );
134
133
@@ -165,9 +164,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
165
164
*/
166
165
private function runTests (array $ tests , OutputInterface $ output , InputInterface $ input )
167
166
{
168
- $ xml = ($ input ->getOption ('xml ' ))
169
- ? '--xml '
170
- : "" ;
167
+ $ xml = ($ input ->getOption ('xml ' )) ? '--xml ' : "" ;
168
+ $ noAnsi = ($ input ->getOption ('no-ansi ' )) ? '--no-ansi ' : "" ;
171
169
if ($ this ->pauseEnabled ()) {
172
170
$ codeceptionCommand = self ::CODECEPT_RUN_FUNCTIONAL ;
173
171
} else {
@@ -196,7 +194,7 @@ private function runTests(array $tests, OutputInterface $output, InputInterface
196
194
$ this ->returnCode = max ($ this ->returnCode , $ this ->codeceptRunTest ($ fullCommand , $ output ));
197
195
} else {
198
196
$ 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 ));
200
198
}
201
199
if (!empty ($ xml )) {
202
200
$ this ->movingXMLFileFromSourceToDestination ($ xml , $ testName , $ output );
@@ -217,9 +215,8 @@ private function runTests(array $tests, OutputInterface $output, InputInterface
217
215
*/
218
216
private function runTestsInSuite (array $ suitesConfig , OutputInterface $ output , InputInterface $ input )
219
217
{
220
- $ xml = ($ input ->getOption ('xml ' ))
221
- ? '--xml '
222
- : "" ;
218
+ $ xml = ($ input ->getOption ('xml ' )) ? '--xml ' : "" ;
219
+ $ noAnsi = ($ input ->getOption ('no-ansi ' )) ? '--no-ansi ' : "" ;
223
220
if ($ this ->pauseEnabled ()) {
224
221
$ codeceptionCommand = self ::CODECEPT_RUN_FUNCTIONAL . '--verbose --steps --debug ' .$ xml ;
225
222
} else {
@@ -240,7 +237,7 @@ private function runTestsInSuite(array $suitesConfig, OutputInterface $output, I
240
237
}
241
238
$ this ->returnCode = max ($ this ->returnCode , $ this ->codeceptRunTest ($ fullCommand , $ output ));
242
239
} else {
243
- $ this ->returnCode = max ($ this ->returnCode , $ this ->executeTestCommand ($ fullCommand , $ output ));
240
+ $ this ->returnCode = max ($ this ->returnCode , $ this ->executeTestCommand ($ fullCommand , $ output, $ noAnsi ));
244
241
}
245
242
if (!empty ($ xml )) {
246
243
$ this ->movingXMLFileFromSourceToDestination ($ xml , $ suite , $ output );
@@ -259,15 +256,31 @@ private function runTestsInSuite(array $suitesConfig, OutputInterface $output, I
259
256
*
260
257
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
261
258
*/
262
- private function executeTestCommand (string $ command , OutputInterface $ output )
259
+ private function executeTestCommand (string $ command , OutputInterface $ output, $ noAnsi )
263
260
{
264
261
$ process = Process::fromShellCommandline ($ command );
265
262
$ process ->setWorkingDirectory (TESTS_BP );
266
263
$ process ->setIdleTimeout (600 );
267
264
$ process ->setTimeout (0 );
268
265
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 );
270
268
$ output ->write ($ buffer );
271
269
});
272
270
}
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
+ }
273
286
}
0 commit comments