Chapter 15. PHPUnit API
For most uses, PHPUnit has a simple API: subclass
PHPUnit2_Framework_TestCase
for your test cases and call assertTrue( )
or assertEquals( )
. However, for those of you who would like to look deeper into PHPUnit, here are all of its published methods and classes.
Overview
Most of the time, you will encounter five classes or interfaces when you are using PHPUnit:
- PHPUnit2_Framework_Assert
A collection of static methods for checking actual values against expected values
- PHPUnit2_Framework_Test
The interface of all objects that act like tests
- PHPUnit2_Framework_TestCase
A single test
- PHPUnit2_Framework_TestSuite
A collection of tests
- PHPUnit2_Framework_TestResult
A summary of the results of running one or more tests
Figure 7 shows the relationship of the five basic classes and interfaces in PHPUnit:
PHPUnit2_Framework_Assert, PHPUnit2_ Framework_Test, PHPUnit2_Framework_TestCase, PHPUnit2_ Framework_TestSuite
, and PHPUnit2_Framework_TestResult
.

PHPUnit2_Framework_Assert
Most test cases written for PHPUnit are derived indirectly from the class PHPUnit2_Framework_Assert
, which contains methods for automatically checking values and reporting discrepancies. The methods are declared static, so you can write design-by-contract style assertions in your methods and have them reported through PHPUnit (Example 19).
Get PHPUnit Pocket Guide now with the O’Reilly learning platform.
O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.