Changeset 117

Show
Ignore:
Timestamp:
02/29/08 19:12:49 (11 months ago)
Author:
iteman
Message:

- Refactored.

Location:
trunk/src/Stagehand
Files:
2 modified

Legend:

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

    r116 r117  
    137137        include_once "Stagehand/TestRunner/$testRunnerName.php"; 
    138138        $className = "Stagehand_TestRunner_$testRunnerName"; 
    139         $testRunner = new $className($color, $isFile); 
    140  
    141         if (!$isRecursive) { 
    142             if (is_null($directory)) { 
    143                 $directory = getcwd(); 
    144             } 
    145  
    146             $testRunner->run($directory); 
    147         } else { 
    148             $directory = getcwd(); 
    149             $testRunner->runRecursively($directory); 
    150         } 
     139        $testRunner = new $className($color, $isFile, $directory, $isRecursive); 
     140        $testRunner->run(); 
    151141 
    152142        return 0; 
  • trunk/src/Stagehand/TestRunner/Common.php

    r110 r117  
    7575 
    7676    private $_isFile; 
     77    private $_directory; 
     78    private $_isRecursive; 
    7779 
    7880    /**#@-*/ 
     
    8890     * @param boolean $color 
    8991     * @param boolean $isFile 
    90      */ 
    91     public function __construct($color, $isFile) 
    92     { 
    93         $this->_color = $color; 
    94         $this->_isFile = $isFile; 
    95     } 
    96  
    97     // }}} 
    98     // {{{ run() 
    99  
    100     /** 
    101      * Runs tests in the directory. 
    102      * 
    103      * @param string $directory 
    104      * @return stdClass 
    105      */ 
    106     public function run($directory) 
    107     { 
    108         if ($this->_isFile) { 
     92     * @param string  $directory 
     93     * @param boolean $isRecursive 
     94     */ 
     95    public function __construct($color, $isFile, $directory, $isRecursive) 
     96    { 
     97        if ($isRecursive || is_null($directory)) { 
     98            $directory = getcwd(); 
     99        } 
     100 
     101        if ($isFile) { 
    109102            if (!preg_match("/{$this->_suffix}\.php\$/", $directory)) { 
    110103                $directory = "$directory{$this->_suffix}.php"; 
     
    112105        } 
    113106 
    114         return $this->_doRun($this->_buildTestSuite($this->_createTestSuite(), $directory)); 
    115     } 
    116  
    117     // }}} 
    118     // {{{ runRecursively() 
    119  
    120     /** 
    121      * Runs tests under the directory recursively. 
    122      * 
    123      * @param string $directory 
     107        $this->_directory = $directory; 
     108        $this->_color = $color; 
     109        $this->_isRecursive = $isRecursive; 
     110    } 
     111 
     112    // }}} 
     113    // {{{ run() 
     114 
     115    /** 
     116     * Runs tests in the directory. 
     117     * 
    124118     * @return stdClass 
    125119     */ 
    126     public function runRecursively($directory) 
    127     { 
    128         $suite = $this->_createTestSuite(); 
    129         $directories = $this->_getDirectories($directory); 
    130         for ($i = 0, $count = count($directories); $i < $count; ++$i) { 
    131             $this->_buildTestSuite($suite, $directories[$i]); 
     120    public function run() 
     121    { 
     122        if ($this->_isRecursive) { 
     123            $suite = $this->_createTestSuite(); 
     124            $directories = $this->_getDirectories($this->_directory); 
     125            for ($i = 0, $count = count($directories); $i < $count; ++$i) { 
     126                $this->_buildTestSuite($suite, $directories[$i]); 
     127            } 
     128        } else { 
     129            $suite = $this->_buildTestSuite($this->_createTestSuite(), $this->_directory); 
    132130        } 
    133131