Writing unit tests for log4php
So how do you get started?
Install the latest version of PHPUnit
Install the latest version of XDebug
- Checkout the latest source code
svn co http://svn.apache.org/repos/asf/incubator/log4php/trunk log4php-trunk
- Run the unit test suite
cd log4php-trunk/src/test/php phpunitA code coverage report is created inside target/test/report.
- Open up target/test/report/index.html in your browser and have a look what's covered by tests and not.
When you find something to test create the according ClassNameTest.php file inside src/test/php/ (the directory layout is the same as you see in src/main/php but using Test.php as the end of the filename).
- Write the test cases
- If you have commit access just go ahead and submit your new test cases when it runs fine and cover new code. If you don't have commit access simply do:
svn diff > something.patch
and hand that file over to log4php mailing list so one of the committers can review and commit it.
- Have a look on how other unit tests are written before you start writing your own tests.
- Use self::markTestIncomplete() to mark incomplete unit tests.
- To execute just one test class use
Running xdebug on a mac
Mac users don't have an easy life with xdebug. For example MAMP cannot be used easily a custom install is necessary.
Using Entropy.ch PHP
Entropy.ch is providing precompiled PHP packages for Tiger (a bit outdated but works for Log4PHP) and Leopard. Even an precompiled Apache can be downloaded. See: http://www.entropy.ch/software/macosx/php/
After installing it on your system under /usr/local you just need to set your .bash_profile variables:
# Set enviroment for Entropy Apache 2 and PHP 5.2.x PATH=$PATH:/usr/local/apache2/bin:/usr/local/php5/bin
and you'll need to upgrade pear:
$ pear upgrade PEAR
Then follow normal instructions above. This worked out for Tiger.
You need to compile Xdebug on Mac (binaries are only available for Windows) and in order to do that you need to have necessary tools and header files installed. The basic requirements for compiling PHP extensions is the same as for PHP itself (see: http://www.php.net/anoncvs.php)
I prefer MacPorts  as my package manager on OS X since that's the easiest way to get all needed tools and header files. There's too many tutorials on this  so I won't go into details. But at least you will have to do this:
$ sudo port install php5 +apache2 +mysql5 +pear $ sudo port install php5-devel
Some of the basic tools like gcc etc is installed with Xcode, but most of what you need is also available in MacPorts.