Skip to content

Commit eb7d262

Browse files
committed
ACQE-5706 : no-ansi fix
1 parent 0ad02f1 commit eb7d262

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,8 @@ protected function configure()
6464
*/
6565
protected function execute(InputInterface $input, OutputInterface $output): int
6666
{
67-
$xml = ($input->getOption('xml'))
68-
? '--xml'
69-
: "";
70-
$noAnsi = ($input->getOption('no-ansi'))
71-
? '--no-ansi'
72-
: "";
67+
$xml = ($input->getOption('xml')) ? '--xml' : "";
68+
$noAnsi = ($input->getOption('no-ansi')) ? '--no-ansi' : "";
7369
$skipGeneration = $input->getOption('skip-generate');
7470
$force = $input->getOption('force');
7571
$groups = $input->getArgument('groups');
@@ -140,11 +136,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
140136
$process->setTimeout(0);
141137
$returnCodes[] = $process->run(
142138
function ($type, $buffer) use ($output, $noAnsi) {
143-
if ($noAnsi != "") {
144-
$pattern = "/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[m|K]/";
145-
// Use preg_replace to remove ANSI escape codes from the string
146-
$buffer = preg_replace($pattern, '', $buffer);
147-
}
139+
$buffer = $this->disableAnsiColorCodes($buffer, $noAnsi);
148140
$output->write($buffer);
149141
}
150142
);
@@ -167,4 +159,19 @@ function ($type, $buffer) use ($output, $noAnsi) {
167159
}
168160
return max($exitCode, $generationErrorCode);
169161
}
162+
163+
/**
164+
* @param string $buffer
165+
* @param string $noAnsi
166+
* @return string
167+
*/
168+
private function disableAnsiColorCodes($buffer, $noAnsi) :string
169+
{
170+
if (empty($noAnsi)) {
171+
return $buffer;
172+
}
173+
$pattern = "/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[m|K]/";
174+
// Use preg_replace to remove ANSI escape codes from the string
175+
return preg_replace($pattern, '', $buffer);
176+
}
170177
}

0 commit comments

Comments
 (0)