Changeset 124

Show
Ignore:
Timestamp:
03/02/08 20:30:30 (10 months ago)
Author:
iteman
Message:

- Added missing method descriptions.
- Removed some unused comments.

Files:
1 modified

Legend:

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

    r122 r124  
    4242 
    4343/** 
     44 * The file and directory alteration monitor. 
     45 * 
    4446 * @package    Stagehand_TestRunner 
    4547 * @copyright  2008 KUBO Atsuhiro <iteman@users.sourceforge.net> 
     
    9395 
    9496    /** 
     97     * Sets a directory and command string to the properties. 
     98     * 
    9599     * @param string $directory 
    96100     * @param string $command 
     
    106110 
    107111    /** 
     112     * Watches for changes in the directory and runs tests in the directory 
     113     * recursively when changes are detected. 
    108114     */ 
    109115    public function monitor() 
     
    115121            $this->_waitForChanges(); 
    116122 
    117             print "Any changes are detected! Running tests ...\n"; 
     123            print "Any changes are detected! Running tests ...\n\n"; 
    118124            $this->_runTests(); 
    119125        } 
     
    136142 
    137143    /** 
    138      * @throws Stagehand_TestRunner_Exception 
     144     * Runs tests in the directory recursively. 
    139145     */ 
    140146    private function _runTests() 
    141147    { 
    142 /*         passthru($this->_command, $result); */ 
    143148        passthru($this->_command, $result); 
    144 /*         if ($result !== 0) { */ 
    145 /*             throw new Stagehand_TestRunner_Exception(); */ 
    146 /*         } */ 
    147     } 
    148  
    149     // }}} 
    150     // {{{ _collectElements() 
    151  
    152     /** 
    153      */ 
    154     private function _collectElements($directory) 
    155     { 
    156         $files = scandir($directory); 
    157         for ($i = 0, $count = count($files); $i < $count; ++$i) { 
    158             if ($files[$i] == '.' || $files[$i] == '..') { 
    159                 continue; 
    160             } 
    161  
    162             foreach ($this->_excludePatterns as $excludePattern) { 
    163                 if (preg_match($excludePattern, $files[$i])) { 
    164                     continue 2; 
    165                 } 
    166             } 
    167  
    168             $element = $directory . DIRECTORY_SEPARATOR . $files[$i]; 
    169             if (!$this->_isFirstTime) { 
    170                 if (!array_key_exists($element, $this->_previousElements)) { 
    171                     throw new Stagehand_TestRunner_Exception(); 
    172                 } 
    173  
    174                 if (!is_dir($element)) { 
    175                     $mtime = filemtime($element); 
    176                     if ($this->_previousElements[$element]['mtime'] != $mtime) { 
    177                         throw new Stagehand_TestRunner_Exception(); 
    178                     } 
    179                 } 
    180  
    181                 $perms = fileperms($element); 
    182                 if ($this->_previousElements[$element]['perms'] != $perms) { 
    183                     throw new Stagehand_TestRunner_Exception(); 
    184                 } 
    185             } 
    186  
    187             if (!is_dir($element)) { 
    188                 $this->_currentElements[$element]['mtime'] = filemtime($element); 
    189             } 
    190  
    191             $this->_currentElements[$element]['perms'] = fileperms($element); 
    192  
    193             if (is_dir($element)) { 
    194                 $this->_collectElements($element); 
    195             } 
    196         } 
    197149    } 
    198150 
     
    201153 
    202154    /** 
     155     * Watches for changes in the directory and returns immediately when 
     156     * changes are detected. 
    203157     */ 
    204158    private function _waitForChanges() 
     
    229183            $this->_previousElements = $this->_currentElements; 
    230184            $this->_isFirstTime = false; 
     185        } 
     186    } 
     187 
     188    // }}} 
     189    // {{{ _collectElements() 
     190 
     191    /** 
     192     * Collects all files and directories in the directory and detects any 
     193     * changes of a file or directory immediately. 
     194     * 
     195     * @param string $directory 
     196     * @throws Stagehand_TestRunner_Exception 
     197     */ 
     198    private function _collectElements($directory) 
     199    { 
     200        $files = scandir($directory); 
     201        for ($i = 0, $count = count($files); $i < $count; ++$i) { 
     202            if ($files[$i] == '.' || $files[$i] == '..') { 
     203                continue; 
     204            } 
     205 
     206            foreach ($this->_excludePatterns as $excludePattern) { 
     207                if (preg_match($excludePattern, $files[$i])) { 
     208                    continue 2; 
     209                } 
     210            } 
     211 
     212            $element = $directory . DIRECTORY_SEPARATOR . $files[$i]; 
     213            if (!$this->_isFirstTime) { 
     214                if (!array_key_exists($element, $this->_previousElements)) { 
     215                    throw new Stagehand_TestRunner_Exception(); 
     216                } 
     217 
     218                if (!is_dir($element)) { 
     219                    $mtime = filemtime($element); 
     220                    if ($this->_previousElements[$element]['mtime'] != $mtime) { 
     221                        throw new Stagehand_TestRunner_Exception(); 
     222                    } 
     223                } 
     224 
     225                $perms = fileperms($element); 
     226                if ($this->_previousElements[$element]['perms'] != $perms) { 
     227                    throw new Stagehand_TestRunner_Exception(); 
     228                } 
     229            } 
     230 
     231            if (!is_dir($element)) { 
     232                $this->_currentElements[$element]['mtime'] = filemtime($element); 
     233            } 
     234 
     235            $this->_currentElements[$element]['perms'] = fileperms($element); 
     236 
     237            if (is_dir($element)) { 
     238                $this->_collectElements($element); 
     239            } 
    231240        } 
    232241    }