Summary: I am on Ubuntu 11.10 and have the necessity to install PHPUnit. From my past experience, I know that installing via repository installs old version + fails to run. So I decided to install it via PEAR. Here’s a walk through!
Upgrade PEAR
Damn! The shipped version of pear via the “php-pear” package is outdated. The first thing we need to do is upgrade our PEAR setup. We have to ask pear to upgrade itself!
1 |
sudo pear upgrade PEAR |
That should upgrade our pear to the latest version available!
Setup PHPUnit
To install PHPUnit, we have to set auto discovery turned on and discover the PHPUnit PEAR channel. Then we force install PHPUnit with all dependencies. That’s simple!
1 2 |
sudo pear config-set auto_discover 1 sudo pear install --force --alldeps pear.phpunit.de/PHPUnit |
If everything goes okay, we have a working setup of PHPUnit by now! Type “phpunit –version” on console and check out the output! Ooops! It didn’t work! We’re getting an error message regarding “require_once()”. The issue is obvious, the PEAR directory which contains all PEAR packages haven’t been added to the php include_path.
Fix it this way:
1 |
sudo vim /etc/php5/conf.d/phpunit.ini |
Vim editor window will open with the empty buffer. If you’re not comfortable with vim, just use another text editor. Type in the following directives:
1 2 3 |
;include path to phpunit [PEAR] include_path=${include_path} ":/usr/share/php/" |
Save and quit. We had to do this manually because pear doesn’t automatically set the include_path to the pear location (which is “/usr/share/php/”).
Now try on terminal:
1 |
phpunit --version |
The output should look like:
1 2 |
masnun@ubuntu:~$ phpunit --version PHPUnit 3.6.10 by Sebastian Bergmann. |
Happy Unit testing!
One reply on “Installing PHPUnit on Ubuntu”
Really helpful post – thanks for sharing.