PHPUnit_TestCase

Adapter for PEAR PHPUnit test case to allow legacy PEAR test cases to be used with SimpleTest.

Defined (1)

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

/src/xmlrpc-3.0/test/PHPUnit/TestCase.php  
  1. class PHPUnit_TestCase extends PHPUnit_Assert { 
  2. /** 
  3. * @var boolean 
  4. * @access private 
  5. */ 
  6. var $_failed = FALSE; 
  7.  
  8. /** 
  9. * The name of the test case. 
  10. * @var string 
  11. * @access private 
  12. */ 
  13. var $_name = ''; 
  14.  
  15. /** 
  16. * PHPUnit_TestResult object 
  17. * @var object 
  18. * @access private 
  19. */ 
  20. var $_result; 
  21.  
  22. /** 
  23. * Constructs a test case with the given name. 
  24. * @param string 
  25. * @access public 
  26. */ 
  27. function PHPUnit_TestCase($name = FALSE) { 
  28. if ($name !== FALSE) { 
  29. $this->setName($name); 
  30.  
  31. /** 
  32. * Counts the number of test cases executed by run(TestResult result). 
  33. * @return integer 
  34. * @access public 
  35. */ 
  36. function countTestCases() { 
  37. return 1; 
  38.  
  39. /** 
  40. * Gets the name of a TestCase. 
  41. * @return string 
  42. * @access public 
  43. */ 
  44. function getName() { 
  45. return $this->_name; 
  46.  
  47. /** 
  48. * Runs the test case and collects the results in a given TestResult object. 
  49. * @param object 
  50. * @return object 
  51. * @access public 
  52. */ 
  53. function run(&$result) { 
  54. $this->_result = &$result; 
  55. $this->_result->run($this); 
  56.  
  57. return $this->_result; 
  58.  
  59. /** 
  60. * Runs the bare test sequence. 
  61. * @access public 
  62. */ 
  63. function runBare() { 
  64. $this->setUp(); 
  65. $this->runTest(); 
  66. $this->tearDown(); 
  67. $this->pass(); 
  68.  
  69. /** 
  70. * Override to run the test and assert its state. 
  71. * @access protected 
  72. */ 
  73. function runTest() { 
  74. call_user_func( 
  75. array( 
  76. &$this,  
  77. $this->_name 
  78. ); 
  79.  
  80. /** 
  81. * Sets the name of a TestCase. 
  82. * @param string 
  83. * @access public 
  84. */ 
  85. function setName($name) { 
  86. $this->_name = $name; 
  87.  
  88. /** 
  89. * Returns a string representation of the test case. 
  90. * @return string 
  91. * @access public 
  92. */ 
  93. function toString() { 
  94. return ''; 
  95.  
  96. /** 
  97. * Creates a default TestResult object. 
  98. * @return object 
  99. * @access protected 
  100. */ 
  101. function &createResult() { 
  102. return new PHPUnit_TestResult; 
  103.  
  104. /** 
  105. * Fails a test with the given message. 
  106. * @param string 
  107. * @access protected 
  108. */ 
  109. function fail($message = '') { 
  110. if (function_exists('debug_backtrace')) { 
  111. $trace = debug_backtrace(); 
  112.  
  113. if (isset($trace['1']['file'])) { 
  114. $message = sprintf( 
  115. "%s in %s:%s",  
  116.  
  117. $message,  
  118. $trace['1']['file'],  
  119. $trace['1']['line'] 
  120. ); 
  121.  
  122. $this->_result->addFailure($this, $message); 
  123. $this->_failed = TRUE; 
  124.  
  125. /** 
  126. * Passes a test. 
  127. * @access protected 
  128. */ 
  129. function pass() { 
  130. if (!$this->_failed) { 
  131. $this->_result->addPassedTest($this); 
  132.  
  133. /** 
  134. * Sets up the fixture, for example, open a network connection. 
  135. * This method is called before a test is executed. 
  136. * @access protected 
  137. * @abstract 
  138. */ 
  139. function setUp() { /** abstract */ } 
  140.  
  141. /** 
  142. * Tears down the fixture, for example, close a network connection. 
  143. * This method is called after a test is executed. 
  144. * @access protected 
  145. * @abstract 
  146. */ 
  147. function tearDown() { /** abstract */ }