Installing PHPUnit on Ubuntu with Composer
I foolishly installed PHPUnit on Ubuntu 12.04 using PEAR.
sudo apt-get install php-pear
sudo pear channel-discover pear.phpunit.de
sudo pear install --alldeps phpunit/PHPUnit
When I went to run it I recieved this message:
You have installed PHPUnit via PEAR. This installation method is no longer
supported and http://pear.phpunit.de/ will be shut down no later than
December, 31 2014.
Please read http://phpunit.de/manual/current/en/installation.html and
learn how to use PHPUnit from a PHAR or install it via Composer.
So first let's remove phpunit and send PEAR away for good
$ sudo apt-get remove phpunit
$ sudo apt-get remove php-pear
Then, assuming Composer is already installed
<br />
$ curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin<br />
$ ln -s /usr/local/bin/composer.phar /usr/local/bin/composer<br />
$ composer global require "phpunit/phpunit=4.1.*"
$ composer global require "phpunit/php-invoker=~1.1."
next, find the ".composer" directory, mine was in my home directory, and create a symbolic link so we can call it from the command line like so: $phpunit
$ sudo ln -s ~/.composer/vendor/phpunit/phpunit/phpunit /usr/bin/
Voila!
Unit test your app and say goodbye to PEAR forever (lol).
$ phpunit -c app/
Written by Jeremy Olson
Related protips
4 Responses
This was very helpful. I was unable to get some of the linking to resolve correctly, but the overall strategy was perfect. Thanks a lot!
It's my first time installing PHPUnit (and through the docs). It was weird that they never mentioned anything about the message. Stumbling upon this tip saved me a lot of time.
Thanks!
This was really very helpful. Finally i am able to install phpunit
this installation is no longer working for me in 2016;
but what did work for me was
$ curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer</code>