/** * Echo $msg in $color * @param $eol Print end of line */ public function report($msg = '', $color = null, $eol = true) { $msg = $color ? EscapeColors::fg_color($color, $msg) : $msg; $msg = $eol ? $msg . PHP_EOL : $msg; echo $msg; }
<?php $pass = EscapeColors::green('PASS'); $fail = EscapeColors::red('FAIL'); /** * TEST version PHP */ $test = phpversion() > 5.4 ? $pass : $fail; echo 'PHP version > 5.4 (' . phpversion() . ')' . "\t" . $test . "\n"; /** * Test module intl */ $test = extension_loaded('intl') ? $pass : $fail; echo 'Module intl loaded: ' . "\t\t" . $test . "\n"; /** * DO NOT TOUCH BELOW */ /** * Color escapes for bash output */ class EscapeColors { private static $foreground = array('black' => '0;30', 'dark_gray' => '1;30', 'red' => '0;31', 'bold_red' => '1;31', 'green' => '0;32', 'bold_green' => '1;32', 'brown' => '0;33', 'yellow' => '1;33', 'blue' => '0;34', 'bold_blue' => '1;34', 'purple' => '0;35', 'bold_purple' => '1;35', 'cyan' => '0;36', 'bold_cyan' => '1;36', 'white' => '1;37', 'bold_gray' => '0;37'); private static $background = array('black' => '40', 'red' => '41', 'magenta' => '45', 'yellow' => '43', 'green' => '42', 'blue' => '44', 'cyan' => '46', 'light_gray' => '47'); /** * Make string appear in color */ public static function fg_color($color, $string) { if (!isset(self::$foreground[$color])) { throw new \Exception('Foreground color is not defined');
public function testCallStatic_GreenBg() { $greenMsg = EscapeColors::green("My message", 'bg'); $realGreenMsg = "[42mMy message[0m"; $this->assertEquals($realGreenMsg, $greenMsg, 'Green text'); }