Changeset 120

Show
Ignore:
Timestamp:
02/29/08 22:48:03 (11 months ago)
Author:
iteman
Message:

- Refacgtored.

Location:
trunk/src/Stagehand
Files:
3 added
3 modified
3 copied
6 moved

Legend:

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

    r118 r120  
    133133        } 
    134134 
    135         include_once "Stagehand/TestRunner/$testRunnerName.php"; 
    136         $className = "Stagehand_TestRunner_$testRunnerName"; 
     135        include_once "Stagehand/TestRunner/Collector/$testRunnerName.php"; 
     136        $className = "Stagehand_TestRunner_Collector_$testRunnerName"; 
     137        $collector = new $className($directory, $isRecursive); 
     138 
    137139        try { 
    138             $testRunner = new $className($color, $directory, $isRecursive); 
     140            $suite = $collector->collect(); 
    139141        } catch (Stagehand_TestRunner_Exception $e) { 
    140142            echo 'ERROR: ' . $e->getMessage() . "\n"; 
     
    143145        } 
    144146 
    145         $testRunner->run(); 
     147        include_once "Stagehand/TestRunner/Runner/$testRunnerName.php"; 
     148        $className = "Stagehand_TestRunner_Runner_$testRunnerName"; 
     149        $runner = new $className(); 
     150        $runner->run($suite, $color); 
    146151 
    147152        return 0; 
  • trunk/src/Stagehand/TestRunner/Collector/Common.php

    r119 r120  
    3333 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License (revised) 
    3434 * @version    SVN: $Id$ 
    35  * @since      File available since Release 1.1.0 
     35 * @since      File available since Release 2.1.0 
    3636 */ 
    3737 
    3838require_once 'Stagehand/TestRunner/Exception.php'; 
    3939 
    40 // {{{ Stagehand_TestRunner_Common 
     40// {{{ Stagehand_TestRunner_Collector_Common 
    4141 
    4242/** 
    43  * The base class for test runners. 
     43 * The base class for test collectors. 
    4444 * 
    4545 * @package    Stagehand_TestRunner 
     
    4747 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License (revised) 
    4848 * @version    Release: @package_version@ 
    49  * @since      Class available since Release 1.1.0 
     49 * @since      Class available since Release 2.1.0 
    5050 */ 
    51 abstract class Stagehand_TestRunner_Common 
     51abstract class Stagehand_TestRunner_Collector_Common 
    5252{ 
    5353 
     
    6767    protected $_baseClass; 
    6868    protected $_suffix = 'TestCase'; 
    69     protected $_color; 
    7069    protected $_includePattern; 
    7170 
     
    7675     */ 
    7776 
    78     private $_suite; 
     77    private $_targetPath; 
     78    private $_isRecursive; 
    7979 
    8080    /**#@-*/ 
     
    8888 
    8989    /** 
    90      * @param boolean $color 
     90     * Initializes some properties of an instance. 
     91     * 
    9192     * @param string  $targetPath 
    9293     * @param boolean $isRecursive 
     94     */ 
     95    public function __construct($targetPath, $isRecursive) 
     96    { 
     97        $this->_targetPath = $targetPath; 
     98        $this->_isRecursive = $isRecursive; 
     99    } 
     100 
     101    // }}} 
     102    // {{{ collect() 
     103 
     104    /** 
     105     * Collects test cases. 
     106     * 
     107     * @return mixed 
    93108     * @throws Stagehand_TestRunner_Exception 
    94109     */ 
    95     public function __construct($color, $targetPath, $isRecursive) 
    96     { 
    97         if (is_null($targetPath)) { 
     110    public function collect() 
     111    { 
     112        if (is_null($this->_targetPath)) { 
    98113            $absoluteTargetPath = getcwd(); 
    99114        } else { 
    100             if (!file_exists($targetPath)) { 
    101                 if (preg_match("/{$this->_suffix}\.php\$/", $targetPath)) { 
    102                     throw new Stagehand_TestRunner_Exception("The directory or file [ $targetPath ] is not found."); 
     115            if (!file_exists($this->_targetPath)) { 
     116                if (preg_match("/{$this->_suffix}\.php\$/", $this->_targetPath)) { 
     117                    throw new Stagehand_TestRunner_Exception("The directory or file [ {$this->_targetPath} ] is not found."); 
    103118                } 
    104119 
    105                 $targetPath = "$targetPath{$this->_suffix}.php"; 
    106             } 
    107  
    108             $absoluteTargetPath = realpath($targetPath); 
     120                $this->_targetPath = "{$this->_targetPath}{$this->_suffix}.php"; 
     121            } 
     122 
     123            $absoluteTargetPath = realpath($this->_targetPath); 
    109124            if ($absoluteTargetPath === false) { 
    110                 throw new Stagehand_TestRunner_Exception("The directory or file [ $targetPath ] is not found."); 
    111             } 
    112         } 
    113  
    114         if (is_dir($absoluteTargetPath) && $isRecursive) { 
     125                throw new Stagehand_TestRunner_Exception("The directory or file [ {$this->_targetPath} ] is not found."); 
     126            } 
     127        } 
     128 
     129        if (is_dir($absoluteTargetPath) && $this->_isRecursive) { 
    115130            $suite = $this->_createTestSuite(); 
    116131            $directories = $this->_getDirectories($absoluteTargetPath); 
     
    122137        } 
    123138 
    124         $this->_suite = $suite; 
    125         $this->_color = $color; 
    126     } 
    127  
    128     // }}} 
    129     // {{{ run() 
    130  
    131     /** 
    132      * Runs tests in the directory. 
    133      * 
    134      * @return stdClass 
    135      */ 
    136     public function run() 
    137     { 
    138         return $this->_doRun($this->_suite); 
     139        return $suite; 
    139140    } 
    140141 
     
    144145     * @access protected 
    145146     */ 
    146  
    147     // }}} 
    148     // {{{ _doRun() 
    149  
    150     /** 
    151      * Runs tests based on the given test suite object. 
    152      * 
    153      * @param mixed $suite 
    154      * @return stdClass 
    155      * @abstract 
    156      */ 
    157     abstract protected function _doRun($suite); 
    158147 
    159148    // }}} 
  • trunk/src/Stagehand/TestRunner/Collector/PHPSpec.php

    r107 r120  
    55 * PHP version 5 
    66 * 
    7  * Copyright (c) 2007 KUBO Atsuhiro <iteman@users.sourceforge.net>, 
     7 * Copyright (c) 2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net>, 
    88 * All rights reserved. 
    99 * 
     
    3030 * 
    3131 * @package    Stagehand_TestRunner 
    32  * @copyright  2007 KUBO Atsuhiro <iteman@users.sourceforge.net> 
     32 * @copyright  2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net> 
    3333 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License (revised) 
    3434 * @version    SVN: $Id$ 
    35  * @link       http://www.phpunit.de/ 
    36  * @see        PHPUnit_Framework_TestSuite, PHPUnit_TextUI_TestRunner::run() 
    37  * @since      File available since Release 2.0.0 
     35 * @link       http://www.phpspec.org/ 
     36 * @since      File available since Release 2.1.0 
    3837 */ 
    3938 
    40 require_once 'Stagehand/TestRunner/Common.php'; 
    41 require_once 'PHPSpec/Framework.php'; 
    42 require_once 'Stagehand/TestRunner/PHPSpec/Reporter.php'; 
     39require_once 'Stagehand/TestRunner/Collector/Common.php'; 
    4340 
    44 // {{{ Stagehand_TestRunner_PHPSpec 
     41// {{{ Stagehand_TestRunner_Collector_PHPSpec 
    4542 
    4643/** 
    47  * A test runner for PHPSpec. 
     44 * A test collector for PHPSpec. 
    4845 * 
    4946 * @package    Stagehand_TestRunner 
    50  * @copyright  2007 KUBO Atsuhiro <iteman@users.sourceforge.net> 
     47 * @copyright  2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net> 
    5148 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License (revised) 
    5249 * @version    Release: @package_version@ 
    53  * @link       http://www.phpunit.de/ 
    54  * @see        PHPUnit_Framework_TestSuite, PHPUnit_TextUI_TestRunner::run() 
    55  * @since      Class available since Release 2.0.0 
     50 * @link       http://www.phpspec.org/ 
     51 * @since      Class available since Release 2.1.0 
    5652 */ 
    57 class Stagehand_TestRunner_PHPSpec extends Stagehand_TestRunner_Common 
     53class Stagehand_TestRunner_Collector_PHPSpec extends Stagehand_TestRunner_Collector_Common 
    5854{ 
    5955 
     
    9187     * @access protected 
    9288     */ 
    93  
    94     // }}} 
    95     // {{{ _doRun() 
    96  
    97     /** 
    98      * Runs tests based on the given test suite ArrayObject. 
    99      * 
    100      * @param ArrayObject $suite 
    101      * @return stdClass 
    102      */ 
    103     protected function _doRun($suite) 
    104     { 
    105         $result = new PHPSpec_Runner_Result(); 
    106         $reporter = new Stagehand_TestRunner_PHPSpec_Reporter($result, $this->_color); 
    107         $result->setReporter($reporter); 
    108  
    109         $result->setRuntimeStart(microtime(true)); 
    110         foreach ($suite as $contextClass) { 
    111             $collection = new PHPSpec_Runner_Collection(new $contextClass()); 
    112             PHPSpec_Runner_Base::execute($collection, $result); 
    113         } 
    114         $result->setRuntimeEnd(microtime(true)); 
    115  
    116         $reporter->output(true); 
    117     } 
    11889 
    11990    // }}} 
  • trunk/src/Stagehand/TestRunner/Collector/PHPUnit.php

    r107 r120  
    55 * PHP version 5 
    66 * 
    7  * Copyright (c) 2007 KUBO Atsuhiro <iteman@users.sourceforge.net>, 
     7 * Copyright (c) 2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net>, 
    88 * All rights reserved. 
    99 * 
     
    3030 * 
    3131 * @package    Stagehand_TestRunner 
    32  * @copyright  2007 KUBO Atsuhiro <iteman@users.sourceforge.net> 
     32 * @copyright  2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net> 
    3333 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License (revised) 
    3434 * @version    SVN: $Id$ 
    3535 * @link       http://www.phpunit.de/ 
    36  * @see        PHPUnit_Framework_TestSuite, PHPUnit_TextUI_TestRunner::run() 
    37  * @since      File available since Release 1.0.0 
     36 * @since      File available since Release 2.1.0 
    3837 */ 
    3938 
    40 define('PHPUnit_MAIN_METHOD', 'Stagehand_TestRunner_PHPUnit::run'); 
    41  
    42 require_once 'Stagehand/TestRunner/Common.php'; 
    43 require_once 'PHPUnit/TextUI/TestRunner.php'; 
     39require_once 'Stagehand/TestRunner/Collector/Common.php'; 
    4440require_once 'PHPUnit/Framework/TestSuite.php'; 
    4541 
    46 // {{{ Stagehand_TestRunner_PHPUnit 
     42// {{{ Stagehand_TestRunner_Collector_PHPUnit 
    4743 
    4844/** 
    49  * A test runner for PHPUnit. 
     45 * A test collector for PHPUnit. 
    5046 * 
    5147 * @package    Stagehand_TestRunner 
    52  * @copyright  2007 KUBO Atsuhiro <iteman@users.sourceforge.net> 
     48 * @copyright  2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net> 
    5349 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License (revised) 
    5450 * @version    Release: @package_version@ 
    5551 * @link       http://www.phpunit.de/ 
    56  * @see        PHPUnit_Framework_TestSuite, PHPUnit_TextUI_TestRunner::run() 
    57  * @since      Class available since Release 1.0.0 
     52 * @since      Class available since Release 2.1.0 
    5853 */ 
    59 class Stagehand_TestRunner_PHPUnit extends Stagehand_TestRunner_Common 
     54class Stagehand_TestRunner_Collector_PHPUnit extends Stagehand_TestRunner_Collector_Common 
    6055{ 
    6156 
     
    9287     * @access protected 
    9388     */ 
    94  
    95     // }}} 
    96     // {{{ _doRun() 
    97  
    98     /** 
    99      * Runs tests based on the given test suite object. 
    100      * 
    101      * @param PHPUnit_Framework_TestSuite $suite 
    102      */ 
    103     protected function _doRun($suite) 
    104     { 
    105         $parameters = array(); 
    106         if ($this->_color) { 
    107             include_once 'Stagehand/TestRunner/PHPUnit/ResultPrinter.php'; 
    108             $parameters['printer'] = new Stagehand_TestRunner_PHPUnit_ResultPrinter(); 
    109         } 
    110  
    111         PHPUnit_TextUI_TestRunner::run($suite, $parameters); 
    112     } 
    11389 
    11490    // }}} 
  • trunk/src/Stagehand/TestRunner/Collector/SimpleTest.php

    r107 r120  
    66 * 
    77 * Copyright (c) 2007 Masahiko Sakamoto <msakamoto-sf@users.sourceforge.net>, 
    8  *               2007 KUBO Atsuhiro <iteman@users.sourceforge.net>, 
     8 *               2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net>, 
    99 * All rights reserved. 
    1010 * 
     
    3232 * @package    Stagehand_TestRunner 
    3333 * @copyright  2007 Masahiko Sakamoto <msakamoto-sf@users.sourceforge.net> 
    34  * @copyright  2007 KUBO Atsuhiro <iteman@users.sourceforge.net> 
     34 * @copyright  2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net> 
    3535 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License (revised) 
    3636 * @version    SVN: $Id$ 
    3737 * @link       http://simpletest.org/ 
    38  * @since      File available since Release 1.1.0 
     38 * @since      File available since Release 2.1.0 
    3939 */ 
    4040 
    41 require_once 'Stagehand/TestRunner/Common.php'; 
     41require_once 'Stagehand/TestRunner/Collector/Common.php'; 
    4242require_once 'simpletest/test_case.php'; 
    43 require_once 'simpletest/reporter.php'; 
    44 require_once 'simpletest/scorer.php'; 
    4543 
    46 // {{{ Stagehand_TestRunner_SimpleTest 
     44// {{{ Stagehand_TestRunner_Collector_SimpleTest 
    4745 
    4846/** 
    49  * A test runner for SimpleTest. 
     47 * A test collector for SimpleTest. 
    5048 * 
    5149 * @package    Stagehand_TestRunner 
    5250 * @copyright  2007 Masahiko Sakamoto <msakamoto-sf@users.sourceforge.net> 
    53  * @copyright  2007 KUBO Atsuhiro <iteman@users.sourceforge.net> 
     51 * @copyright  2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net> 
    5452 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License (revised) 
    5553 * @version    Release: @package_version@ 
    5654 * @link       http://simpletest.org/ 
    57  * @since      Class available since Release 1.1.0 
     55 * @since      Class available since Release 2.1.0 
    5856 */ 
    59 class Stagehand_TestRunner_SimpleTest extends Stagehand_TestRunner_Common 
     57class Stagehand_TestRunner_Collector_SimpleTest extends Stagehand_TestRunner_Collector_Common 
    6058{ 
    6159 
     
    9290     * @access protected 
    9391     */ 
    94  
    95     // }}} 
    96     // {{{ _doRun() 
    97  
    98     /** 
    99      * Runs tests based on the given test suite object. 
    100      * 
    101      * @param TestSuite $suite 
    102      */ 
    103     protected function _doRun($suite) 
    104     { 
    105         $reporter = new TextReporter(); 
    106         ob_start(); 
    107         $suite->run($reporter); 
    108         $output = ob_get_contents(); 
    109         ob_end_clean(); 
    110  
    111         if ($this->_color) { 
    112             include_once 'Console/Color.php'; 
    113             print Console_Color::convert(preg_replace(array('/^(OK.+)/ms', 
    114                                                             '/^(FAILURES!!!.+)/ms', 
    115                                                             '/^(\d+\)\s)(.+at \[.+\]$\s+in .+)$/m', 
    116                                                             '/^(Exception \d+!)/m', 
    117                                                             '/^(Unexpected exception of type \[.+\] with message \[.+\] in \[.+\]$\s+in .+)$/m'), 
    118                                                       array('%g$1%n', 
    119                                                             '%r$1%n', 
    120                                                             "\$1%r\$2%n", 
    121                                                             '%p$1%n', 
    122                                                             '%p$1%n'), 
    123                                                       Console_Color::escape($output)) 
    124                                          ); 
    125         } else { 
    126             print $output; 
    127         } 
    128     } 
    12992 
    13093    // }}} 
  • trunk/src/Stagehand/TestRunner/Runner/PHPSpec.php

    r107 r120  
    55 * PHP version 5 
    66 * 
    7  * Copyright (c) 2007 KUBO Atsuhiro <iteman@users.sourceforge.net>, 
     7 * Copyright (c) 2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net>, 
    88 * All rights reserved. 
    99 * 
     
    3030 * 
    3131 * @package    Stagehand_TestRunner 
    32  * @copyright  2007 KUBO Atsuhiro <iteman@users.sourceforge.net> 
     32 * @copyright  2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net> 
    3333 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License (revised) 
    3434 * @version    SVN: $Id$ 
    35  * @link       http://www.phpunit.de/ 
    36  * @see        PHPUnit_Framework_TestSuite, PHPUnit_TextUI_TestRunner::run() 
    37  * @since      File available since Release 2.0.0 
     35 * @link       http://www.phpspec.org/ 
     36 * @since      File available since Release 2.1.0 
    3837 */ 
    3938 
    40 require_once 'Stagehand/TestRunner/Common.php'; 
     39require_once 'Stagehand/TestRunner/IRunner.php'; 
    4140require_once 'PHPSpec/Framework.php'; 
    42 require_once 'Stagehand/TestRunner/PHPSpec/Reporter.php'; 
     41require_once 'Stagehand/TestRunner/Runner/PHPSpec/Reporter.php'; 
    4342 
    44 // {{{ Stagehand_TestRunner_PHPSpec 
     43// {{{ Stagehand_TestRunner_Runner_PHPSpec 
    4544 
    4645/** 
     
    4847 * 
    4948 * @package    Stagehand_TestRunner 
    50  * @copyright  2007 KUBO Atsuhiro <iteman@users.sourceforge.net> 
     49 * @copyright  2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net> 
    5150 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License (revised) 
    5251 * @version    Release: @package_version@ 
    53  * @link       http://www.phpunit.de/ 
    54  * @see        PHPUnit_Framework_TestSuite, PHPUnit_TextUI_TestRunner::run() 
    55  * @since      Class available since Release 2.0.0 
     52 * @link       http://www.phpspec.org/ 
     53 * @since      Class available since Release 2.1.0 
    5654 */ 
    57 class Stagehand_TestRunner_PHPSpec extends Stagehand_TestRunner_Common 
     55class Stagehand_TestRunner_Runner_PHPSpec implements Stagehand_TestRunner_IRunner 
    5856{ 
    5957 
     
    7068     */ 
    7169 
    72     protected $_baseClass = 'PHPSpec_Context'; 
    73     protected $_suffix = 'Spec'; 
    74     protected $_includePattern = '!(^[Dd]escribe|[Ss]pec$)!'; 
    75  
    7670    /**#@-*/ 
    7771 
     
    8680     */ 
    8781 
    88     /**#@-*/ 
    89  
    90     /**#@+ 
    91      * @access protected 
    92      */ 
    93  
    9482    // }}} 
    95     // {{{ _doRun() 
     83    // {{{ run() 
    9684 
    9785    /** 
    98      * Runs tests based on the given test suite ArrayObject. 
     86     * Runs tests based on the given ArrayObject object. 
    9987     * 
    10088     * @param ArrayObject $suite 
    101      * @return stdClass 
     89     * @param boolean     $color 
    10290     */ 
    103     protected function _doRun($suite) 
     91    public function run($suite, $color) 
    10492    { 
    10593        $result = new PHPSpec_Runner_Result(); 
    106         $reporter = new Stagehand_TestRunner_PHPSpec_Reporter($result, $this->_color); 
     94        $reporter = new Stagehand_TestRunner_Runner_PHPSpec_Reporter($result, $color); 
    10795        $result->setReporter($reporter); 
    10896 
     
    117105    } 
    118106 
    119     // }}} 
    120     // {{{ _createTestSuite() 
     107    /**#@-*/ 
    121108 
    122     /** 
    123      * Creates a test suite ArrayObject. 
    124      * 
    125      * @return ArrayObject 
     109    /**#@+ 
     110     * @access protected 
    126111     */ 
    127     protected function _createTestSuite() 
    128     { 
    129         return new ArrayObject(); 
    130     } 
    131  
    132     // }}} 
    133     // {{{ _doBuildTestSuite() 
    134  
    135     /** 
    136      * Aggregates a test suite ArrayObject to an aggregate test suite ArrayObject. 
    137      * 
    138      * @param ArrayObject $aggregateSuite 
    139      * @param ArrayObject $suite 
    140      */ 
    141     protected function _doBuildTestSuite($aggregateSuite, $suite) 
    142     { 
    143         if (!count($suite)) { 
    144             return; 
    145         } 
    146  
    147         foreach ($suite as $testCase) { 
    148             $aggregateSuite->append($testCase); 
    149         } 
    150     } 
    151  
    152     // }}} 
    153     // {{{ _addTestCase() 
    154  
    155     /** 
    156      * Adds a test case to a test suite ArrayObject. 
    157      * 
    158      * @param ArrayObject $suite 
    159      * @param string      $testCase 
    160      */ 
    161     protected function _addTestCase($suite, $testCase) 
    162     { 
    163         $suite[] = $testCase; 
    164     } 
    165112 
    166113    /**#@-*/ 
  • trunk/src/Stagehand/TestRunner/Runner/PHPSpec/Reporter.php

    r110 r120  
    3333 * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License (revised) 
    3434 * @version    SVN: $Id$ 
    35  * @link       http://www.phpunit.de/ 
     35 * @link       http://www.phpspec.org/ 
    3636 * @since      File available since Release 2.0.0 
    3737 */ 
    3838 
    39 // {{{ Stagehand_TestRunner_PHPSpec_Reporter 
     39// {{{ Stagehand_TestRunner_Runner_PHPSpec_Reporter 
    4040 
    4141/** 
     
    4646 * @license    htt