Changeset 165

Show
Ignore:
Timestamp:
05/25/08 12:55:44 (8 months ago)
Author:
iteman
Message:

- Refactored.

Location:
trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • trunk/bin/specrunner

    r160 r165  
    4545require_once 'Stagehand/TestRunner.php'; 
    4646 
    47 $result = Stagehand_TestRunner::run('PHPSpec'); 
     47$runner = new Stagehand_TestRunner('PHPSpec'); 
     48$result = $runner->run(); 
    4849 
    4950exit($result); 
  • trunk/bin/testrunner

    r160 r165  
    4545require_once 'Stagehand/TestRunner.php'; 
    4646 
    47 $result = Stagehand_TestRunner::run('PHPUnit'); 
     47$runner = new Stagehand_TestRunner('PHPUnit'); 
     48$result = $runner->run(); 
    4849 
    4950exit($result); 
  • trunk/bin/testrunner-st

    r160 r165  
    4545require_once 'Stagehand/TestRunner.php'; 
    4646 
    47 $result = Stagehand_TestRunner::run('SimpleTest'); 
     47$runner = new Stagehand_TestRunner('SimpleTest'); 
     48$result = $runner->run(); 
    4849 
    4950exit($result); 
  • trunk/src/Stagehand/TestRunner.php

    r163 r165  
    7272     */ 
    7373 
     74    private $_testRunnerName; 
     75    private $_config; 
     76 
    7477    /**#@-*/ 
    7578 
     
    7780     * @access public 
    7881     */ 
     82 
     83    // }}} 
     84    // {{{ __construct() 
     85 
     86    /** 
     87     * @param string $testRunnerName 
     88     */ 
     89    public function __construct($testRunnerName) 
     90    { 
     91        $this->_testRunnerName = $testRunnerName; 
     92    } 
    7993 
    8094    // }}} 
     
    8498     * Runs tests automatically. 
    8599     * 
    86      * @param string $testRunnerName 
    87      */ 
    88     public static function run($testRunnerName) 
     100     * @return integer 
     101     */ 
     102    public function run() 
    89103    { 
    90104        if (!array_key_exists('argv', $_SERVER)) { 
     
    94108 
    95109        try { 
    96             $config = self::_parseOptions(); 
    97             if (is_null($config)) { 
     110            $this->_config = $this->_parseOptions(); 
     111            if (is_null($this->_config)) { 
    98112                return 1; 
    99113            } 
    100114 
    101             if (!$config->enableAutotest) { 
    102                 self::_runTests($testRunnerName, $config); 
     115            if (!$this->_config->enableAutotest) { 
     116                $this->_runTests(); 
    103117            } else { 
    104                 self::_monitorAlteration($config); 
     118                $this->_monitorAlteration(); 
    105119            } 
    106120        } catch (Stagehand_TestRunner_Exception $e) { 
    107121            echo 'ERROR: ' . $e->getMessage() . "\n"; 
    108             self::_displayUsage(); 
     122            $this->_displayUsage(); 
    109123            return 1; 
    110124        } 
     
    131145     * Displays the usage. 
    132146     */ 
    133     private static function _displayUsage() 
     147    private function _displayUsage() 
    134148    { 
    135149        echo "Usage: {$_SERVER['SCRIPT_NAME']} [options] [directory or file] 
     
    155169     * Displays the version. 
    156170     */ 
    157     private static function _displayVersion() 
    158     { 
    159         echo "Stagehand_TestRunner @package_version@ 
     171    private function _displayVersion() 
     172    { 
     173        echo "Stagehand_TestRunner @package_version@ ({$this->_testRunnerName}) 
    160174 
    161175Copyright (c) 2005-2008 KUBO Atsuhiro <iteman@users.sourceforge.net>, 
     
    173187     * directory is always added to the target directories. 
    174188     * 
    175      * @param stdClass $config 
    176189     * @throws Stagehand_TestRunner_Exception 
    177190     * @since Method available since Release 2.1.0 
    178191     */ 
    179     private static function _monitorAlteration($config) 
     192    private function _monitorAlteration() 
    180193    { 
    181194        $targetDirectories = array(); 
    182         foreach (array_merge($config->targetDirectories, (array)$config->directory) 
     195        foreach (array_merge($this->_config->targetDirectories, (array)$this->_config->directory) 
    183196                 as $directory 
    184197                 ) { 
     
    224237        $options[] = '-R'; 
    225238 
    226         if (!is_null($config->preloadFile)) { 
    227             $options[] = "-p {$config->preloadFile}"; 
    228         } 
    229  
    230         if ($config->color) { 
     239        if (!is_null($this->_config->preloadFile)) { 
     240            $options[] = "-p {$this->_config->preloadFile}"; 
     241        } 
     242 
     243        if ($this->_config->color) { 
    231244            $options[] = '-c'; 
    232245        } 
    233246 
    234         if ($config->useGrowl) { 
     247        if ($this->_config->useGrowl) { 
    235248            $options[] = '-g'; 
    236249        } 
    237250 
    238         $options[] = $config->directory; 
     251        $options[] = $this->_config->directory; 
    239252 
    240253        $monitor = new Stagehand_TestRunner_AlterationMonitor($targetDirectories, 
     
    254267     * @since Method available since Release 2.1.0 
    255268     */ 
    256     private static function _parseOptions() 
     269    private function _parseOptions() 
    257270    { 
    258271        PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); 
     
    287300                    switch ($option[0]) { 
    288301                    case 'h': 
    289                         self::_displayUsage(); 
     302                        $this->_displayUsage(); 
    290303                        return; 
    291304                    case 'V': 
    292                         self::_displayVersion(); 
     305                        $this->_displayVersion(); 
    293306                        return; 
    294307                    case 'R': 
     
    337350     * Runs tests. 
    338351     * 
    339      * @param string $testRunnerName 
    340      * @param stdClass $config 
    341352     * @since Method available since Release 2.1.0 
    342353     */ 
    343     private static function _runTests($testRunnerName, $config) 
    344     { 
    345         include_once "Stagehand/TestRunner/Collector/$testRunnerName.php"; 
    346         $className = "Stagehand_TestRunner_Collector_$testRunnerName"; 
    347         $collector = new $className($config->directory, $config->isRecursive); 
     354    private function _runTests() 
     355    { 
     356        include_once "Stagehand/TestRunner/Collector/{$this->_testRunnerName}.php"; 
     357        $className = "Stagehand_TestRunner_Collector_{$this->_testRunnerName}"; 
     358        $collector = new $className($this->_config->directory, 
     359                                    $this->_config->isRecursive 
     360                                    ); 
    348361        $suite = $collector->collect(); 
    349362 
    350         include_once "Stagehand/TestRunner/Runner/$testRunnerName.php"; 
    351         $className = "Stagehand_TestRunner_Runner_$testRunnerName"; 
     363        include_once "Stagehand/TestRunner/Runner/{$this->_testRunnerName}.php"; 
     364        $className = "Stagehand_TestRunner_Runner_{$this->_testRunnerName}"; 
    352365        $runner = new $className(); 
    353         $runner->run($suite, $config); 
    354  
    355         if ($config->useGrowl) { 
     366        $runner->run($suite, $this->_config); 
     367 
     368        if ($this->_config->useGrowl) { 
    356369            $notification = $runner->getNotification(); 
    357370            $application = new Net_Growl_Application('Stagehand_TestRunner',