Changeset 163
- Timestamp:
- 05/24/08 22:59:48 (8 months ago)
- Location:
- trunk/src/Stagehand
- Files:
-
- 5 modified
-
TestRunner.php (modified) (7 diffs)
-
TestRunner/IRunner.php (modified) (1 diff)
-
TestRunner/Runner/PHPSpec.php (modified) (3 diffs)
-
TestRunner/Runner/PHPUnit.php (modified) (2 diffs)
-
TestRunner/Runner/SimpleTest.php (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/Stagehand/TestRunner.php
r148 r163 143 143 -a watch for changes in one or more directories and run tests in the test directory recursively when changes are detected (autotest) 144 144 -w <directory1,directory2,...> specify one or more directories to be watched for changes 145 -g notify test results to Growl 145 146 146 147 With no [directory or file], run all tests in the current directory. … … 231 232 } 232 233 234 if ($config->useGrowl) { 235 $options[] = '-g'; 236 } 237 233 238 $options[] = $config->directory; 234 239 … … 260 265 array_shift($argv); 261 266 PEAR::staticPushErrorHandling(PEAR_ERROR_RETURN); 262 $allOptions = Console_Getopt::getopt2($argv, 'hVRcp:aw: ');267 $allOptions = Console_Getopt::getopt2($argv, 'hVRcp:aw:g'); 263 268 PEAR::staticPopErrorHandling(); 264 269 if (PEAR::isError($allOptions)) { … … 272 277 $preloadFile = null; 273 278 $targetDirectories = array(); 279 $useGrowl = false; 274 280 foreach ($allOptions as $options) { 275 281 if (!count($options)) { … … 303 309 $targetDirectories = explode(',', $option[1]); 304 310 break; 311 case 'g': 312 if (@include_once 'Net/Growl.php') { 313 $useGrowl = true; 314 } 315 break; 305 316 } 306 317 } else { … … 315 326 'enableAutotest' => $enableAutotest, 316 327 'preloadFile' => $preloadFile, 317 'targetDirectories' => $targetDirectories 328 'targetDirectories' => $targetDirectories, 329 'useGrowl' => $useGrowl 318 330 ); 319 331 } … … 339 351 $className = "Stagehand_TestRunner_Runner_$testRunnerName"; 340 352 $runner = new $className(); 341 $runner->run($suite, $config->color); 353 $runner->run($suite, $config); 354 355 if ($config->useGrowl) { 356 $notification = $runner->getNotification(); 357 $application = new Net_Growl_Application('Stagehand_TestRunner', 358 array('Green', 'Red') 359 ); 360 $growl = new Net_Growl($application); 361 $growl->notify($notification->name, 362 'Test Results by Stagehand_TestRunner', 363 $notification->description 364 ); 365 } 342 366 } 343 367 -
trunk/src/Stagehand/TestRunner/IRunner.php
r120 r163 60 60 * Runs tests based on the given test suite. 61 61 * 62 * @param mixed $suite63 * @param boolean $color62 * @param mixed $suite 63 * @param stdClass $config 64 64 */ 65 public function run($suite, $color); 65 public function run($suite, $config); 66 67 // }}} 68 // {{{ getNotification() 69 70 /** 71 * Gets a notification object for Growl. 72 * 73 * @return stdClass 74 */ 75 public function getNotification(); 66 76 67 77 /**#@-*/ -
trunk/src/Stagehand/TestRunner/Runner/PHPSpec.php
r120 r163 74 74 */ 75 75 76 private $_notification; 77 76 78 /**#@-*/ 77 79 … … 87 89 * 88 90 * @param ArrayObject $suite 89 * @param boolean $color91 * @param stdClass $config 90 92 */ 91 public function run($suite, $co lor)93 public function run($suite, $config) 92 94 { 93 95 $result = new PHPSpec_Runner_Result(); 94 $reporter = new Stagehand_TestRunner_Runner_PHPSpec_Reporter($result, $color); 96 $reporter = new Stagehand_TestRunner_Runner_PHPSpec_Reporter($result, 97 $config->color 98 ); 95 99 $result->setReporter($reporter); 96 100 … … 103 107 104 108 $reporter->output(true); 109 110 if ($config->useGrowl) { 111 $output = $reporter->toString(true); 112 113 $failuresCount = $result->countFailures(); 114 $deliberateFailuresCount = $result->countDeliberateFailures(); 115 $errorsCount = $result->countErrors(); 116 $exceptionsCount = $result->countExceptions(); 117 $pendingsCount = $result->countPending(); 118 119 $this->_notification = new stdClass(); 120 if ($failuresCount + $deliberateFailuresCount + $errorsCount + $exceptionsCount + $pendingsCount == 0) { 121 $this->_notification->name = 'Green'; 122 } elseif ($pendingsCount && $failuresCount + $deliberateFailuresCount + $errorsCount + $exceptionsCount == 0) { 123 $this->_notification->name = 'Green'; 124 } else { 125 $this->_notification->name = 'Red'; 126 } 127 128 preg_match('/^(\d+ examples?, \d+ failures?.*)/m', $output, $matches); 129 $this->_notification->description = $matches[1]; 130 } 131 } 132 133 // }}} 134 // {{{ getNotification() 135 136 /** 137 * Gets a notification object for Growl. 138 * 139 * @return stdClass 140 */ 141 public function getNotification() 142 { 143 return $this->_notification; 105 144 } 106 145 -
trunk/src/Stagehand/TestRunner/Runner/PHPUnit.php
r139 r163 75 75 */ 76 76 77 private $_notification; 78 77 79 /**#@-*/ 78 80 … … 88 90 * 89 91 * @param PHPUnit_Framework_TestSuite $suite 90 * @param boolean $color92 * @param stdClass $config 91 93 */ 92 public function run($suite, $co lor)94 public function run($suite, $config) 93 95 { 94 96 $parameters = array(); 95 if ($co lor) {97 if ($config->color) { 96 98 include_once 'Stagehand/TestRunner/Runner/PHPUnit/ResultPrinter.php'; 97 99 $parameters['printer'] = new Stagehand_TestRunner_Runner_PHPUnit_ResultPrinter(); 98 100 } 99 101 102 ob_start(); 100 103 PHPUnit_TextUI_TestRunner::run($suite, $parameters); 104 $output = ob_get_contents(); 105 ob_end_clean(); 106 107 print $output; 108 109 if ($config->useGrowl) { 110 if (preg_match('/^(?:\x1b\[3[23]m)?(OK[^\x1b]+)/ms', $output, $matches)) { 111 $this->_notification->name = 'Green'; 112 $this->_notification->description = $matches[1]; 113 } elseif (preg_match('/^(?:\x1b\[31m)?(FAILURES[^\x1b]+)/ms', $output, $matches)) { 114 $this->_notification->name = 'Red'; 115 $this->_notification->description = $matches[1]; 116 } 117 } 118 } 119 120 // }}} 121 // {{{ getNotification() 122 123 /** 124 * Gets a notification object for Growl. 125 * 126 * @return stdClass 127 */ 128 public function getNotification() 129 { 130 return $this->_notification; 101 131 } 102 132 -
trunk/src/Stagehand/TestRunner/Runner/SimpleTest.php
r120 r163 76 76 */ 77 77 78 private $_notification; 79 78 80 /**#@-*/ 79 81 … … 89 91 * 90 92 * @param TestSuite $suite 91 * @param boolean $color93 * @param stdClass $config 92 94 */ 93 public function run($suite, $co lor)95 public function run($suite, $config) 94 96 { 95 97 $reporter = new TextReporter(); … … 99 101 ob_end_clean(); 100 102 101 if ($color) { 103 if ($config->useGrowl) { 104 if (preg_match('/^(OK.+)/ms', $output, $matches)) { 105 $this->_notification->name = 'Green'; 106 $this->_notification->description = $matches[1]; 107 } elseif (preg_match('/^(FAILURES.+)/ms', $output, $matches)) { 108 $this->_notification->name = 'Red'; 109 $this->_notification->description = $matches[1]; 110 } 111 } 112 113 if ($config->color) { 102 114 include_once 'Console/Color.php'; 103 115 print Console_Color::convert(preg_replace(array('/^(OK.+)/ms', … … 116 128 print $output; 117 129 } 130 } 131 132 // }}} 133 // {{{ getNotification() 134 135 /** 136 * Gets a notification object for Growl. 137 * 138 * @return stdClass 139 */ 140 public function getNotification() 141 { 142 return $this->_notification; 118 143 } 119 144
