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

Class: PHPUnit2_Framework_TestCase

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

Methods


Child classes:

PHPUnit2_Framework_Warning
PHPUnit2_Extensions_PerformanceTestCase
A TestCase that expects a TestCase to be executed meeting a given time limit.
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::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::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 reference the same object.
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 reference 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 79]
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 107]

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_PerformanceTestCase::__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 142]

integer countTestCases( )

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

[ Top ]

createResult   [line 292]

PHPUnit2_Framework_TestResult createResult( )

Creates a default TestResult object.
  • Access: protected

[ Top ]

getCodeCoverageInformation   [line 155]

array getCodeCoverageInformation( )

Returns the Code Coverage information provided by Xdebug.
  • Access: public

[ Top ]

getName   [line 168]

string getName( )

Gets the name of a TestCase.
  • Access: public

[ Top ]

run   [line 183]

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

void runBare( )

Runs the bare test sequence.
  • Access: public

[ Top ]

runTest   [line 237]

void runTest( )

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

Overridden in child classes as:

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

[ Top ]

setName   [line 279]

void setName( string $name)

Sets the name of a TestCase.
  • Access: public

Parameters:

string   $name   — 

[ Top ]

setUp   [line 305]

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

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

string toString( )

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

[ Top ]


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