PHPUnit_TestResult

A TestResult collects the results of executing a test case.

Defined (1)

The class is defined in the following location(s).

/src/xmlrpc-3.0/test/PHPUnit/TestResult.php  
  1. class PHPUnit_TestResult { 
  2. /** 
  3. * @var array 
  4. * @access protected 
  5. */ 
  6. var $_errors = array(); 
  7.  
  8. /** 
  9. * @var array 
  10. * @access protected 
  11. */ 
  12. var $_failures = array(); 
  13.  
  14. /** 
  15. * @var array 
  16. * @access protected 
  17. */ 
  18. var $_listeners = array(); 
  19.  
  20. /** 
  21. * @var array 
  22. * @access protected 
  23. */ 
  24. var $_passedTests = array(); 
  25.  
  26. /** 
  27. * @var integer 
  28. * @access protected 
  29. */ 
  30. var $_runTests = 0; 
  31.  
  32. /** 
  33. * @var boolean 
  34. * @access private 
  35. */ 
  36. var $_stop = FALSE; 
  37.  
  38. /** 
  39. * Adds an error to the list of errors. 
  40. * The passed in exception caused the error. 
  41. * @param object 
  42. * @param object 
  43. * @access public 
  44. */ 
  45. function addError(&$test, &$t) { 
  46. $this->_errors[] = new PHPUnit_TestFailure($test, $t); 
  47.  
  48. for ($i = 0; $i < sizeof($this->_listeners); $i++) { 
  49. $this->_listeners[$i]->addError($test, $t); 
  50.  
  51. /** 
  52. * Adds a failure to the list of failures. 
  53. * The passed in exception caused the failure. 
  54. * @param object 
  55. * @param object 
  56. * @access public 
  57. */ 
  58. function addFailure(&$test, &$t) { 
  59. $this->_failures[] = new PHPUnit_TestFailure($test, $t); 
  60.  
  61. for ($i = 0; $i < sizeof($this->_listeners); $i++) { 
  62. $this->_listeners[$i]->addFailure($test, $t); 
  63.  
  64. /** 
  65. * Registers a TestListener. 
  66. * @param object 
  67. * @access public 
  68. */ 
  69. function addListener(&$listener) { 
  70. if (is_object($listener) && 
  71. is_a($listener, 'PHPUnit_TestListener')) { 
  72. $this->_listeners[] = &$listener; 
  73.  
  74. /** 
  75. * Adds a passed test to the list of passed tests. 
  76. * @param object 
  77. * @access public 
  78. */ 
  79. function addPassedTest(&$test) { 
  80. $this->_passedTests[] = &$test; 
  81.  
  82. /** 
  83. * Informs the result that a test was completed. 
  84. * @param object 
  85. * @access public 
  86. */ 
  87. function endTest(&$test) { 
  88. for ($i = 0; $i < sizeof($this->_listeners); $i++) { 
  89. $this->_listeners[$i]->endTest($test); 
  90.  
  91. /** 
  92. * Gets the number of detected errors. 
  93. * @return integer 
  94. * @access public 
  95. */ 
  96. function errorCount() { 
  97. return sizeof($this->_errors); 
  98.  
  99. /** 
  100. * Returns an Enumeration for the errors. 
  101. * @return array 
  102. * @access public 
  103. */ 
  104. function &errors() { 
  105. return $this->_errors; 
  106.  
  107. /** 
  108. * Gets the number of detected failures. 
  109. * @return integer 
  110. * @access public 
  111. */ 
  112. function failureCount() { 
  113. return sizeof($this->_failures); 
  114.  
  115. /** 
  116. * Returns an Enumeration for the failures. 
  117. * @return array 
  118. * @access public 
  119. */ 
  120. function &failures() { 
  121. return $this->_failures; 
  122.  
  123. /** 
  124. * Returns an Enumeration for the passed tests. 
  125. * @return array 
  126. * @access public 
  127. */ 
  128. function &passedTests() { 
  129. return $this->_passedTests; 
  130.  
  131. /** 
  132. * Unregisters a TestListener. 
  133. * This requires the Zend Engine 2 (to work properly). 
  134. * @param object 
  135. * @access public 
  136. */ 
  137. function removeListener(&$listener) { 
  138. for ($i = 0; $i < sizeof($this->_listeners); $i++) { 
  139. if ($this->_listeners[$i] === $listener) { 
  140. unset($this->_listeners[$i]); 
  141.  
  142. /** 
  143. * Runs a TestCase. 
  144. * @param object 
  145. * @access public 
  146. */ 
  147. function run(&$test) { 
  148. $this->startTest($test); 
  149. $this->_runTests++; 
  150. $test->runBare(); 
  151. $this->endTest($test); 
  152.  
  153. /** 
  154. * Gets the number of run tests. 
  155. * @return integer 
  156. * @access public 
  157. */ 
  158. function runCount() { 
  159. return $this->_runTests; 
  160.  
  161. /** 
  162. * Checks whether the test run should stop. 
  163. * @access public 
  164. */ 
  165. function shouldStop() { 
  166. return $this->_stop; 
  167.  
  168. /** 
  169. * Informs the result that a test will be started. 
  170. * @param object 
  171. * @access public 
  172. */ 
  173. function startTest(&$test) { 
  174. for ($i = 0; $i < sizeof($this->_listeners); $i++) { 
  175. $this->_listeners[$i]->startTest($test); 
  176.  
  177. /** 
  178. * Marks that the test run should stop. 
  179. * @access public 
  180. */ 
  181. function stop() { 
  182. $this->_stop = TRUE; 
  183.  
  184. /** 
  185. * Returns a HTML representation of the test result. 
  186. * @return string 
  187. * @access public 
  188. */ 
  189. function toHTML() { 
  190. return '<pre>' . htmlspecialchars($this->toString()) . '</pre>'; 
  191.  
  192. /** 
  193. * Returns a text representation of the test result. 
  194. * @return string 
  195. * @access public 
  196. */ 
  197. function toString() { 
  198. $result = ''; 
  199.  
  200. foreach ($this->_passedTests as $passedTest) { 
  201. $result .= sprintf( 
  202. "TestCase %s->%s() passed\n",  
  203.  
  204. get_class($passedTest),  
  205. $passedTest->getName() 
  206. ); 
  207.  
  208. foreach ($this->_failures as $failedTest) { 
  209. $result .= $failedTest->toString(); 
  210.  
  211. return $result; 
  212.  
  213. /** 
  214. * Returns whether the entire test was successful or not. 
  215. * @return boolean 
  216. * @access public 
  217. */ 
  218. function wasSuccessful() { 
  219. if (empty($this->_errors) && empty($this->_failures)) { 
  220. return TRUE; 
  221. } else { 
  222. return FALSE;