Source for file TestCase.php
Documentation is available at TestCase.php
// +------------------------------------------------------------------------+
// +------------------------------------------------------------------------+
// | Copyright (c) 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>. |
// +------------------------------------------------------------------------+
// | This source file is subject to version 3.00 of the PHP License, |
// | that is available at http://www.php.net/license/3_0.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +------------------------------------------------------------------------+
// $Id: TestCase.php,v 1.19.2.3 2005/02/04 10:01:56 sebastian Exp $
require_once 'PHPUnit2/Framework/Assert.php';
require_once 'PHPUnit2/Framework/Error.php';
require_once 'PHPUnit2/Framework/Test.php';
require_once 'PHPUnit2/Framework/TestResult.php';
require_once 'PHPUnit2/Util/Filter.php';
* A TestCase defines the fixture to run multiple tests.
* 1) Implement a subclass of PHPUnit2_Framework_TestCase.
* 2) Define instance variables that store the state of the fixture.
* 3) Initialize the fixture state by overriding setUp().
* 4) Clean-up after a test by overriding tearDown().
* Each test runs in its own fixture so there can be no side effects
* require_once 'PHPUnit2/Framework/TestCase.php';
* class MathTest extends PHPUnit2_Framework_TestCase {
* public function __construct($name) {
* parent::__construct($name);
* public function setUp() {
* For each test implement a method which interacts with the fixture.
* Verify the expected results with assertions specified by calling
* public function testPass() {
* $this->assertTrue($this->value1 + $this->value2 == 5);
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright Copyright © 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.php.net/license/3_0.txt The PHP License, Version 3.0
// {{{ Instance Variables
* Code Coverage information provided by Xdebug.
private $codeCoverageInformation = array ();
* The name of the test case.
// {{{ public function __construct($name = NULL)
* Constructs a test case with the given name.
// {{{ public function toString()
* Returns a string representation of the test case.
$class = new ReflectionClass ($this);
// {{{ public function countTestCases()
* Counts the number of test cases executed by run(TestResult result).
// {{{ public function getCodeCoverageInformation()
* Returns the Code Coverage information provided by Xdebug.
return $this->codeCoverageInformation;
// {{{ public function getName()
* Gets the name of a TestCase.
// {{{ public function run($result = NULL)
* Runs the test case and collects the results in a TestResult object.
* If no TestResult object is passed a new one will be created.
* @param PHPUnit2_Framework_TestResult $result
* @return PHPUnit2_Framework_TestResult
public function run($result = NULL ) {
// XXX: Workaround for missing ability to declare type-hinted parameters as optional.
'Argument 1 must be an instance of PHPUnit2_Framework_TestResult.'
// {{{ public function runBare()
* Runs the bare test sequence.
$catchedException = NULL;
// Workaround for missing "finally".
if ($catchedException !== NULL ) {
// {{{ protected function runTest()
* Override to run the test and assert its state.
if ($this->name === NULL ) {
'PHPUnit2_Framework_TestCase::$name must not be NULL.'
$class = new ReflectionClass ($this);
$method = $class->getMethod ($this->name);
catch (ReflectionException $e) {
$this->fail($e->getMessage ());
xdebug_start_code_coverage (XDEBUG_CC_UNUSED );
xdebug_get_code_coverage ()
xdebug_stop_code_coverage ();
// {{{ public function setName($name)
* Sets the name of a TestCase.
// {{{ protected function createResult()
* Creates a default TestResult object.
* @return PHPUnit2_Framework_TestResult
// {{{ protected function setUp()
* Sets up the fixture, for example, open a network connection.
* This method is called before a test is executed.
protected function setUp() {}
// {{{ protected function tearDown()
* Tears down the fixture, for example, close a network connection.
* This method is called after a test is executed.
* vim600: et sw=2 ts=2 fdm=marker
Documentation generated on Mon, 11 Mar 2019 14:19:19 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|