Chapter 1. Installing PHPUnit

Note

PHPUnit 3.9 requires PHP 5.3.3; using the latest version of PHP is highly recommended.

For code coverage support, Xdebug 2.1.3 is required; using the latest version of Xdebug is highly recommended.

PHP Archive (PHAR)

The easiest way to obtain PHPUnit is to download a PHP Archive (PHAR) that has all required (as well as some optional) dependencies of PHPUnit bundled in a single file:

wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
mv phpunit.phar /usr/local/bin/phpunit

You can also immediately use the PHAR after you have downloaded it, of course:

wget https://phar.phpunit.de/phpunit.phar
php phpunit.phar

Composer

Simply add a dependency on phpunit/phpunit to your project's composer.json file if you use Composer to manage the dependencies of your project. Here is a minimal example of a composer.json file that just defines a development-time dependency on PHPUnit 3.9:

{
    "require-dev": {
        "phpunit/phpunit": "3.9.*"
    }
}

For a system-wide installation via Composer, you can run:

composer global require 'phpunit/phpunit=3.9.*'

Make sure you have ~/.composer/vendor/bin/ in your path.

PEAR

The following two commands (which you may have to run as root) are all that is required to install PHPUnit using the PEAR Installer:

pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit

Caution

Depending on your OS distribution and/or your PHP environment, you may need to install PEAR or update your existing PEAR installation before you can proceed with the instructions in this section.

sudo pear upgrade PEAR usually suffices to upgrade an existing PEAR installation. The PEAR Manual explains how to perform a fresh installation of PEAR.

Optional packages

The following optional packages are available:

DbUnit

DbUnit port for PHP/PHPUnit to support database interaction testing.

This package can be installed via PEAR using the following command:

pear install phpunit/DbUnit

This package can be installed via Composer by adding the following "require-dev" dependency:

"phpunit/dbunit": ">=1.2"
PHP_Invoker

A utility class for invoking callables with a timeout. This package is required to enforce test timeouts in strict mode.

This package can be installed using the following command:

pear install phpunit/PHP_Invoker

This package can be installed via Composer by adding the following "require-dev" dependency:

"phpunit/php-invoker": "*"
PHPUnit_Selenium

Selenium RC integration for PHPUnit.

This package can be installed via PEAR using the following command:

pear install phpunit/PHPUnit_Selenium

This package can be installed via Composer by adding the following "require-dev" dependency:

"phpunit/phpunit-selenium": ">=1.2"
PHPUnit_Story

Story-based test runner for Behavior-Driven Development with PHPUnit.

This package can be installed via PEAR using the following command:

pear install phpunit/PHPUnit_Story

This package can be installed via Composer by adding the following "require-dev" dependency:

"phpunit/phpunit-story": "*"
PHPUnit_SkeletonGenerator

Tool that can generate skeleton test classes from production code classes and vice versa.

This package can be installed using the following command:

pear install phpunit/PHPUnit_SkeletonGenerator
PHPUnit_TestListener_DBUS

A TestListener that sends events to DBUS.

This package can be installed using the following command:

pear install phpunit/PHPUnit_TestListener_DBUS
PHPUnit_TestListener_XHProf

A TestListener that uses XHProf for automated profiling of the tested code.

This package can be installed using the following command:

pear install phpunit/PHPUnit_TestListener_XHProf
PHPUnit_TicketListener_Fogbugz

A ticket listener that interacts with the Fogbugz issue API.

This package can be installed using the following command:

pear install phpunit/PHPUnit_TicketListener_Fogbugz
PHPUnit_TicketListener_GitHub

A ticket listener that interacts with the GitHub issue API.

This package can be installed using the following command:

pear install phpunit/PHPUnit_TicketListener_GitHub
PHPUnit_TicketListener_GoogleCode

A ticket listener that interacts with the Google Code issue API.

This package can be installed using the following command:

pear install phpunit/PHPUnit_TicketListener_GoogleCode
PHPUnit_TicketListener_Trac

A ticket listener that interacts with the Trac issue API.

This package can be installed using the following command:

pear install phpunit/PHPUnit_TicketListener_Trac

Upgrading

This section serves as a collection of minor BC issues that one might run into when upgrading from PHPUnit 3.7 to PHPUnit 3.9.

The upgrade should be rather easy and work without any issues as it was tested against all major Open Source frameworks and there was not a single problem for them. Still every project is different and if you did not get around to trying one of the release candidates and have ran into an issue this document might provide some help.

Please open a ticket on GitHub to suggest improvements to this page. Thanks!