Please read the section called “Upgrading from PHPUnit 4.1 to PHPUnit 4.2” in case you are upgrading from a previous version of PHPUnit.
PHPUnit 4.2 requires PHP 5.3.3; using the latest version of PHP is highly recommended.
PHPUnit requires the dom, json, pcre, reflection, and spl extensions. These extensions are usually compiled and enabled by default. Some of them cannot even be disabled and are therefore always available.
For code coverage support, Xdebug 2.1.3 is required; using the latest version of Xdebug is highly recommended. The tokenizer extension is also required for the code coverage functionality to work. The xmlwriter extension is required to log code coverage information as XML.
The phar
extension is required for using PHPUnit from a PHP Archive (PHAR). The
openssl
extension is required for the --self-update
functionality of PHPUnit's PHAR to work. You need to configure
suhosin.executor.include.whitelist = phar
if you are
using the Suhosin extension and
would like to use PHPUnit from a 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
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.2:
{ "require-dev": { "phpunit/phpunit": "4.2.*" } }
For a system-wide installation via Composer, you can run:
composer global require "phpunit/phpunit=4.2.*"
Make sure you have ~/.composer/vendor/bin/
in your
path.
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"