PHPUnit: Migration from PEAR to PHAR

Sebastian Bergmann |

In April 2014 I announced that I would shut down on December 31, 2014. The motivation behind this move was to simplify the release process of PHPUnit by getting rid of an outdated distribution channel.

I was afraid that I would leave users of my software behind by this move: users that cannot or do not want to use a distribution of PHPUnit other than the traditional PEAR package. I am relieved that the shutdown of went as smooth as it did: in the two weeks since the shutdown I have not seen a single complaint on the mailinglist, on the issue tracker, or on Twitter.

In this article I show you how to make the transition from using PHPUnit from a PEAR package to using PHPUnit from a PHP Archive or using Composer as easy and convenient as possible.

Uninstalling PEAR Packages

If you have installed PHPUnit 3.7 using the PEAR Installer then you need to uninstall at least the PHPUnit, PHPUnit_MockObject, and PHP_CodeCoverage PEAR packages:

$ pear uninstall phpunit/PHPUnit \
                 phpunit/PHPUnit_MockObject \

If you have installed PHPUnit 4.0 using the PEAR Installer then you only need to uninstall the PHPUnit PEAR package:

$ pear uninstall phpunit/PHPUnit

You may have other packages from the channel installed, for instance as dependencies for other tools that you may have installed. If

$ pear list -c phpunit

shows that you still have packages from the channel installed then you should uninstall those packages, too. Please make sure, though, that these packages are not required by other tools that you may have installed.

Using PHPUnit from a PHP Archive (PHAR)

The PHP Archive (PHAR) of PHPUnit contains everything you need in order to use PHPUnit. Simply download it from, make it executable, and put it into your $PATH, for instance:

$ wget
chmod +x phpunit.phar
sudo mv phpunit.phar /usr/local/bin/phpunit

Instead of installing the phpunit.phar globally as shown above, you can also put the PHAR into your project's repository. This allows for different PHPUnit versions per project, for instance.

Installing PHPUnit with Composer

If you use Composer to manage the dependencies of your project you may also want to use it to manage the version of PHPUnit used to run the project's test suite. Here is a minimal example of a composer.json file that just defines a development-time dependency on PHPUnit 4.4:

    "require-dev": {
        "phpunit/phpunit": "4.4.*"

Old Versions

On and on Packagist you can find all releases of PHPUnit since version 3.7.3 as a PHP Archive (PHAR) or as a Composer-installable package, respectively.

Versions of PHPUnit that were released before September 2012 are no longer offered for direct download or installation. The tags in PHPUnit's Git repository on GitHub still exist, of course, but you are on your own to install these unsupported versions.

About the author

Sebastian Bergmann

Sebastian Bergmann is the author of PHPUnit and sets the industry standard of quality assurance.