Skip to Main Content
PHPUnit Pocket Guide
book

PHPUnit Pocket Guide

by Sebastian Bergmann
September 2005
Intermediate to advanced content levelIntermediate to advanced
90 pages
1h 53m
English
O'Reilly Media, Inc.
Content preview from PHPUnit Pocket Guide

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Mastering PHP 7

Mastering PHP 7

Branko Ajzele

Publisher Resources

ISBN: 0596101031Errata Page