Automated unit testing in PHP using PHPUnit

As part of the ZendFramework excercise I am following the author describes some automated testing process for the Framework modules as we build them. He talks about using the PHPUnit testing software which is available here This allows a developer to write automated tests for his objects as he develops and greatly improves the security of the code. The installation manual is here which describes how to install and run the product.

Couple of things you need to know before setting this up for the i5

Firstly the product uses the PEAR application to install. The documentation above shows how it should be installed but we needed to clarify a few things before we started.

1. The Install of pear is already in the Zend PHP install. If you check the PHP configuration you will see it is configured –with-pear (either use the ZendCore GUI or a script with phpinfo(); to get this information).
2. The pear object can be found in /usr/local/Zend/Core/bin. This is not the same for all installs so we had to find out where it was.

Now we know where the command is we started a QP2TERM session (call QP2TERM) and changed directory to /usr/local/Zend/Core/bin.

Then the commands which are detailed in the above documentation work! You will see a message when PHPUnit is installed correctly.

We ran a quick test to make sure it had in fact installed by calling phpunit –help this produced help output so we know it at least installed. now we have to write some tests to make sure it does what we expect.

If you are going to develop large and complex site using PHP we would suggest you install some kind of test environment such as this which allows you to block test your work.


Leave a Reply

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