You are here

protected function PHPUnit_TextUI_ResultPrinter::formatWithColor in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php \PHPUnit_TextUI_ResultPrinter::formatWithColor()

Formats a buffer with a specified ANSI color sequence if colors are enabled.

@since Method available since Release 4.0.0

Parameters

string $color:

string $buffer:

Return value

string

2 calls to PHPUnit_TextUI_ResultPrinter::formatWithColor()
PHPUnit_TextUI_ResultPrinter::writeProgressWithColor in vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php
Writes progress with a color sequence if colors are enabled.
PHPUnit_TextUI_ResultPrinter::writeWithColor in vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php
Writes a buffer out with a color sequence if colors are enabled.

File

vendor/phpunit/phpunit/src/TextUI/ResultPrinter.php, line 558

Class

PHPUnit_TextUI_ResultPrinter
Prints the result of a TextUI TestRunner run.

Code

protected function formatWithColor($color, $buffer) {
  if (!$this->colors) {
    return $buffer;
  }
  $codes = array_map('trim', explode(',', $color));
  $lines = explode("\n", $buffer);
  $padding = max(array_map('strlen', $lines));
  $styles = array();
  foreach ($codes as $code) {
    $styles[] = self::$ansiCodes[$code];
  }
  $style = sprintf("\33[%sm", implode(';', $styles));
  $styledLines = array();
  foreach ($lines as $line) {
    $styledLines[] = $style . str_pad($line, $padding) . "\33[0m";
  }
  return implode("\n", $styledLines);
}