There is a release series of PHPUnit that works with PHP 4 and does not require PHP 5. Due to PHP 4's limited object model, PHPUnit for PHP 4 is not a complete port of JUnit as PHPUnit for PHP 5 is. It also lacks certain features of PHPUnit for PHP 5, such as code-coverage analysis.
The following command line shows how to install PHPUnit for PHP 4 using the PEAR Installer:
pear install -f http://pear.phpunit.de/get/PHPUnit-1.3.3.tgz
A test-case class that is used with PHPUnit for PHP 4 is similar
to one that is used with PHPUnit for PHP 5. The essential difference is
that such a class extends
(which itself extends
PHPUnit_Assert, the class that
provides the assertion methods).
shows a version of the
ArrayTest test case that can
be used with PHPUnit for PHP 4.
Example A.1: Writing a test case for PHPUnit 1.x
class ArrayTest extends PHPUnit_TestCase
$this->_fixture = array();
$this->_fixture = 'Element';
PHPUnit for PHP 4 does not provide a TextUI test runner. The most commonly used way to run tests with PHPUnit for PHP 4 is to write a test suite and run it manually, as shown in Example A.2.
Example A.2: Running a test case with PHPUnit 1.x
$suite = new PHPUnit_TestSuite('ArrayTest');
$result = PHPUnit::run($suite);
TestCase arraytest->testnewarrayisempty() passed TestCase arraytest->testarraycontainsanelement() passed
Figure A.1 shows the one feature that PHPUnit for PHP 4 has that PHPUnit for PHP 5 does not yet have: a test runner with a graphical user interface based on PHP-GTK.