| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * base include file for eclipse plugin 4 * @package SimpleTest 5 * @subpackage Eclipse 6 * @version $Id: eclipse.php 5999 2007-06-18 13:13:08Z pachanga $ 7 */ 8 /**#@+ 9 * simpletest include files 10 */ 11 include_once 'unit_tester.php'; 12 include_once 'test_case.php'; 13 include_once 'invoker.php'; 14 include_once 'socket.php'; 15 include_once 'mock_objects.php'; 16 /**#@-*/ 17 18 /** 19 * base reported class for eclipse plugin 20 * @package SimpleTest 21 * @subpackage Eclipse 22 */ 23 class EclipseReporter extends SimpleScorer { 24 function EclipseReporter(&$listener,$cc=false){ 25 $this->_listener = &$listener; 26 $this->SimpleScorer(); 27 $this->_case = ""; 28 $this->_group = ""; 29 $this->_method = ""; 30 $this->_cc = $cc; 31 $this->_error = false; 32 $this->_fail = false; 33 } 34 35 function getDumper() { 36 return new SimpleDumper(); 37 } 38 39 function &createListener($port,$host="127.0.0.1"){ 40 $tmplistener = & new SimpleSocket($host,$port,5); 41 return $tmplistener; 42 } 43 44 function &createInvoker(&$invoker){ 45 $eclinvoker = & new EclipseInvoker( $invoker, $this->_listener); 46 return $eclinvoker; 47 } 48 49 function escapeVal($val){ 50 $needle = array("\\","\"","/","\b","\f","\n","\r","\t"); 51 $replace = array('\\\\','\"','\/','\b','\f','\n','\r','\t'); 52 return str_replace($needle,$replace,$val); 53 } 54 55 function paintPass($message){ 56 //get the first passing item -- so that clicking the test item goes to first pass 57 if (!$this->_pass){ 58 $this->_message = $this->escapeVal($message); 59 } 60 $this->_pass = true; 61 } 62 63 function paintFail($message){ 64 //only get the first failure or error 65 if (!$this->_fail && !$this->_error){ 66 $this->_fail = true; 67 $this->_message = $this->escapeVal($message); 68 $this->_listener->write('{status:"fail",message:"'.$this->_message.'",group:"'.$this->_group.'",case:"'.$this->_case.'",method:"'.$this->_method.'"}'); 69 } 70 } 71 72 function paintError($message){ 73 //only get the first failure or error 74 if (!$this->_fail && !$this->_error){ 75 $this->_error = true; 76 $this->_message = $this->escapeVal($message); 77 $this->_listener->write('{status:"error",message:"'.$this->_message.'",group:"'.$this->_group.'",case:"'.$this->_case.'",method:"'.$this->_method.'"}'); 78 } 79 } 80 81 function paintHeader($method){ 82 } 83 84 function paintFooter($method){ 85 } 86 87 function paintMethodStart($method) { 88 $this->_pass = false; 89 $this->_fail = false; 90 $this->_error = false; 91 $this->_method = $this->escapeVal($method); 92 } 93 94 function paintMethodEnd($method){ 95 if ($this->_fail || $this->_error || !$this->_pass){ 96 //do nothing 97 }else{ 98 //this ensures we only get one message per method that passes 99 $this->_listener->write('{status:"pass",message:"'.$this->_message.'",group:"'.$this->_group.'",case:"'.$this->_case.'",method:"'.$this->_method.'"}'); 100 } 101 } 102 103 function paintCaseStart($case){ 104 $this->_case = $this->escapeVal($case); 105 } 106 107 function paintCaseEnd($case){ 108 $this->_case = ""; 109 } 110 function paintGroupStart($group,$size){ 111 $this->_group = $this->escapeVal($group); 112 if ($this->_cc){ 113 if (extension_loaded('xdebug')){ 114 xdebug_start_code_coverage(XDEBUG_CC_UNUSED| XDEBUG_CC_DEAD_CODE); 115 } 116 } 117 } 118 function paintGroupEnd($group){ 119 $this->_group = ""; 120 $cc = ""; 121 if ($this->_cc){ 122 if (extension_loaded('xdebug')){ 123 $arrfiles = xdebug_get_code_coverage(); 124 xdebug_stop_code_coverage(); 125 $thisdir = dirname(__FILE__); 126 $thisdirlen = strlen($thisdir); 127 foreach ($arrfiles as $index=>$file){ 128 if (substr($index,0,$thisdirlen)===$thisdir){ 129 continue; 130 } 131 $lcnt = 0; 132 $ccnt = 0; 133 foreach ($file as $line){ 134 if ($line == -2){ 135 continue; 136 } 137 $lcnt++; 138 if ($line==1){ 139 $ccnt++; 140 } 141 } 142 if ($lcnt > 0){ 143 $cc.=round(($ccnt/$lcnt)*100,2).'%'; 144 }else{ 145 $cc.="0.00%"; 146 } 147 $cc.= "\t".$index."\n"; 148 } 149 } 150 } 151 $this->_listener->write('{status:"coverage",message:"'.EclipseReporter::escapeVal($cc).'"}'); 152 } 153 } 154 155 /** 156 * base invoker class for eclipse plugin 157 * @package SimpleTest 158 * @subpackage Eclipse 159 */ 160 class EclipseInvoker extends SimpleInvokerDecorator{ 161 function EclipseInvoker(&$invoker,&$listener) { 162 $this->_listener = &$listener; 163 $this->SimpleInvokerDecorator($invoker); 164 } 165 166 function before($method){ 167 ob_start(); 168 $this->_invoker->before($method); 169 } 170 171 function after($method) { 172 $this->_invoker->after($method); 173 $output = ob_get_contents(); 174 ob_end_clean(); 175 if ($output!==""){ 176 $result = $this->_listener->write('{status:"info",message:"'.EclipseReporter::escapeVal($output).'"}'); 177 } 178 } 179 180 181 } 182 183 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Nov 22 03:48:54 2008 | Cross-referenced by PHPXref 0.7 |