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

Class: PHPUnit2_Framework_TestCase

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

Class Overview

PHPUnit2_Framework_Assert
   |
   --PHPUnit2_Framework_TestCase

A TestCase defines the fixture to run multiple tests.


Author(s):

Copyright:

  • Copyright &copy; 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de>

Methods


Child classes:

PHPUnit2_Framework_Warning
PHPUnit2_Extensions_ExceptionTestCase
A TestCase that expects an Exception of class fExpected 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::assertEquals()
Asserts that two variables are equal.
PHPUnit2_Framework_Assert::assertFalse()
Asserts that a condition is false.
PHPUnit2_Framework_Assert::assertNotNull()
Asserts that an object isn't null.
PHPUnit2_Framework_Assert::assertNotSame()
Asserts that two objects refer not to the same object.
PHPUnit2_Framework_Assert::assertNull()
Asserts that an object is null.
PHPUnit2_Framework_Assert::assertRegExp()
Asserts that a string matches a given regular expression.
PHPUnit2_Framework_Assert::assertSame()
Asserts that two objects refer to the same object.
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 78]
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 98]

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()
PHPUnit2_Extensions_ExceptionTestCase::__construct()

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

Parameters:

string   $name   — 

[ Top ]

countTestCases   [line 133]

integer countTestCases( )

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

[ Top ]

createResult   [line 252]

PHPUnit2_Framework_TestResult createResult( )

Creates a default TestResult object.
  • Access: protected

[ Top ]

getName   [line 146]

string getName( )

Gets the name of a TestCase.
  • Access: public

[ Top ]

run   [line 161]

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

Parameters:

PHPUnit2_Framework_TestResult   $result   — 

[ Top ]

runBare   [line 186]

void runBare( )

Runs the bare test sequence.
  • Access: public

[ Top ]

runTest   [line 215]

void runTest( )

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

Overridden in child classes as:

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

[ Top ]

setName   [line 239]

void setName( string $name)

Sets the name of a TestCase.
  • Access: public

Parameters:

string   $name   — 

[ Top ]

setUp   [line 265]

void setUp( )

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

This method is called before a test is executed.

  • Access: protected

[ Top ]

tearDown   [line 276]

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 113]

string toString( )

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

[ Top ]


Documentation generated on Mon, 11 Mar 2019 13:55:58 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.