2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
7 * LICENSE: This source file is subject to version 3.0 of the PHP license
8 * that is available through the world-wide-web at the following URI:
9 * http://www.php.net/license/3_0.txt. If you did not receive a copy of
10 * the PHP License and are unable to obtain it through the web, please
11 * send a note to license@php.net so we can mail you a copy immediately.
15 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
16 * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
17 * @license http://www.php.net/license/3_0.txt PHP License 3.0
19 * @link http://pear.php.net/package/PHPUnit
20 * @since File available since Release 1.0.0
23 require_once 'PHPUnit/TestCase.php';
26 * A TestSuite is a Composite of Tests. It runs a collection of test cases.
28 * Here is an example using the dynamic test definition.
32 * $suite = new PHPUnit_TestSuite();
33 * $suite->addTest(new MathTest('testPass'));
37 * Alternatively, a TestSuite can extract the tests to be run automatically.
38 * To do so you pass the classname of your TestCase class to the TestSuite
43 * $suite = new TestSuite('classname');
47 * This constructor creates a suite with all the methods starting with
48 * "test" that take no arguments.
52 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
53 * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
54 * @license http://www.php.net/license/3_0.txt PHP License 3.0
55 * @version Release: @package_version@
56 * @link http://pear.php.net/package/PHPUnit
57 * @since Class available since Release 1.0.0
59 class PHPUnit_TestSuite {
61 * The name of the test suite.
69 * The tests in the test suite.
74 var $_tests = array();
77 * Constructs a TestSuite.
82 function PHPUnit_TestSuite($test = FALSE) {
83 if ($test !== FALSE) {
84 $this->setName($test);
85 $this->addTestSuite($test);
90 * Adds a test to the suite.
95 function addTest(&$test) {
96 $this->_tests[] = &$test;
100 * Adds the tests from the given class to the suite.
105 function addTestSuite($testClass) {
106 if (class_exists($testClass)) {
107 $methods = get_class_methods($testClass);
108 $parentClasses = array(strtolower($testClass));
109 $parentClass = $testClass;
111 while(is_string($parentClass = get_parent_class($parentClass))) {
112 $parentClasses[] = $parentClass;
115 foreach ($methods as $method) {
116 if (substr($method, 0, 4) == 'test' &&
117 !in_array($method, $parentClasses)) {
118 $this->addTest(new $testClass($method));
125 * Counts the number of test cases that will be run by this test.
130 function countTestCases() {
133 foreach ($this->_tests as $test) {
134 $count += $test->countTestCases();
141 * Returns the name of the suite.
151 * Runs the tests and collects their result in a TestResult.
156 function run(&$result, $show_progress='') {
157 for ($i = 0; $i < sizeof($this->_tests) && !$result->shouldStop(); $i++) {
158 $this->_tests[$i]->run($result);
159 if ($show_progress != '') {
160 echo $show_progress; flush(); @ob_flush();
172 function runTest(&$test, &$result) {
177 * Sets the name of the suite.
182 function setName($name) {
183 $this->_name = $name;
187 * Returns the test at the given index.
193 function &testAt($index) {
194 if (isset($this->_tests[$index])) {
195 return $this->_tests[$index];
202 * Returns the number of tests in this suite.
207 function testCount() {
208 return sizeof($this->_tests);
212 * Returns the tests as an enumeration.
218 return $this->_tests;
222 * Returns a string representation of the test suite.
227 function toString() {
236 * c-hanging-comment-ender-p: nil