PHPUnit_TestSuite

A TestSuite is a Composite of Tests.

Defined (1)

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

/src/xmlrpc-3.0/test/PHPUnit/TestSuite.php  
  1. class PHPUnit_TestSuite { 
  2. /** 
  3. * The name of the test suite. 
  4. * @var string 
  5. * @access private 
  6. */ 
  7. var $_name = ''; 
  8.  
  9. /** 
  10. * The tests in the test suite. 
  11. * @var array 
  12. * @access private 
  13. */ 
  14. var $_tests = array(); 
  15.  
  16. /** 
  17. * Constructs a TestSuite. 
  18. * @param mixed 
  19. * @access public 
  20. */ 
  21. function PHPUnit_TestSuite($test = FALSE) { 
  22. if ($test !== FALSE) { 
  23. $this->setName($test); 
  24. $this->addTestSuite($test); 
  25.  
  26. /** 
  27. * Adds a test to the suite. 
  28. * @param object 
  29. * @access public 
  30. */ 
  31. function addTest(&$test) { 
  32. $this->_tests[] = &$test; 
  33.  
  34. /** 
  35. * Adds the tests from the given class to the suite. 
  36. * @param string 
  37. * @access public 
  38. */ 
  39. function addTestSuite($testClass) { 
  40. if (class_exists($testClass)) { 
  41. $methods = get_class_methods($testClass); 
  42. $parentClasses = array(strtolower($testClass)); 
  43. $parentClass = $testClass; 
  44.  
  45. while(is_string($parentClass = get_parent_class($parentClass))) { 
  46. $parentClasses[] = $parentClass; 
  47.  
  48. foreach ($methods as $method) { 
  49. if (substr($method, 0, 4) == 'test' && 
  50. !in_array($method, $parentClasses)) { 
  51. $this->addTest(new $testClass($method)); 
  52.  
  53. /** 
  54. * Counts the number of test cases that will be run by this test. 
  55. * @return integer 
  56. * @access public 
  57. */ 
  58. function countTestCases() { 
  59. $count = 0; 
  60.  
  61. foreach ($this->_tests as $test) { 
  62. $count += $test->countTestCases(); 
  63.  
  64. return $count; 
  65.  
  66. /** 
  67. * Returns the name of the suite. 
  68. * @return string 
  69. * @access public 
  70. */ 
  71. function getName() { 
  72. return $this->_name; 
  73.  
  74. /** 
  75. * Runs the tests and collects their result in a TestResult. 
  76. * @param object 
  77. * @access public 
  78. */ 
  79. function run(&$result, $show_progress='') { 
  80. for ($i = 0; $i < sizeof($this->_tests) && !$result->shouldStop(); $i++) { 
  81. $this->_tests[$i]->run($result); 
  82. if ($show_progress != '') { 
  83. echo $show_progress; flush(); @ob_flush(); 
  84.  
  85. /** 
  86. * Runs a test. 
  87. * @param object 
  88. * @param object 
  89. * @access public 
  90. */ 
  91. function runTest(&$test, &$result) { 
  92. $test->run($result); 
  93.  
  94. /** 
  95. * Sets the name of the suite. 
  96. * @param string 
  97. * @access public 
  98. */ 
  99. function setName($name) { 
  100. $this->_name = $name; 
  101.  
  102. /** 
  103. * Returns the test at the given index. 
  104. * @param integer 
  105. * @return object 
  106. * @access public 
  107. */ 
  108. function &testAt($index) { 
  109. if (isset($this->_tests[$index])) { 
  110. return $this->_tests[$index]; 
  111. } else { 
  112. return FALSE; 
  113.  
  114. /** 
  115. * Returns the number of tests in this suite. 
  116. * @return integer 
  117. * @access public 
  118. */ 
  119. function testCount() { 
  120. return sizeof($this->_tests); 
  121.  
  122. /** 
  123. * Returns the tests as an enumeration. 
  124. * @return array 
  125. * @access public 
  126. */ 
  127. function &tests() { 
  128. return $this->_tests; 
  129.  
  130. /** 
  131. * Returns a string representation of the test suite. 
  132. * @return string 
  133. * @access public 
  134. */ 
  135. function toString() { 
  136. return '';