Приглашаем посетить
Чулков (chulkov.lit-info.ru)

Section 15-6.  PHPUnit2_Framework_TestResult

Previous
Table of Contents
Next

15-6. PHPUnit2_Framework_TestResult

While you are running all these tests, you need somewhere to store the results: how many tests ran, which failed, and how long they took. PHPUnit2_Framework_TestResult collects results. A single PHPUnit2_Framework_TestResult is passed around the whole tree of tests; when a test runs or fails, the fact is noted in the PHPUnit2_Framework_TestResult. At the end of the run, PHPUnit2_Framework_TestResult contains a summary of all the tests.

This example shows the PHPUnit test suite running:

	php AllTests.php 
	PHPUnit 2.3.0 by Sebastian Bergmann.

	.........................................
	.........................................
	.......

	Time: 4.642600

	OK (89 tests)

PHPUnit2_Framework_TestResult is also a subject that can be observed by other objects wanting to report test progress. For example, a graphical test runner might observe the PHPUnit2_Framework_TestResult and update a progress bar every time a test starts.

Table 13 summarizes the external protocols of PHPUnit2_ Framework_TestResult.

Table 13. TestResult external protocols

Method

Description

void addError(PHPUnit2_Framework_Test $test, Exception $e)

Records that running $test caused $e to be thrown unexpectedly.

void addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e)

Records that running $test caused $e to be thrown unexpectedly.

PHPUnit2_Framework_TestFailure[] errors( )

Returns the errors recorded.

PHPUnit2_Framework_TestFailure[] failures( )

Returns the failures recorded.

PHPUnit2_Framework_TestFailure[] notImplemented( )

Returns the incomplete test cases recorded.

int errorCount( )

Returns the number of errors.

int failureCount( )

Returns the number of failures.

int notImplementedCount( )

Returns the number of incomplete test cases.

int runCount( )

Returns the total number of test cases run.

Boolean wasSuccessful( )

Returns whether or not all tests ran successfully.

Boolean allCompletlyImplemented( )

Returns whether or not all tests were completely implemented.

void collectCodeCoverageInformation (Boolean $flag)

Enables or disables the collection of code-coverage information.

Array getCodeCoverageInformation( )

Returns the code-coverage information collected.


If you want to register as an observer of a PHPUnit2_ Framework_TestResult, you need to implement PHPUnit2_ Framework_TestListener. To register, call addListener( ), as shown in Table 14.

Table 14. TestResult and TestListener

Method

Description

void addListener(PHPUnit2_Framework_TestListener $listener)

Registers $listener to receive updates as results are recorded in the test result.

void removeListener(PHPUnit2_Framework_TestListener $listener)

Unregisters $listener from receiving updates.


Table 15 shows the methods that test listeners implement; also see Example 26.

Table 15. TestListener callbacks

Method

Meaning

void addError(PHPUnit2_Framework_Test $test, Exception $e)

$test has thrown $e.

void addFailure(PHPUnit2_ Framework_Test $test, PHPUnit2_Framework_ AssertionFailedError $e)

$test has failed an assertion, throwing a kind of PHPUnit2_Framework_ AssertionFailedError.

void addIncompleteTest(PHPUnit2_ Framework_Test $test, Exception $e)

$test is an incomplete test.

void startTestSuite(PHPUnit2_ Framework_TestSuite $suite)

$suite is about to be run.

void endTestSuite(PHPUnit2_ Framework_TestSuite $suite)

$suite has finished running.

void startTest(PHPUnit2_ Framework_Test $test)

$test is about to be run.

void endTest(PHPUnit2_ Framework_Test $test)

$test has finished running.



Previous
Table of Contents
Next