PHPUnit2
[ class tree: PHPUnit2 ] [ index: PHPUnit2 ] [ all elements ]

Class: PHPUnit2_Framework_TestCase

Source Location: /PHPUnit2-2.3.6/Framework/TestCase.php

Class Overview

PHPUnit2_Framework_Assert
   |
   --PHPUnit2_Framework_TestCase

A TestCase defines the fixture to run multiple tests.


Author(s):

Version:

  • Release: @package_version@

Copyright:

  • 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>

Methods


Child classes:

Inherited Variables

Inherited Methods

Class: PHPUnit2_Framework_Assert

PHPUnit2_Framework_Assert::assertContains()
Asserts that a haystack contains a needle.
PHPUnit2_Framework_Assert::assertEquals()
Asserts that two variables are equal.
PHPUnit2_Framework_Assert::assertFalse()
Asserts that a condition is false.
PHPUnit2_Framework_Assert::assertNotContains()
Asserts that a haystack does not contain a needle.
PHPUnit2_Framework_Assert::assertNotEquals()
Asserts that two variables are not equal.
PHPUnit2_Framework_Assert::assertNotNull()
Asserts that a variable is not NULL.
PHPUnit2_Framework_Assert::assertNotRegExp()
Asserts that a string does not match a given regular expression.
PHPUnit2_Framework_Assert::assertNotSame()
Asserts that two variables do not have the same type and value.
PHPUnit2_Framework_Assert::assertNotType()
Asserts that a variable is not of a given type.
PHPUnit2_Framework_Assert::assertNull()
Asserts that a variable is NULL.
PHPUnit2_Framework_Assert::assertRegExp()
Asserts that a string matches a given regular expression.
PHPUnit2_Framework_Assert::assertSame()
Asserts that two variables have the same type and value.
PHPUnit2_Framework_Assert::assertTrue()
Asserts that a condition is true.
PHPUnit2_Framework_Assert::assertType()
Asserts that a variable is of a given type.
PHPUnit2_Framework_Assert::fail()
Fails a test with the given message.
PHPUnit2_Framework_Assert::format()
PHPUnit2_Framework_Assert::setLooselyTyped()
PHPUnit2_Framework_Assert::__construct()
Protect constructor since it is a static only class.

Class Details

[line 111]
A TestCase defines the fixture to run multiple tests.

To define a TestCase

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 among test runs.

Here is an example:


1 <?php
2 require_once 'PHPUnit2/Framework/TestCase.php';
3
4 class MathTest extends PHPUnit2_Framework_TestCase {
5 public $value1;
6 public $value2;
7
8 public function __construct($name) {
9 parent::__construct($name);
10 }
11
12 public function setUp() {
13 $this->value1 = 2;
14 $this->value2 = 3;
15 }
16 }
17 ?>

For each test implement a method which interacts with the fixture. Verify the expected results with assertions specified by calling assert with a boolean.


1 <?php
2 public function testPass() {
3 $this->assertTrue($this->value1 + $this->value2 == 5);
4 }
5 ?>



[ Top ]


Method Detail

countTestCases   [line 155]

integer countTestCases( )

Counts the number of test cases executed by run(TestResult result).
  • Access: public

[ Top ]

createResult   [line 262]

PHPUnit2_Framework_TestResult createResult( )

Creates a default TestResult object.
  • Access: protected

[ Top ]

getName   [line 165]

string getName( )

Gets the name of a TestCase.
  • Access: public

[ Top ]

run   [line 178]

PHPUnit2_Framework_TestResult run( [PHPUnit2_Framework_TestResult $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.

  • Access: public
  • Throws: Exception

Parameters:

PHPUnit2_Framework_TestResult   $result     

[ Top ]

runBare   [line 200]

void runBare( )

Runs the bare test sequence.
  • Access: public

[ Top ]

runTest   [line 227]


setName   [line 252]

void setName( string $name)

Sets the name of a TestCase.
  • Access: public

Parameters:

string   $name     

[ Top ]

setUp   [line 272]

void setUp( )

Sets up the fixture, for example, open a network connection.

This method is called before a test is executed.

  • Access: protected

Overridden in child classes as:

BankAccountTest::setUp()
Sets up the test fixture.
MoneyTest::setUp()
Framework_SuiteTest::setUp()
Framework_TestListenerTest::setUp()
Util_TestDox_NamePrettifierTest::setUp()
SetupFailure::setUp()
TornDown4::setUp()

[ Top ]

tearDown   [line 281]

void tearDown( )

Tears down the fixture, for example, close a network connection.

This method is called after a test is executed.

  • Access: protected

Overridden in child classes as:

TearDownFailure::tearDown()
TornDown2::tearDown()
TornDown3::tearDown()
TornDown5::tearDown()

[ Top ]

toString   [line 138]

string toString( )

Returns a string representation of the test case.
  • Access: public

[ Top ]

__construct   [line 126]

void __construct( [string $name = NULL])

Constructs a test case with the given name.
  • Access: public

Overridden in child classes as:

PHPUnit2_Framework_Warning::__construct()

Overrides PHPUnit2_Framework_Assert::__construct() (Protect constructor since it is a static only class.)

Parameters:

string   $name     

[ Top ]


Documentation generated on Tue, 12 Sep 2006 09:35:28 -0400 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.