$codes = array(); isset($parameters['fg']) and $codes[] = $foreground[$parameters['fg']]; isset($parameters['bg']) and $codes[] = $background[$parameters['bg']]; foreach ($options as $option => $value) { isset($parameters[$option]) && $parameters[$option] and $codes[] = $value; } return "[" . implode(';', $codes) . 'm' . $text . "[0m"; } } lime_colorizer::style('ERROR', array('bg' => 'red', 'fg' => 'white', 'bold' => true)); lime_colorizer::style('INFO', array('fg' => 'green', 'bold' => true)); lime_colorizer::style('PARAMETER', array('fg' => 'cyan')); lime_colorizer::style('COMMENT', array('fg' => 'yellow')); lime_colorizer::style('GREEN_BAR', array('fg' => 'white', 'bg' => 'green', 'bold' => true)); lime_colorizer::style('RED_BAR', array('fg' => 'white', 'bg' => 'red', 'bold' => true)); lime_colorizer::style('INFO_BAR', array('fg' => 'cyan', 'bold' => true)); class lime_harness extends lime_registration { public $options = array(); public $php_cli = null; public $stats = array(); public $output = null; public function __construct($options = array()) { // for BC if (!is_array($options)) { $options = array('output' => $options); } $this->options = array_merge(array('php_cli' => null, 'force_colors' => false, 'output' => null, 'verbose' => false), $options); $this->php_cli = $this->find_php_cli($this->options['php_cli']); $this->output = $this->options['output'] ? $this->options['output'] : new lime_output($this->options['force_colors']);
!is_array($parameters) && isset(self::$styles[$parameters]) and $parameters = self::$styles[$parameters]; $codes = array(); isset($parameters['fg']) and $codes[] = $foreground[$parameters['fg']]; isset($parameters['bg']) and $codes[] = $background[$parameters['bg']]; foreach ($options as $option => $value) { isset($parameters[$option]) && $parameters[$option] and $codes[] = $value; } return "[" . implode(';', $codes) . 'm' . $text . "[0m"; } } lime_colorizer::style('ERROR', array('bg' => 'red', 'fg' => 'white', 'bold' => true)); lime_colorizer::style('INFO', array('fg' => 'green', 'bold' => true)); lime_colorizer::style('PARAMETER', array('fg' => 'cyan')); lime_colorizer::style('COMMENT', array('fg' => 'yellow')); lime_colorizer::style('GREEN_BAR', array('fg' => 'white', 'bg' => 'green', 'bold' => true)); lime_colorizer::style('RED_BAR', array('fg' => 'white', 'bg' => 'red', 'bold' => true)); class lime_harness extends lime_registration { public $php_cli = ''; public $stats = array(); public $output = null; function __construct($output_instance, $php_cli = null) { if (getenv('PHP_PATH')) { $this->php_cli = getenv('PHP_PATH'); if (!is_executable($this->php_cli)) { throw new Exception('The defined PHP_PATH environment variable is not a valid PHP executable.'); } } $this->php_cli = null === $php_cli ? PHP_BINDIR . DIRECTORY_SEPARATOR . 'php' : $php_cli; if (!is_executable($this->php_cli)) {
isset($parameters[$option]) && $parameters[$option] and $codes[] = $value; } return "[" . implode(';', $codes) . 'm' . $text . "[0m"; } } lime_colorizer::style('ERROR', array('bg' => 'red', 'fg' => 'white', 'bold' => true)); lime_colorizer::style('INFO', array('fg' => 'green', 'bold' => true)); lime_colorizer::style('TRACE', array('fg' => 'green', 'bold' => true)); lime_colorizer::style('PARAMETER', array('fg' => 'cyan')); lime_colorizer::style('COMMENT', array('fg' => 'yellow')); lime_colorizer::style('GREEN_BAR', array('fg' => 'white', 'bg' => 'green', 'bold' => true)); lime_colorizer::style('RED_BAR', array('fg' => 'white', 'bg' => 'red', 'bold' => true)); lime_colorizer::style('YELLOW_BAR', array('fg' => 'black', 'bg' => 'yellow', 'bold' => true)); lime_colorizer::style('INFO_BAR', array('fg' => 'cyan', 'bold' => true)); lime_colorizer::style('DIFF_DELETED', array('fg' => 'red', 'bold' => true)); lime_colorizer::style('DIFF_ADDED', array('fg' => 'green', 'bold' => true)); /** * lime_harness class. * * @extends lime_registration * @package lime */ class lime_harness extends lime_registration { public $options = array(); public $php_cli = null; public $stats = array(); public $output = null; public function __construct($options = array()) { // for BC
static $foreground = array('black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'white' => 37); static $background = array('black' => 40, 'red' => 41, 'green' => 42, 'yellow' => 43, 'blue' => 44, 'magenta' => 45, 'cyan' => 46, 'white' => 47); !is_array($parameters) && isset(self::$styles[$parameters]) and $parameters = self::$styles[$parameters]; $codes = array(); isset($parameters['fg']) and $codes[] = $foreground[$parameters['fg']]; isset($parameters['bg']) and $codes[] = $background[$parameters['bg']]; foreach ($options as $option => $value) { isset($parameters[$option]) && $parameters[$option] and $codes[] = $value; } return "[" . implode(';', $codes) . 'm' . $text . "[0m"; } } lime_colorizer::style('ERROR', array('bg' => 'red', 'fg' => 'white', 'bold' => true)); lime_colorizer::style('INFO', array('fg' => 'green', 'bold' => true)); lime_colorizer::style('PARAMETER', array('fg' => 'cyan')); lime_colorizer::style('COMMENT', array('fg' => 'yellow')); class lime_harness extends lime_registration { public $php_cli = ''; public $stats = array(); public $output = null; function __construct($output_instance, $php_cli = null) { $this->php_cli = null === $php_cli ? PHP_BINDIR . DIRECTORY_SEPARATOR . 'php' : $php_cli; if (!is_executable($this->php_cli)) { $this->php_cli = $this->find_php_cli(); } $this->output = $output_instance ? $output_instance : new lime_output(); } protected function find_php_cli() {
<?php /* * This file is part of the Lime framework. * * (c) Fabien Potencier <*****@*****.**> * (c) Bernhard Schussek <*****@*****.**> * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ $t = new LimeTest(); $t->diag('Text can be colorized with font and color styles'); $c = new LimeColorizer(); $t->is($c->colorize('Hello World', array('bold' => true)), "[1mHello World[0m", 'Text can be bold'); $t->is($c->colorize('Hello World', array('underscore' => true)), "[4mHello World[0m", 'Text can be underscored'); $t->is($c->colorize('Hello World', array('blink' => true)), "[5mHello World[0m", 'Text can be blinking'); $t->is($c->colorize('Hello World', array('reverse' => true)), "[7mHello World[0m", 'Text can be reversed'); $t->is($c->colorize('Hello World', array('conceal' => true)), "[8mHello World[0m", 'Text can be invisible'); $t->is($c->colorize('Hello World', array('fg' => 'white')), "[37mHello World[0m", 'Text can have a custom text color'); $t->is($c->colorize('Hello World', array('bg' => 'white')), "[47mHello World[0m", 'Text can have a custom background color'); $t->is($c->colorize('Hello World', array('bold' => true, 'fg' => 'black', 'bg' => 'white')), "[30;47;1mHello World[0m", 'Styles can be combined'); $t->diag('Text styles can be preset using ->setStyle()'); $c = new LimeColorizer(); $c->setStyle('test_style', array('bold' => true, 'fg' => 'black', 'bg' => 'white')); $t->is($c->colorize('Hello World', 'test_style'), "[30;47;1mHello World[0m", 'Predefined styles can be used'); $t->diag('Text styles can be preset using backwards compatible ::style()'); LimeAutoloader::enableLegacyMode(); lime_colorizer::style('test_style', array('bold' => true, 'fg' => 'black', 'bg' => 'white')); $c = new lime_colorizer(); $t->is($c->colorize('Hello World', 'test_style'), "[30;47;1mHello World[0m", 'Predefined styles can be used');