Skip to content

Instantly share code, notes, and snippets.

@twmbx
Last active December 20, 2015 23:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twmbx/e36affb956420ba8d582 to your computer and use it in GitHub Desktop.
Save twmbx/e36affb956420ba8d582 to your computer and use it in GitHub Desktop.
Robo PHP: PHPunit & PHPspec with notifications
<?php
/**
* @Author Twaambo Haamucenje
* @Email contact@twaambo.com
*
* better phpunit and phpspec tests with linux desktop notifications using Robo PHP
*
* @see http://robo.li/
*/
class RoboFile extends \Robo\Tasks
{
// define public methods as commands
private $paths = ['app', 'config', 'tests'];
public function tdd(){
$this->taskWatch()->monitor( $paths, function(){
$this->test();
})->run();
}
public function test(){
if( $this->taskPHPUnit()->run()->wasSuccessful() ){
$this->notify( 'pass', 'phpunit' );
} else {
$this->notify( 'fail', 'phpunit' );
}
if( $this->taskPhpspec()
->format('pretty')
->noInteraction()
->run()
->wasSuccessful() ){
$this->notify( 'pass', 'phpspec' );
} else {
$this->notify( 'fail', 'phpspec' );
}
}
public function notify( $status, $test ){
$icon = ( $status == 'pass' ) ? '~/bin/icons/pass.png' : '~/bin/icons/fail.png';
$title = ( $test == 'phpunit' ) ? 'PHP Unit' : 'PHP Spec';
$message = ( $status == 'pass' ) ? 'Tests Passed!' : 'Tests Failed!!';
$notification = "notify-send '".$title."' '".$message."' -i '".$icon."'";
$this->_exec( $notification );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment