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/Assert.php';
24 require_once 'PHPUnit/TestResult.php';
27 * A TestCase defines the fixture to run multiple tests.
29 * To define a TestCase
31 * 1) Implement a subclass of PHPUnit_TestCase.
32 * 2) Define instance variables that store the state of the fixture.
33 * 3) Initialize the fixture state by overriding setUp().
34 * 4) Clean-up after a test by overriding tearDown().
36 * Each test runs in its own fixture so there can be no side effects
43 * class MathTest extends PHPUnit_TestCase {
47 * function MathTest($name) {
48 * $this->PHPUnit_TestCase($name);
59 * For each test implement a method which interacts with the fixture.
60 * Verify the expected results with assertions specified by calling
61 * assert with a boolean.
65 * function testPass() {
66 * $this->assertTrue($this->fValue1 + $this->fValue2 == 5);
73 * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
74 * @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
75 * @license http://www.php.net/license/3_0.txt PHP License 3.0
76 * @version Release: @package_version@
77 * @link http://pear.php.net/package/PHPUnit
78 * @since Class available since Release 1.0.0
80 class PHPUnit_TestCase extends PHPUnit_Assert {
88 * The name of the test case.
96 * PHPUnit_TestResult object
104 * Constructs a test case with the given name.
109 function PHPUnit_TestCase($name = FALSE) {
110 if ($name !== FALSE) {
111 $this->setName($name);
116 * Counts the number of test cases executed by run(TestResult result).
121 function countTestCases() {
126 * Gets the name of a TestCase.
136 * Runs the test case and collects the results in a given TestResult object.
142 function run(&$result) {
143 $this->_result = &$result;
144 $this->_result->run($this);
146 return $this->_result;
150 * Runs the bare test sequence.
162 * Override to run the test and assert its state.
176 * Sets the name of a TestCase.
181 function setName($name) {
182 $this->_name = $name;
186 * Returns a string representation of the test case.
191 function toString() {
196 * Creates a default TestResult object.
201 function &createResult() {
202 return new PHPUnit_TestResult;
206 * Fails a test with the given message.
211 function fail($message = '') {
212 if (function_exists('debug_backtrace')) {
213 $trace = debug_backtrace();
215 if (isset($trace['1']['file'])) {
226 $this->_result->addFailure($this, $message);
227 $this->_failed = TRUE;
236 if (!$this->_failed) {
237 $this->_result->addPassedTest($this);
242 * Sets up the fixture, for example, open a network connection.
243 * This method is called before a test is executed.
248 function setUp() { /* abstract */ }
251 * Tears down the fixture, for example, close a network connection.
252 * This method is called after a test is executed.
257 function tearDown() { /* abstract */ }
264 * c-hanging-comment-ender-p: nil