Chapter 1. Installing PHPUnit

Note

PHPUnit 4.0 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.

Please read the section called “Upgrading from PHPUnit 3.7 to PHPUnit 4.0” in case you are upgrading from a previous version of PHPUnit.

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 4.0:

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

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

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

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

Optional packages

The following optional packages are available:

PHP_Invoker

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

This package is included in the PHAR distribution of PHPUnit. It can be installed via Composer by adding the following "require-dev" dependency:

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

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

This package is included in the PHAR distribution of PHPUnit. It can be installed via Composer by adding the following "require-dev" dependency:

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

Selenium RC integration for PHPUnit.

This package is included in the PHAR distribution of PHPUnit. It can be installed via Composer by adding the following "require-dev" dependency:

"phpunit/phpunit-selenium": ">=1.2"
Please open a ticket on GitHub to suggest improvements to this page. Thanks!