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

Class: PHPUnit2_Framework_TestCase

Source Location: /PHPUnit2-2.3.0/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-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>

Methods


Child classes:

PHPUnit2_Framework_Warning
A warning.
BankAccountTest
Tests for the BankAccount class.
MoneyTest
Tests for the Money and MoneyBag classes.
PHPUnit2_Extensions_PerformanceTestCase
A TestCase that expects a TestCase to be executed meeting a given time limit.
PHPUnit2_Extensions_ExceptionTestCase
A TestCase that expects a specified Exception to be thrown.

Inherited Variables

Inherited Methods

Class: PHPUnit2_Framework_Assert

PHPUnit2_Framework_Assert::__construct()
Protect constructor since it is a static only class.
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()

Class Details

[line 85]
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

__construct (Constructor)   [line 100]

PHPUnit2_Framework_TestCase __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 ]

countTestCases   [line 129]

integer countTestCases( )

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

[ Top ]

createResult   [line 236]

PHPUnit2_Framework_TestResult createResult( )

Creates a default TestResult object.
  • Access: protected

[ Top ]

getName   [line 139]

string getName( )

Gets the name of a TestCase.
  • Access: public

[ Top ]

run   [line 152]

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.

  • Throws: Exception
  • Access: public

Parameters:

PHPUnit2_Framework_TestResult   $result   — 

[ Top ]

runBare   [line 174]

void runBare( )

Runs the bare test sequence.
  • Access: public

[ Top ]

runTest   [line 201]

void runTest( )

Override to run the test and assert its state.
  • Throws: PHPUnit2_Framework_Error
  • Access: protected

Overridden in child classes as:

PHPUnit2_Framework_Warning::runTest()
PHPUnit2_Extensions_PerformanceTestCase::runTest()
PHPUnit2_Extensions_ExceptionTestCase::runTest()

[ Top ]

setName   [line 226]

void setName( string $name)

Sets the name of a TestCase.
  • Access: public

Parameters:

string   $name   — 

[ Top ]

setUp   [line 246]

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()

[ Top ]

tearDown   [line 255]

void tearDown( )

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

This method is called after a test is executed.

  • Access: protected

[ Top ]

toString   [line 112]

string toString( )

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

[ Top ]


Documentation generated on Mon, 11 Mar 2019 14:12:37 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.