Installing PHPUnit

PHPUnit is a powerful unit testing framework written in and for PHP. Rather than testing everything as a whole the idea behind PHPUnit is to test that everything works as it is expected to work before it is integrated into the rest of the program. In this way problems are found earlier rather than later and this makes fixing them a lot easier. With tests written for every small component of the program it is then possible to test the whole thing by running all of the tests at once. It is also possible to automate PHPUnit so that everything about a program is tested before it is built. If any tests fail then the build is stopped.

The best way to install PHPUnit is to use the PEAR installer. To install PHPUnit you first need to add the correct channel so that PEAR can find PHPUnit easily. You do this by typing the following into the command line.

pear channel-discover pear.phpunit.de

You can now install PHPUnit by using the following command.

pear install phpunit/PHPUnit

You can now test your install by trying to run PHPUni through the command line.

phpunit

If properly installed this command will print out usage and parameter information for PHPUnit.

You can see which version of PHPUnit is installed by using the --version parameter.

phpunit --version

For more information about PHPUnit take a look at the PHPUnit website.

Comments

Just a note that if you have having trouble installing PHPUnit you might find the following error:
phpunit/PHPUnit requires PEAR Installer (version >= 1.8.1), installed version is
 1.7.2
You will therefore need to upgrade your copy of PEAR. To do this just type:
pear upgrade-all
Into the command line and PEAR will update itself. You can now proceed with installing PHPUnit!
Name
Philip Norton
Permalink

Add new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
13 + 1 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.