So I have PHPUnit running in PHPStorm 7.1, but I can't find out how to get the ANSI color codes working from within tests. My PHPunit.xml has colors = "true" in the property list, but every time I try something like:
echo "\033[31mError! Error!\033[0m\n";
Inside one of my test cases, it just gives me:
[31mError! Error
class Display
{
/**
 * The escape sequence that clears any active styling on the terminal.
 */
const CLEAR = "\e[0m";
/**
 * Warning escape sequence which sets the background color to red and the
 * foreground to white.
 */
const WARNING = "\e[41;97m";
/**
 * Caution escape sequence which sets the background color to yellow and the
 * foreground to black.
 */
const CAUTION = "\e[43;30m";
/**
 * OK escape sequence which sets the background color to green and the
 * foreground to black.
 */
const OK      = "\e[42;30m";
/**
 * Display the text with a red background and white foreground
 * and end it with the newline character (if desired)
 *
 * @param mixed $text - the text of the message
 * @param boolean $newline - whether to append a new line
 * 
 * @return string - the escaped sequence and the optional newline
 */
public static function warning($text, $newline = true) {
    // echo the string surrounded with the escape coding to
    // display a warning
    $text = self::WARNING . $text . self::CLEAR;
    // if a carriage return was desired, send it out
    $text .= $newline ? "\n" : "";
    // return the escaped text
    return $text;
}
/**
 * Display the text with a yellow background and black foreground
 * and end it with the newline character (if desired)
 *
 * @param mixed $text - the text of the message
 * @param boolean $newline - whether to append a new line
 * 
 * @return string - the escaped sequence and the optional newline
 */
public static function caution($text, $newline = true) {
    // echo the string surrounded with the escape coding to
    // display a cautionary message
    $text = self::CAUTION . $text . self::CLEAR;
    // if a carriage return was desired, send it out
    $text .= $newline ? "\n" : "";
    // return the escaped text
    return $text;
}
/**
 * Display the text with a green background and black foreground
 * and end it with the newline character (if desired)
 *
 * @param mixed $text - the text of the message
 * @param boolean $newline - whether to append a new line
 * 
 * @return string - the escaped sequence and the optional newline
 */
public static function OK($text, $newline = true) {
    // echo the string surrounded with the escape coding to
    // display a positive message
    $text = self::OK . $text . self::CLEAR;
    // if a carriage return was desired, send it out
    $text .= $newline ? "\n" : "";
    // return the escaped text
    return $text;
}
                        PhpStorm has special integration script to run PHPUnit tests (all messages/progress indicators are transferred into GUI part where you can easily see what tests have passed and what did not etc).
PhpStorm's console does not support ANSI colors -- http://youtrack.jetbrains.com/issue/IDEA-69880 and related tickets.
But you can install Grep Console plugin and it will add support for ANSI colors (needs to be activated in Settings). I have tried it with PHPUnit and it worked -- not everything was colored (some of the codes were not recognized, but most worked). You can contact plugin author with not working parts if desired.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With