Installing PHPUnit in XAMPP

I’ve recently begun working on a PHP-based project and wanted to introduce unit testing into the mix to cover some of the core code.

On my local development environment, I’m running an WAMP stack (specifically with XAMPP) and was looking for a solid unit test framework for PHP.

PHPUnit is solid has is apparently emerging as the standard framework. It’s easy to set it up in an environment powered by XAMPP, too.

If you’ve got the path to PEAR specified in your environmental variables, then you should be able to run this in any directory; otherwise, launch a command line in the XAMPP PHP directory.

Before installing PHPUnit, you may need to upgrade your existing PEAR installation:

pear upgrade-all

Next issue the following commands:

pear channel-discover pear.phpunit.de
pear channel-discover components.ez.no
pear channel-discover pear.symfony-project.com
pear install phpunit/PHPUnit

Assuming all goes well, you’ll get a success message and you should be good to go.

Depending on where you’re writing code, you may need to include the libraries at the top of each of your tests:

include_once ('C:Program FilesxamppphpPEARPHPUnitautoload.php');

Done.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.