Changeset 163

Show
Ignore:
Timestamp:
05/24/08 22:59:48 (8 months ago)
Author:
iteman
Message:

- Added support for Growl. (Ticket #21)

Location:
trunk/src/Stagehand
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/Stagehand/TestRunner.php

    r148 r163  
    143143  -a        watch for changes in one or more directories and run tests in the test directory recursively when changes are detected (autotest) 
    144144  -w <directory1,directory2,...> specify one or more directories to be watched for changes 
     145  -g        notify test results to Growl 
    145146 
    146147With no [directory or file], run all tests in the current directory. 
     
    231232        } 
    232233 
     234        if ($config->useGrowl) { 
     235            $options[] = '-g'; 
     236        } 
     237 
    233238        $options[] = $config->directory; 
    234239 
     
    260265        array_shift($argv); 
    261266        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); 
    262         $allOptions = Console_Getopt::getopt2($argv, 'hVRcp:aw:'); 
     267        $allOptions = Console_Getopt::getopt2($argv, 'hVRcp:aw:g'); 
    263268        PEAR::staticPopErrorHandling(); 
    264269        if (PEAR::isError($allOptions)) { 
     
    272277        $preloadFile = null; 
    273278        $targetDirectories = array(); 
     279        $useGrowl = false; 
    274280        foreach ($allOptions as $options) { 
    275281            if (!count($options)) { 
     
    303309                        $targetDirectories = explode(',', $option[1]); 
    304310                        break; 
     311                    case 'g': 
     312                        if (@include_once 'Net/Growl.php') { 
     313                            $useGrowl = true; 
     314                        } 
     315                        break; 
    305316                    } 
    306317                } else { 
     
    315326                             'enableAutotest' => $enableAutotest, 
    316327                             'preloadFile' => $preloadFile, 
    317                              'targetDirectories' => $targetDirectories 
     328                             'targetDirectories' => $targetDirectories, 
     329                             'useGrowl' => $useGrowl 
    318330                             ); 
    319331    } 
     
    339351        $className = "Stagehand_TestRunner_Runner_$testRunnerName"; 
    340352        $runner = new $className(); 
    341         $runner->run($suite, $config->color); 
     353        $runner->run($suite, $config); 
     354 
     355        if ($config->useGrowl) { 
     356            $notification = $runner->getNotification(); 
     357            $application = new Net_Growl_Application('Stagehand_TestRunner', 
     358                                                     array('Green', 'Red') 
     359                                                     ); 
     360            $growl = new Net_Growl($application); 
     361            $growl->notify($notification->name, 
     362                           'Test Results by Stagehand_TestRunner', 
     363                           $notification->description 
     364                           ); 
     365        } 
    342366    } 
    343367 
  • trunk/src/Stagehand/TestRunner/IRunner.php

    r120 r163  
    6060     * Runs tests based on the given test suite. 
    6161     * 
    62      * @param mixed   $suite 
    63      * @param boolean $color 
     62     * @param mixed    $suite 
     63     * @param stdClass $config 
    6464     */ 
    65     public function run($suite, $color); 
     65    public function run($suite, $config); 
     66 
     67    // }}} 
     68    // {{{ getNotification() 
     69 
     70    /** 
     71     * Gets a notification object for Growl. 
     72     * 
     73     * @return stdClass 
     74     */ 
     75    public function getNotification(); 
    6676 
    6777    /**#@-*/ 
  • trunk/src/Stagehand/TestRunner/Runner/PHPSpec.php

    r120 r163  
    7474     */ 
    7575 
     76    private $_notification; 
     77 
    7678    /**#@-*/ 
    7779 
     
    8789     * 
    8890     * @param ArrayObject $suite 
    89      * @param boolean     $color 
     91     * @param stdClass    $config 
    9092     */ 
    91     public function run($suite, $color) 
     93    public function run($suite, $config) 
    9294    { 
    9395        $result = new PHPSpec_Runner_Result(); 
    94         $reporter = new Stagehand_TestRunner_Runner_PHPSpec_Reporter($result, $color); 
     96        $reporter = new Stagehand_TestRunner_Runner_PHPSpec_Reporter($result, 
     97                                                                     $config->color 
     98                                                                     ); 
    9599        $result->setReporter($reporter); 
    96100 
     
    103107 
    104108        $reporter->output(true); 
     109 
     110        if ($config->useGrowl) { 
     111            $output = $reporter->toString(true); 
     112 
     113            $failuresCount = $result->countFailures(); 
     114            $deliberateFailuresCount = $result->countDeliberateFailures(); 
     115            $errorsCount = $result->countErrors(); 
     116            $exceptionsCount = $result->countExceptions(); 
     117            $pendingsCount = $result->countPending(); 
     118 
     119            $this->_notification = new stdClass(); 
     120            if ($failuresCount + $deliberateFailuresCount + $errorsCount + $exceptionsCount + $pendingsCount == 0) { 
     121                $this->_notification->name = 'Green'; 
     122            } elseif ($pendingsCount && $failuresCount + $deliberateFailuresCount + $errorsCount + $exceptionsCount == 0) { 
     123                $this->_notification->name = 'Green'; 
     124            } else { 
     125                $this->_notification->name = 'Red'; 
     126            } 
     127 
     128            preg_match('/^(\d+ examples?, \d+ failures?.*)/m', $output, $matches); 
     129            $this->_notification->description = $matches[1]; 
     130        } 
     131    } 
     132 
     133    // }}} 
     134    // {{{ getNotification() 
     135 
     136    /** 
     137     * Gets a notification object for Growl. 
     138     * 
     139     * @return stdClass 
     140     */ 
     141    public function getNotification() 
     142    { 
     143        return $this->_notification; 
    105144    } 
    106145 
  • trunk/src/Stagehand/TestRunner/Runner/PHPUnit.php

    r139 r163  
    7575     */ 
    7676 
     77    private $_notification; 
     78 
    7779    /**#@-*/ 
    7880 
     
    8890     * 
    8991     * @param PHPUnit_Framework_TestSuite $suite 
    90      * @param boolean                     $color 
     92     * @param stdClass                    $config 
    9193     */ 
    92     public function run($suite, $color) 
     94    public function run($suite, $config) 
    9395    { 
    9496        $parameters = array(); 
    95         if ($color) { 
     97        if ($config->color) { 
    9698            include_once 'Stagehand/TestRunner/Runner/PHPUnit/ResultPrinter.php'; 
    9799            $parameters['printer'] = new Stagehand_TestRunner_Runner_PHPUnit_ResultPrinter(); 
    98100        } 
    99101 
     102        ob_start(); 
    100103        PHPUnit_TextUI_TestRunner::run($suite, $parameters); 
     104        $output = ob_get_contents(); 
     105        ob_end_clean(); 
     106 
     107        print $output; 
     108 
     109        if ($config->useGrowl) { 
     110            if (preg_match('/^(?:\x1b\[3[23]m)?(OK[^\x1b]+)/ms', $output, $matches)) { 
     111                $this->_notification->name = 'Green'; 
     112                $this->_notification->description = $matches[1]; 
     113            } elseif (preg_match('/^(?:\x1b\[31m)?(FAILURES[^\x1b]+)/ms', $output, $matches)) { 
     114                $this->_notification->name = 'Red'; 
     115                $this->_notification->description = $matches[1]; 
     116            } 
     117        } 
     118    } 
     119 
     120    // }}} 
     121    // {{{ getNotification() 
     122 
     123    /** 
     124     * Gets a notification object for Growl. 
     125     * 
     126     * @return stdClass 
     127     */ 
     128    public function getNotification() 
     129    { 
     130        return $this->_notification; 
    101131    } 
    102132 
  • trunk/src/Stagehand/TestRunner/Runner/SimpleTest.php

    r120 r163  
    7676     */ 
    7777 
     78    private $_notification; 
     79 
    7880    /**#@-*/ 
    7981 
     
    8991     * 
    9092     * @param TestSuite $suite 
    91      * @param boolean   $color 
     93     * @param stdClass  $config 
    9294     */ 
    93     public function run($suite, $color) 
     95    public function run($suite, $config) 
    9496    { 
    9597        $reporter = new TextReporter(); 
     
    99101        ob_end_clean(); 
    100102 
    101         if ($color) { 
     103        if ($config->useGrowl) { 
     104            if (preg_match('/^(OK.+)/ms', $output, $matches)) { 
     105                $this->_notification->name = 'Green'; 
     106                $this->_notification->description = $matches[1]; 
     107            } elseif (preg_match('/^(FAILURES.+)/ms', $output, $matches)) { 
     108                $this->_notification->name = 'Red'; 
     109                $this->_notification->description = $matches[1]; 
     110            } 
     111        } 
     112 
     113        if ($config->color) { 
    102114            include_once 'Console/Color.php'; 
    103115            print Console_Color::convert(preg_replace(array('/^(OK.+)/ms', 
     
    116128            print $output; 
    117129        } 
     130    } 
     131 
     132    // }}} 
     133    // {{{ getNotification() 
     134 
     135    /** 
     136     * Gets a notification object for Growl. 
     137     * 
     138     * @return stdClass 
     139     */ 
     140    public function getNotification() 
     141    { 
     142        return $this->_notification; 
    118143    } 
    119144