[ Index ] |
|
Code source de LifeType 1.2.4 |
1 <?php 2 3 lt_include( PLOG_CLASS_PATH."class/test/PHPUnit/TestResult.php" ); 4 lt_include( PLOG_CLASS_PATH."class/test/PHPUnit/TestListener.php" ); 5 6 /** 7 * \ingroup Test 8 * 9 * Reporter class that generates output suitable for a terminal console 10 */ 11 class ConsoleReporter 12 { 13 var $_result; 14 15 function ConsoleReporter( $result ) 16 { 17 $this->_result = $result; 18 } 19 20 function _getHeader() 21 { 22 return("\nFailed tests\n------------\n"); 23 } 24 25 function _getFooter() 26 { 27 return( $this->_getStats()); 28 } 29 30 function _cleanGroupName( $group ) 31 { 32 $group = strtolower( $group ); 33 $group = str_replace( "_test", "", $group ); 34 return( $group ); 35 } 36 37 function _getPassed( $test, $group = "" ) 38 { 39 return( "[".$this->_cleanGroupName($group)."] ".$test->getName()." => PASSED\n" ); 40 } 41 42 function _getFailed( $test, $group = "" ) 43 { 44 return( "[".$this->_cleanGroupName($group)."] ".$test->_failedTest->getName()." => FAILED: ".$test->_thrownException."\n" ); 45 } 46 47 function _getStats() 48 { 49 return( " 50 Test Stats 51 ---------- 52 * Number of tests: ".$this->_result->runCount()." 53 * Number of tests passed: ".($this->_result->runCount() - $this->_result->failureCount())." 54 * Number of tests failed: ".$this->_result->failureCount()."\n" 55 ); 56 } 57 58 function generate() 59 { 60 $groups = $this->_prepare(); 61 62 $result = $this->_getHeader(); 63 64 foreach( $groups as $group => $tests ) { 65 foreach( $tests as $test ) { 66 if( isset( $test->_failedTest )) { 67 $result .= $this->_getFailed( $test, $group ); 68 } 69 /*else { 70 $result .= $this->_getPassed( $test, $group ); 71 }*/ 72 } 73 } 74 75 $result .= $this->_getFooter(); 76 return( $result ); 77 } 78 79 function _prepare() 80 { 81 $groups = Array(); 82 foreach ($this->_result->_passedTests as $passedTest) { 83 $groups[get_class($passedTest)][] = $passedTest; 84 } 85 foreach ($this->_result->_failures as $failedTest) { 86 $groups[get_class($failedTest->_failedTest)][] = $failedTest; 87 } 88 89 return( $groups ); 90 } 91 } 92 93 /** 94 * A listener class to do "live" reporting to the console 95 */ 96 class ConsoleReporterListener extends PHPUnit_TestListener 97 { 98 function startTest(&$test) { 99 print( "Executing test [".ConsoleReporter::_cleanGroupName(get_class($test))."] ".$test->getName()." ... " ); 100 } 101 102 function endTest(&$test) { 103 if( !$test->_failed ) 104 print( "DONE\n" ); 105 } 106 107 function addFailure(&$test) 108 { 109 print("FAILED\n"); 110 $test->_failed = true; 111 } 112 } 113 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 21:04:15 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |