Phpunit

From DreamHost

Jump to: navigation, search

PHPUnit is an open-source unit testing framework, which is an integral part of best-practices development. It is an important part of the Agile methodology and Extreme Programming.

Contents

Installation

You can use PEAR on Dreamhost to install PHPUnit. The instructions here are for the latest-and-greatest PHPUnit build which you can download from the PHPUnit website. http://www.phpunit.de/

First, download the package and untar to your directory.

$ tar -zxvf PHPUnit-vX.XXX.tar.gz

Next, create a local bin directory if you don't have one already.

$ mkdir -p $HOME/local/bin

Copy the phpunit executable into local/bin.

$ cp PHPunit-vXXX/bin/phpunit $HOME/local/bin

Next, add the local bin to your path (if you don't have it already) by adding this line to the end of your .bash_profile:

PATH="/home/<username>/local/bin:$PATH"

Now, test to ensure phpunit is working properly.

$ phpunit --help

You should get a detailed list of help on all the options without any sort of error message.

Enabling Code Coverage Capability

Note, the key aspects to installing this properly is to create a wrapper script to call a custom php.ini which will load xdebug.so and disable the ZendOptimizer because they are incompatible.

First, create a wrapper script in your $HOME/local/bin/php-wrapper using an editor like vi or emacs. The contents of the script should be:

#!/bin/sh
exec /usr/local/php5/bin/php -c $HOME/phpunit-php.ini

Now, copy the existing php.ini from the system to your local folder.

$ cp /etc/php5/php.ini $HOME/phpunit-php.ini

Next, copy the xdebug.so binary from this link, and place it in $HOME/local/lib

$ cp <xdebug.so> $HOME/local/lib

Next, change the phpunit-php.ini by commenting out the following line:

 # zend_extension=/some/path/to/ZendOptimizer

And add the following line:

 zend_extension=/home/<username>/local/lib/xdebug.so

Now, modify the local/bin/phpunit application to use your wrapper script by changing the first line to:

#! /home/<yourusername>/local/bin/php-wrapper

Again, test phpunit to ensure that it is working:

$ phpunit --help

This time, you should see flags for --code-coverage which indicates you have successfully set-up the custom ini file with xdebug.so. Sweet.

Troubleshooting

Nothing here, yet.

External Links

Official Site: http://pear.php.net

Personal tools