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:

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_OutputTestCase
A TestCase that expects a specified output.
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::anything()
PHPUnit2_Framework_Assert::arrayContains()
PHPUnit2_Framework_Assert::arrayHasKey()
PHPUnit2_Framework_Assert::assertArrayHasKey()
Asserts that an array has a specified key.
PHPUnit2_Framework_Assert::assertArrayNotHasKey()
Asserts that an array does not have a specified key.
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::assertFileExists()
Asserts that a file exists.
PHPUnit2_Framework_Assert::assertFileNotExists()
Asserts that a file does not exist.
PHPUnit2_Framework_Assert::assertHasProperty()
Asserts that an object has a specified property.
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::assertNotHasProperty()
Asserts that an object does not have a specified property.
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::assertThat()
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::equalTo()
PHPUnit2_Framework_Assert::fail()
Fails a test with the given message.
PHPUnit2_Framework_Assert::failConstraint()
Fails a test based on a failed constraint.
PHPUnit2_Framework_Assert::fileExists()
PHPUnit2_Framework_Assert::getNonPublicProperty()
Returns the value of an object's property that is declared protected or private.
PHPUnit2_Framework_Assert::greaterThan()
PHPUnit2_Framework_Assert::hasProperty()
PHPUnit2_Framework_Assert::identicalTo()
PHPUnit2_Framework_Assert::isInstanceOf()
PHPUnit2_Framework_Assert::isType()
PHPUnit2_Framework_Assert::lessThan()
PHPUnit2_Framework_Assert::logicalAnd()
Logical AND.
PHPUnit2_Framework_Assert::logicalNot()
Logical NOT.
PHPUnit2_Framework_Assert::logicalOr()
Logical OR.
PHPUnit2_Framework_Assert::markTestIncomplete()
Mark the test as incomplete.
PHPUnit2_Framework_Assert::markTestSkipped()
Mark the test as skipped.
PHPUnit2_Framework_Assert::matchesRegularExpression()
PHPUnit2_Framework_Assert::stringContains()

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

__construct (Constructor)   [line 140]

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 ]

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, [Array $methods = array()], [Array $arguments = array()], [string $mockClassName = ''])

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
  • Throws: InvalidArgumentException
  • Throws: RuntimeException
  • Access: protected

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( [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: InvalidArgumentException
  • Access: public

Parameters:

PHPUnit2_Framework_TestResult   $result   — 

[ Top ]

runBare   [line 212]

void runBare( )

Runs the bare test sequence.
  • Access: public

[ Top ]

runTest   [line 258]

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

[ Top ]

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

[ 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

[ Top ]

toString   [line 153]

string toString( )

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

[ Top ]


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