Changeset 120
- Timestamp:
- 02/29/08 22:48:03 (11 months ago)
- Location:
- trunk/src/Stagehand
- Files:
-
- 3 added
- 3 modified
- 3 copied
- 6 moved
-
TestRunner.php (modified) (2 diffs)
-
TestRunner/Collector (added)
-
TestRunner/Collector/Common.php (moved) (moved from trunk/src/Stagehand/TestRunner/Common.php) (7 diffs)
-
TestRunner/Collector/PHPSpec.php (copied) (copied from trunk/src/Stagehand/TestRunner/PHPSpec.php) (3 diffs)
-
TestRunner/Collector/PHPUnit.php (copied) (copied from trunk/src/Stagehand/TestRunner/PHPUnit.php) (3 diffs)
-
TestRunner/Collector/SimpleTest.php (moved) (moved from trunk/src/Stagehand/TestRunner/SimpleTest.php) (3 diffs)
-
TestRunner/IRunner.php (added)
-
TestRunner/Runner (added)
-
TestRunner/Runner/PHPSpec (moved) (moved from trunk/src/Stagehand/TestRunner/PHPSpec)
-
TestRunner/Runner/PHPSpec.php (moved) (moved from trunk/src/Stagehand/TestRunner/PHPSpec.php) (6 diffs)
-
TestRunner/Runner/PHPSpec/Reporter.php (modified) (2 diffs)
-
TestRunner/Runner/PHPUnit (moved) (moved from trunk/src/Stagehand/TestRunner/PHPUnit)
-
TestRunner/Runner/PHPUnit.php (moved) (moved from trunk/src/Stagehand/TestRunner/PHPUnit.php) (6 diffs)
-
TestRunner/Runner/PHPUnit/ResultPrinter.php (modified) (5 diffs)
-
TestRunner/Runner/SimpleTest.php (copied) (copied from trunk/src/Stagehand/TestRunner/SimpleTest.php) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Stagehand/TestRunner.php
r118 r120 133 133 } 134 134 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 137 139 try { 138 $ testRunner = new $className($color, $directory, $isRecursive);140 $suite = $collector->collect(); 139 141 } catch (Stagehand_TestRunner_Exception $e) { 140 142 echo 'ERROR: ' . $e->getMessage() . "\n"; … … 143 145 } 144 146 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); 146 151 147 152 return 0; -
trunk/src/Stagehand/TestRunner/Collector/Common.php
r119 r120 33 33 * @license http://www.opensource.org/licenses/bsd-license.php BSD License (revised) 34 34 * @version SVN: $Id$ 35 * @since File available since Release 1.1.035 * @since File available since Release 2.1.0 36 36 */ 37 37 38 38 require_once 'Stagehand/TestRunner/Exception.php'; 39 39 40 // {{{ Stagehand_TestRunner_Co mmon40 // {{{ Stagehand_TestRunner_Collector_Common 41 41 42 42 /** 43 * The base class for test runners.43 * The base class for test collectors. 44 44 * 45 45 * @package Stagehand_TestRunner … … 47 47 * @license http://www.opensource.org/licenses/bsd-license.php BSD License (revised) 48 48 * @version Release: @package_version@ 49 * @since Class available since Release 1.1.049 * @since Class available since Release 2.1.0 50 50 */ 51 abstract class Stagehand_TestRunner_Co mmon51 abstract class Stagehand_TestRunner_Collector_Common 52 52 { 53 53 … … 67 67 protected $_baseClass; 68 68 protected $_suffix = 'TestCase'; 69 protected $_color;70 69 protected $_includePattern; 71 70 … … 76 75 */ 77 76 78 private $_suite; 77 private $_targetPath; 78 private $_isRecursive; 79 79 80 80 /**#@-*/ … … 88 88 89 89 /** 90 * @param boolean $color 90 * Initializes some properties of an instance. 91 * 91 92 * @param string $targetPath 92 93 * @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 93 108 * @throws Stagehand_TestRunner_Exception 94 109 */ 95 public function __construct($color, $targetPath, $isRecursive)96 { 97 if (is_null($t argetPath)) {110 public function collect() 111 { 112 if (is_null($this->_targetPath)) { 98 113 $absoluteTargetPath = getcwd(); 99 114 } else { 100 if (!file_exists($t argetPath)) {101 if (preg_match("/{$this->_suffix}\.php\$/", $t argetPath)) {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."); 103 118 } 104 119 105 $t argetPath = "$targetPath{$this->_suffix}.php";106 } 107 108 $absoluteTargetPath = realpath($t argetPath);120 $this->_targetPath = "{$this->_targetPath}{$this->_suffix}.php"; 121 } 122 123 $absoluteTargetPath = realpath($this->_targetPath); 109 124 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) { 115 130 $suite = $this->_createTestSuite(); 116 131 $directories = $this->_getDirectories($absoluteTargetPath); … … 122 137 } 123 138 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; 139 140 } 140 141 … … 144 145 * @access protected 145 146 */ 146 147 // }}}148 // {{{ _doRun()149 150 /**151 * Runs tests based on the given test suite object.152 *153 * @param mixed $suite154 * @return stdClass155 * @abstract156 */157 abstract protected function _doRun($suite);158 147 159 148 // }}} -
trunk/src/Stagehand/TestRunner/Collector/PHPSpec.php
r107 r120 5 5 * PHP version 5 6 6 * 7 * Copyright (c) 2007 KUBO Atsuhiro <iteman@users.sourceforge.net>,7 * Copyright (c) 2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net>, 8 8 * All rights reserved. 9 9 * … … 30 30 * 31 31 * @package Stagehand_TestRunner 32 * @copyright 2007 KUBO Atsuhiro <iteman@users.sourceforge.net>32 * @copyright 2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net> 33 33 * @license http://www.opensource.org/licenses/bsd-license.php BSD License (revised) 34 34 * @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 38 37 */ 39 38 40 require_once 'Stagehand/TestRunner/Common.php'; 41 require_once 'PHPSpec/Framework.php'; 42 require_once 'Stagehand/TestRunner/PHPSpec/Reporter.php'; 39 require_once 'Stagehand/TestRunner/Collector/Common.php'; 43 40 44 // {{{ Stagehand_TestRunner_ PHPSpec41 // {{{ Stagehand_TestRunner_Collector_PHPSpec 45 42 46 43 /** 47 * A test runner for PHPSpec.44 * A test collector for PHPSpec. 48 45 * 49 46 * @package Stagehand_TestRunner 50 * @copyright 2007 KUBO Atsuhiro <iteman@users.sourceforge.net>47 * @copyright 2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net> 51 48 * @license http://www.opensource.org/licenses/bsd-license.php BSD License (revised) 52 49 * @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 56 52 */ 57 class Stagehand_TestRunner_ PHPSpec extends Stagehand_TestRunner_Common53 class Stagehand_TestRunner_Collector_PHPSpec extends Stagehand_TestRunner_Collector_Common 58 54 { 59 55 … … 91 87 * @access protected 92 88 */ 93 94 // }}}95 // {{{ _doRun()96 97 /**98 * Runs tests based on the given test suite ArrayObject.99 *100 * @param ArrayObject $suite101 * @return stdClass102 */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 }118 89 119 90 // }}} -
trunk/src/Stagehand/TestRunner/Collector/PHPUnit.php
r107 r120 5 5 * PHP version 5 6 6 * 7 * Copyright (c) 2007 KUBO Atsuhiro <iteman@users.sourceforge.net>,7 * Copyright (c) 2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net>, 8 8 * All rights reserved. 9 9 * … … 30 30 * 31 31 * @package Stagehand_TestRunner 32 * @copyright 2007 KUBO Atsuhiro <iteman@users.sourceforge.net>32 * @copyright 2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net> 33 33 * @license http://www.opensource.org/licenses/bsd-license.php BSD License (revised) 34 34 * @version SVN: $Id$ 35 35 * @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 38 37 */ 39 38 40 define('PHPUnit_MAIN_METHOD', 'Stagehand_TestRunner_PHPUnit::run'); 41 42 require_once 'Stagehand/TestRunner/Common.php'; 43 require_once 'PHPUnit/TextUI/TestRunner.php'; 39 require_once 'Stagehand/TestRunner/Collector/Common.php'; 44 40 require_once 'PHPUnit/Framework/TestSuite.php'; 45 41 46 // {{{ Stagehand_TestRunner_ PHPUnit42 // {{{ Stagehand_TestRunner_Collector_PHPUnit 47 43 48 44 /** 49 * A test runner for PHPUnit.45 * A test collector for PHPUnit. 50 46 * 51 47 * @package Stagehand_TestRunner 52 * @copyright 2007 KUBO Atsuhiro <iteman@users.sourceforge.net>48 * @copyright 2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net> 53 49 * @license http://www.opensource.org/licenses/bsd-license.php BSD License (revised) 54 50 * @version Release: @package_version@ 55 51 * @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 58 53 */ 59 class Stagehand_TestRunner_ PHPUnit extends Stagehand_TestRunner_Common54 class Stagehand_TestRunner_Collector_PHPUnit extends Stagehand_TestRunner_Collector_Common 60 55 { 61 56 … … 92 87 * @access protected 93 88 */ 94 95 // }}}96 // {{{ _doRun()97 98 /**99 * Runs tests based on the given test suite object.100 *101 * @param PHPUnit_Framework_TestSuite $suite102 */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 }113 89 114 90 // }}} -
trunk/src/Stagehand/TestRunner/Collector/SimpleTest.php
r107 r120 6 6 * 7 7 * 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>, 9 9 * All rights reserved. 10 10 * … … 32 32 * @package Stagehand_TestRunner 33 33 * @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> 35 35 * @license http://www.opensource.org/licenses/bsd-license.php BSD License (revised) 36 36 * @version SVN: $Id$ 37 37 * @link http://simpletest.org/ 38 * @since File available since Release 1.1.038 * @since File available since Release 2.1.0 39 39 */ 40 40 41 require_once 'Stagehand/TestRunner/Co mmon.php';41 require_once 'Stagehand/TestRunner/Collector/Common.php'; 42 42 require_once 'simpletest/test_case.php'; 43 require_once 'simpletest/reporter.php';44 require_once 'simpletest/scorer.php';45 43 46 // {{{ Stagehand_TestRunner_ SimpleTest44 // {{{ Stagehand_TestRunner_Collector_SimpleTest 47 45 48 46 /** 49 * A test runner for SimpleTest.47 * A test collector for SimpleTest. 50 48 * 51 49 * @package Stagehand_TestRunner 52 50 * @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> 54 52 * @license http://www.opensource.org/licenses/bsd-license.php BSD License (revised) 55 53 * @version Release: @package_version@ 56 54 * @link http://simpletest.org/ 57 * @since Class available since Release 1.1.055 * @since Class available since Release 2.1.0 58 56 */ 59 class Stagehand_TestRunner_ SimpleTest extends Stagehand_TestRunner_Common57 class Stagehand_TestRunner_Collector_SimpleTest extends Stagehand_TestRunner_Collector_Common 60 58 { 61 59 … … 92 90 * @access protected 93 91 */ 94 95 // }}}96 // {{{ _doRun()97 98 /**99 * Runs tests based on the given test suite object.100 *101 * @param TestSuite $suite102 */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 }129 92 130 93 // }}} -
trunk/src/Stagehand/TestRunner/Runner/PHPSpec.php
r107 r120 5 5 * PHP version 5 6 6 * 7 * Copyright (c) 2007 KUBO Atsuhiro <iteman@users.sourceforge.net>,7 * Copyright (c) 2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net>, 8 8 * All rights reserved. 9 9 * … … 30 30 * 31 31 * @package Stagehand_TestRunner 32 * @copyright 2007 KUBO Atsuhiro <iteman@users.sourceforge.net>32 * @copyright 2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net> 33 33 * @license http://www.opensource.org/licenses/bsd-license.php BSD License (revised) 34 34 * @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 38 37 */ 39 38 40 require_once 'Stagehand/TestRunner/ Common.php';39 require_once 'Stagehand/TestRunner/IRunner.php'; 41 40 require_once 'PHPSpec/Framework.php'; 42 require_once 'Stagehand/TestRunner/ PHPSpec/Reporter.php';41 require_once 'Stagehand/TestRunner/Runner/PHPSpec/Reporter.php'; 43 42 44 // {{{ Stagehand_TestRunner_ PHPSpec43 // {{{ Stagehand_TestRunner_Runner_PHPSpec 45 44 46 45 /** … … 48 47 * 49 48 * @package Stagehand_TestRunner 50 * @copyright 2007 KUBO Atsuhiro <iteman@users.sourceforge.net>49 * @copyright 2007-2008 KUBO Atsuhiro <iteman@users.sourceforge.net> 51 50 * @license http://www.opensource.org/licenses/bsd-license.php BSD License (revised) 52 51 * @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 56 54 */ 57 class Stagehand_TestRunner_ PHPSpec extends Stagehand_TestRunner_Common55 class Stagehand_TestRunner_Runner_PHPSpec implements Stagehand_TestRunner_IRunner 58 56 { 59 57 … … 70 68 */ 71 69 72 protected $_baseClass = 'PHPSpec_Context';73 protected $_suffix = 'Spec';74 protected $_includePattern = '!(^[Dd]escribe|[Ss]pec$)!';75 76 70 /**#@-*/ 77 71 … … 86 80 */ 87 81 88 /**#@-*/89 90 /**#@+91 * @access protected92 */93 94 82 // }}} 95 // {{{ _doRun()83 // {{{ run() 96 84 97 85 /** 98 * Runs tests based on the given test suite ArrayObject.86 * Runs tests based on the given ArrayObject object. 99 87 * 100 88 * @param ArrayObject $suite 101 * @ return stdClass89 * @param boolean $color 102 90 */ 103 p rotected function _doRun($suite)91 public function run($suite, $color) 104 92 { 105 93 $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); 107 95 $result->setReporter($reporter); 108 96 … … 117 105 } 118 106 119 // }}} 120 // {{{ _createTestSuite() 107 /**#@-*/ 121 108 122 /** 123 * Creates a test suite ArrayObject. 124 * 125 * @return ArrayObject 109 /**#@+ 110 * @access protected 126 111 */ 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 $aggregateSuite139 * @param ArrayObject $suite140 */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 $suite159 * @param string $testCase160 */161 protected function _addTestCase($suite, $testCase)162 {163 $suite[] = $testCase;164 }165 112 166 113 /**#@-*/ -
trunk/src/Stagehand/TestRunner/Runner/PHPSpec/Reporter.php
r110 r120 33 33 * @license http://www.opensource.org/licenses/bsd-license.php BSD License (revised) 34 34 * @version SVN: $Id$ 35 * @link http://www.php unit.de/35 * @link http://www.phpspec.org/ 36 36 * @since File available since Release 2.0.0 37 37 */ 38 38 39 // {{{ Stagehand_TestRunner_ PHPSpec_Reporter39 // {{{ Stagehand_TestRunner_Runner_PHPSpec_Reporter 40 40 41 41 /** … … 46 46 * @license htt
