O'Reilly logo

PHPUnit Pocket Guide by Sebastian Bergmann

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required