Skip to content

Instantly share code, notes, and snippets.

@jaggy
Created February 12, 2014 05:26
Show Gist options
  • Save jaggy/8950466 to your computer and use it in GitHub Desktop.
Save jaggy/8950466 to your computer and use it in GitHub Desktop.
Parse the PHPUnit watcher with the --testdox parameter and colorize the output
<?php
class ParseShell extends AppShell
{
function main()
{
$this->stdout->styles( 'pass', [ 'text' => 'green' ] );
$this->stdout->styles( 'fail', [ 'text' => 'red' ] );
$this->stdout->styles( 'pending', [ 'text' => 'yellow' ] );
$watcher = ROOT . DS . APP_DIR . DS . 'watch.rb';
$command = "`which observr` {$watcher} 2>&1";
// pipe handle
$handle = popen( $command, 'r' );
// check to see if pipe is open
$pipe_is_open = !feof( $handle );
// loop through the pipe contents
while( $pipe_is_open )
{
// get the buffer
$buffer = fgets( $handle );
$buffer = str_replace( "\n", '', $buffer );
// check to see if the buffer is a test
$line_is_test = strstr( $buffer, '[' ) && strstr( $buffer, ']' );
if( $line_is_test )
{
// create a formatter
$formatter = ( strstr( $buffer, '[x]' ) ) ? '<pass>%f</pass>' : '<fail>%f</fail>';
// wrap the text with the tag
$buffer = str_replace( '%f', $buffer, $formatter );
}
$this->out( $buffer );
}
// close the pipe
pclose( $handle );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment