00001 <?php 00002 // $Id: scorer.php,v 1.1 2008/04/20 18:34:43 dries Exp $ 00003 00012 class SimpleScorer { 00013 var$_passes; 00014 var$_fails; 00015 var$_exceptions; 00016 var$_is_dry_run; 00017 00022 function SimpleScorer() { 00023 $this->_passes = 0; 00024 $this->_fails = 0; 00025 $this->_exceptions = 0; 00026 $this->_is_dry_run = false; 00027 } 00028 00036 function makeDry($is_dry = true) { 00037 $this->_is_dry_run = $is_dry; 00038 } 00039 00046 function shouldInvoke($test_case_name, $method) { 00047 return !$this->_is_dry_run; 00048 } 00049 00057 function & createInvoker(&$invoker) { 00058 return $invoker; 00059 } 00060 00068 function getStatus() { 00069 if ($this->_exceptions + $this->_fails > 0) { 00070 return false; 00071 } 00072 return true; 00073 } 00074 00081 function paintGroupStart($test_name, $size) {} 00082 00088 function paintGroupEnd($test_name) {} 00089 00095 function paintCaseStart($test_name) {} 00096 00102 function paintCaseEnd($test_name) {} 00103 00109 function paintMethodStart($test_name) {} 00110 00116 function paintMethodEnd($test_name) {} 00117 00123 function paintPass($message) { 00124 $this->_passes++; 00125 } 00126 00132 function paintFail($message) { 00133 $this->_fails++; 00134 } 00135 00142 function paintError($message) { 00143 $this->_exceptions++; 00144 } 00145 00151 function paintException($exception) { 00152 $this->_exceptions++; 00153 } 00154 00160 function paintSkip($message) {} 00161 00167 function getPassCount() { 00168 return $this->_passes; 00169 } 00170 00176 function getFailCount() { 00177 return $this->_fails; 00178 } 00179 00186 function getExceptionCount() { 00187 return $this->_exceptions; 00188 } 00189 00195 function paintMessage($message) {} 00196 00203 function paintFormattedMessage($message) {} 00204 00211 function paintSignal($type, $payload) {} 00212 } 00213 00222 class SimpleReporter extends SimpleScorer { 00223 var$_test_stack; 00224 var$_size; 00225 var$_progress; 00226 00231 function SimpleReporter() { 00232 $this->SimpleScorer(); 00233 $this->_test_stack = array(); 00234 $this->_size = null; 00235 $this->_progress = 0; 00236 } 00237 00244 function getDumper() { 00245 return new SimpleDumper(); 00246 } 00247 00257 function paintGroupStart($test_name, $size) { 00258 if (!isset($this->_size)) { 00259 $this->_size = $size; 00260 } 00261 if (count($this->_test_stack) == 0) { 00262 $this->paintHeader($test_name); 00263 } 00264 $this->_test_stack[] = $test_name; 00265 } 00266 00274 function paintGroupEnd($test_name) { 00275 array_pop($this->_test_stack); 00276 if (count($this->_test_stack) == 0) { 00277 $this->paintFooter($test_name); 00278 } 00279 } 00280 00289 function paintCaseStart($test_name) { 00290 if (!isset($this->_size)) { 00291 $this->_size = 1; 00292 } 00293 if (count($this->_test_stack) == 0) { 00294 $this->paintHeader($test_name); 00295 } 00296 $this->_test_stack[] = $test_name; 00297 } 00298 00305 function paintCaseEnd($test_name) { 00306 $this->_progress++; 00307 array_pop($this->_test_stack); 00308 if (count($this->_test_stack) == 0) { 00309 $this->paintFooter($test_name); 00310 } 00311 } 00312 00318 function paintMethodStart($test_name) { 00319 $this->_test_stack[] = $test_name; 00320 } 00321 00328 function paintMethodEnd($test_name) { 00329 array_pop($this->_test_stack); 00330 } 00331 00339 function paintHeader($test_name) {} 00340 00347 function paintFooter($test_name) {} 00348 00356 function getTestList() { 00357 return $this->_test_stack; 00358 } 00359 00367 function getTestCaseCount() { 00368 return $this->_size; 00369 } 00370 00377 function getTestCaseProgress() { 00378 return $this->_progress; 00379 } 00380 00387 function inCli() { 00388 return php_sapi_name() == 'cli'; 00389 } 00390 } 00391 00397 class SimpleReporterDecorator { 00398 var $_reporter; 00399 00404 function __construct(&$reporter) { 00405 $this->_reporter = &$reporter; 00406 } 00407 00408 function __call($method, $arguments) { 00409 if (method_exists($this->_reporter, $method)) { 00410 return call_user_func_array($this->_reporter->$method, $arguments); 00411 } 00412 } 00413 }