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

Class: PHPUnit_TestCase

Source Location: /PHPUnit-1.2.2/PHPUnit/TestCase.php

Class Overview

PHPUnit_Assert
   |
   --PHPUnit_TestCase

A TestCase defines the fixture to run multiple tests.


Author(s):

Copyright:

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

Methods


Inherited Variables

Inherited Methods

Class: PHPUnit_Assert

PHPUnit_Assert::assertContains()
Asserts that a haystack contains a needle.
PHPUnit_Assert::assertEquals()
Asserts that two variables are equal.
PHPUnit_Assert::assertFalse()
Asserts that a condition is false.
PHPUnit_Assert::assertNotContains()
Asserts that a haystack does not contain a needle.
PHPUnit_Assert::assertNotNull()
Asserts that a variable is not NULL.
PHPUnit_Assert::assertNotRegExp()
Asserts that a string does not match a given regular expression.
PHPUnit_Assert::assertNotSame()
Asserts that two variables do not reference the same object.
PHPUnit_Assert::assertNull()
Asserts that a variable is NULL.
PHPUnit_Assert::assertRegExp()
Asserts that a string matches a given regular expression.
PHPUnit_Assert::assertSame()
Asserts that two variables reference the same object.
PHPUnit_Assert::assertTrue()
Asserts that a condition is true.
PHPUnit_Assert::assertType()
Asserts that a variable is of a given type.
PHPUnit_Assert::fail()
Fails a test with the given message.
PHPUnit_Assert::setLooselyTyped()

Class Details

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

To define a TestCase

1) Implement a subclass of PHPUnit_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.  class MathTest extends PHPUnit_TestCase {
  3.      var $fValue1;
  4.      var $fValue2;
  5.  
  6.      function MathTest($name{
  7.          $this->PHPUnit_TestCase($name);
  8.      }
  9.  
  10.      function setUp({
  11.          $this->fValue1 = 2;
  12.          $this->fValue2 = 3;
  13.      }
  14.  }
  15.  ?>

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.  function testPass({
  3.      $this->assertTrue($this->fValue1 + $this->fValue2 == 5);
  4.  }
  5.  ?>



[ Top ]


Method Detail

PHPUnit_TestCase (Constructor)   [line 101]

PHPUnit_TestCase PHPUnit_TestCase( [string $name = FALSE])

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

Parameters:

string   $name   — 

[ Top ]

countTestCases   [line 113]

integer countTestCases( )

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

[ Top ]

createResult   [line 193]

object &createResult( )

Creates a default TestResult object.
  • Access: protected

[ Top ]

fail   [line 203]

void fail( [string $message = ''])

Fails a test with the given message.
  • Access: protected

Overrides PHPUnit_Assert::fail() (Fails a test with the given message.)

Parameters:

string   $message   — 

[ Top ]

getName   [line 123]

string getName( )

Gets the name of a TestCase.
  • Access: public

[ Top ]

pass   [line 213]

void pass( )

Passes a test.
  • Access: protected

[ Top ]

run   [line 134]

object run( object &$result)

Runs the test case and collects the results in a given TestResult object.
  • Access: public

Parameters:

object   &$result   — 

[ Top ]

runBare   [line 146]

void runBare( )

Runs the bare test sequence.
  • Access: public

[ Top ]

runTest   [line 158]

void runTest( )

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

[ Top ]

setName   [line 173]

void setName( string $name)

Sets the name of a TestCase.
  • Access: public

Parameters:

string   $name   — 

[ Top ]

setUp   [line 226]

void setUp( )

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

This method is called before a test is executed.

  • Abstract:
  • Access: protected

[ Top ]

tearDown   [line 235]

void tearDown( )

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

This method is called after a test is executed.

  • Abstract:
  • Access: protected

[ Top ]

toString   [line 183]

string toString( )

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

[ Top ]


Documentation generated on Thu, 10 Dec 2015 05:37:22 +0000 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.