Wednesday, February 16, 2011

Install PHPunit and upgrading PEAR.

PhpUnit manual has all information about to install phpunit on your server.

http://www.phpunit.de/manual/3.5/en/phpunit-book.html#installation

PHPUnit 3.5 requires PHP 5.2.7 (or later) but PHP 5.3.3 (or later) is highly recommended.

sudo pear channel-discover pear.phpunit.de
sudo pear channel-discover components.ez.no
sudo pear channel-discover pear.symfony-project.com

This has to be done only once. Now the PEAR Installer can be used to install packages from the PHPUnit channel:

sudo pear install phpunit/PHPUnit

After the installation you can find the PHPUnit source files inside your local PEAR directory; the path is usually /usr/lib/php/PHPUnit.
After installation, if you don't find phpunit utility, the please check your pear installation version.
Phpunit installation requires PEAR version >= 1.9.1
You can update PEAR version by using command,

sudo pear upgrade pear

This will upgrade pear and then if you run 'pear install phpunit/PHPUnit' this will install phpunit correctly.

If you see following error,

Failed to download pear/HTTP_Request2 within preferred state "stable", latest release is version 2.0.0RC1, stability "beta", use "channel://pear.php.net/HTTP_Request2-2.0.0RC1" to install
phpunit/PHPUnit can optionally use PHP extension "dbus"
pear/XML_RPC2 requires package "pear/HTTP_Request2" (version >= 0.6.0)
phpunit/PHPUnit requires package "pear/XML_RPC2"
No valid packages found
install failed

To install this missing HTTP_Request2 package, run following command,

sudo pear install HTTP_Request2-2.0.0RC1

If you see following error while executing above command,

Failed to download pear/Net_URL2 within preferred state "stable", latest release is version 0.3.1, stability "beta", use "channel://pear.php.net/Net_URL2-0.3.1" to install
pear/HTTP_Request2 requires package "pear/Net_URL2" (version >= 0.3.0)
pear/HTTP_Request2 can optionally use PHP extension "fileinfo"
No valid packages found
install failed

Then in that case you will need to install Net_URL2 package first, for doing so use following command,

sudo pear install NET_URL2-0.3.1

now install HTTP_Request2 and then PHPUnit.