@@ -46,14 +46,7 @@ protected function configure()
46
46
'xml ' ,
47
47
InputOption::VALUE_NONE ,
48
48
"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 (
57
50
'name ' ,
58
51
InputArgument::OPTIONAL | InputArgument::IS_ARRAY ,
59
52
"name of tests to generate and execute "
@@ -134,7 +127,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
134
127
'--debug ' => $ debug ,
135
128
'--allow-skipped ' => $ allowSkipped ,
136
129
'-v ' => $ verbose ,
137
- ''
130
+ ''
138
131
];
139
132
$ command ->run (new ArrayInput ($ args ), $ output );
140
133
@@ -171,12 +164,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
171
164
*/
172
165
private function runTests (array $ tests , OutputInterface $ output , InputInterface $ input )
173
166
{
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 ' : "" ;
180
169
if ($ this ->pauseEnabled ()) {
181
170
$ codeceptionCommand = self ::CODECEPT_RUN_FUNCTIONAL ;
182
171
} else {
@@ -226,9 +215,8 @@ private function runTests(array $tests, OutputInterface $output, InputInterface
226
215
*/
227
216
private function runTestsInSuite (array $ suitesConfig , OutputInterface $ output , InputInterface $ input )
228
217
{
229
- $ xml = ($ input ->getOption ('xml ' ))
230
- ? '--xml '
231
- : "" ;
218
+ $ xml = ($ input ->getOption ('xml ' )) ? '--xml ' : "" ;
219
+ $ noAnsi = ($ input ->getOption ('no-ansi ' )) ? '--no-ansi ' : "" ;
232
220
if ($ this ->pauseEnabled ()) {
233
221
$ codeceptionCommand = self ::CODECEPT_RUN_FUNCTIONAL . '--verbose --steps --debug ' .$ xml ;
234
222
} else {
@@ -249,7 +237,7 @@ private function runTestsInSuite(array $suitesConfig, OutputInterface $output, I
249
237
}
250
238
$ this ->returnCode = max ($ this ->returnCode , $ this ->codeceptRunTest ($ fullCommand , $ output ));
251
239
} else {
252
- $ this ->returnCode = max ($ this ->returnCode , $ this ->executeTestCommand ($ fullCommand , $ output ));
240
+ $ this ->returnCode = max ($ this ->returnCode , $ this ->executeTestCommand ($ fullCommand , $ output, $ noAnsi ));
253
241
}
254
242
if (!empty ($ xml )) {
255
243
$ this ->movingXMLFileFromSourceToDestination ($ xml , $ suite , $ output );
@@ -276,12 +264,23 @@ private function executeTestCommand(string $command, OutputInterface $output, $n
276
264
$ process ->setTimeout (0 );
277
265
278
266
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 );
284
268
$ output ->write ($ buffer );
285
269
});
286
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
+ }
287
286
}
0 commit comments