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

Class: PHPUnit2_Framework_TestCase

Source Location: /PHPUnit2-3.0.0alpha11/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::assertArrayHasKey()
Asserts that an array has a specified key.
PHPUnit2_Framework_Assert::__construct()
Protect constructor since it is a static only class.

Class Details

[line 112]
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 {
6 public $value1;
7 public $value2;
8
9 protected function setUp()
10 {
11 $this->value1 = 2;
12 $this->value2 = 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 public function testPass()
3 {
4 $this->assertTrue($this->value1 + $this->value2 == 5);
5 }
6 ?>



[ Top ]


Method Detail

at   [line 399]

PHPUnit2_Extensions_MockObject_Matcher_InvokedAtIndex at( integer $index)

  • Since: Method available since Release 3.0.0
  • Access: protected

Parameters:

integer   $index     

[ Top ]

atLeastOnce   [line 361]

PHPUnit2_Extensions_MockObject_Matcher_InvokedAtLeastOnce atLeastOnce( )

  • Since: Method available since Release 3.0.0
  • Access: protected

[ Top ]

count   [line 171]

integer count( )

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

[ Top ]

createResult   [line 438]

PHPUnit2_Framework_TestResult createResult( )

Creates a default TestResult object.
  • Access: protected

[ Top ]

exactly   [line 386]

PHPUnit2_Extensions_MockObject_Matcher_InvokedCount exactly( integer $count)

  • Since: Method available since Release 3.0.0
  • Access: protected

Parameters:

integer   $count     

[ Top ]

getMock   [line 327]

object getMock( string $className, [string $mockClassName = array $methods = array() $arguments = array()''], array $methods, array $arguments)

Returns a mock object for the specified class.
  • Since: Method available since Release 3.0.0
  • Access: protected

Parameters:

string   $className     
array   $methods     
array   $arguments     
string   $mockClassName     

[ Top ]

getName   [line 182]

string getName( )

Gets the name of a TestCase.
  • Access: public

[ Top ]

iniSet   [line 301]

void iniSet( string $varName, string $newValue)

This method is a wrapper for the ini_set() function that automatically resets the modified php.ini setting to its original value after the test is run.
  • Since: Method available since Release 3.0.0
  • Access: protected
  • Throws: RuntimeException
  • Throws: InvalidArgumentException

Parameters:

string   $varName     
string   $newValue     

[ Top ]

never   [line 349]

PHPUnit2_Extensions_MockObject_Matcher_InvokedCount never( )

  • Since: Method available since Release 3.0.0
  • Access: protected

[ Top ]

once   [line 373]

PHPUnit2_Extensions_MockObject_Matcher_InvokedCount once( )

  • Since: Method available since Release 3.0.0
  • Access: protected

[ Top ]

onConsecutiveCalls   [line 425]

PHPUnit2_Extensions_MockObject_Stub_ConsecutiveCalls onConsecutiveCalls( mixed $value,)

  • Since: Method available since Release 3.0.0
  • Access: protected

Parameters:

mixed   $value,     ...

[ Top ]

returnValue   [line 412]

PHPUnit2_Extensions_MockObject_Stub_Return returnValue( mixed $value)

  • Since: Method available since Release 3.0.0
  • Access: protected

Parameters:

mixed   $value     

[ Top ]

run   [line 196]

PHPUnit2_Framework_TestResult run( [mixed PHPUnit2_Framework_TestResult$result = NULL], PHPUnit2_Framework_TestResult $result)

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: InvalidArgumentException

Parameters:

PHPUnit2_Framework_TestResult   $result     

[ Top ]

runBare   [line 212]

void runBare( )

Runs the bare test sequence.
  • Access: public

[ Top ]

runTest   [line 258]


setName   [line 284]

void setName( string $name)

Sets the name of a TestCase.
  • Access: public

Parameters:

string   $name     

[ Top ]

setUp   [line 449]

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()
SetupFailure::setUp()
TornDown4::setUp()
Framework_SuiteTest::setUp()
Framework_TestListenerTest::setUp()
Util_TestDox_NamePrettifierTest::setUp()

[ Top ]

tearDown   [line 459]

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

string toString( )

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

[ Top ]

__construct   [line 140]

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:37:54 -0400 by phpDocumentor 1.2.3. PEAR Logo Copyright © PHP Group 2004.