Created
February 12, 2014 05:26
-
-
Save jaggy/8950466 to your computer and use it in GitHub Desktop.
Parse the PHPUnit watcher with the --testdox parameter and colorize the output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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