Categories
Linux PHP

Installing PHPUnit on Ubuntu

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!

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!

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:

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:

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:

The output should look like:

Happy Unit testing!

One reply on “Installing PHPUnit on Ubuntu”

Comments are closed.