PHPUnit2_Framework_TestCase

Your test-case classes will inherit from PHPUnit2_Framework_ TestCase. Most of the time, you will run tests from automatically created test suites. In this case, each of your tests should be represented by a method named test* (by convention).

PHPUnit2_Framework_TestCase implements PHPUnit2_Framework_ Test::countTestCases( ) so that it always returns 1. The implementation of PHPUnit2_Framework_Test::run(PHPUnit2_ Framework_TestResult $result) in this class runs setUp( ), runs the test method, and then runs tearDown( ), reporting any exceptions to the PHPUnit2_Framework_TestResult.

Table 9 shows the external protocols implemented by PHPUnit2_Framework_TestCase.

Table 9. TestCase external protocols

Method

Description

__construct( )

Creates a test case.

__construct(String $name)

Creates a named test case. Names are used to print the test case and often as the name of the test method to be run by reflection.

String getName( )

Returns the name of the test case.

void setName($name( )

Sets the name of the test case.

PHPUnit2_Framework_TestResult run(PHPUnit2_Framework_TestResult $result)

Runs the test case and reports the result in $result.

void runTest( )

Overrides with a testing method if you do not want the testing method to be invoked by reflection.

There are two template methods—setUp( ) and tearDown( )— you can override to create and dispose of the objects against which you are going to test. Table 10 shows these methods.

Table 10. Template ...

Get PHPUnit Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.