|
Size: 3003
Comment:
|
← Revision 10 as of 2011-11-16 10:17:02 ⇥
Size: 2957
Comment: Removed spam links.
|
| Deletions are marked like this. | Additions are marked like this. |
| Line 48: | Line 48: |
| [[http://www.myownasp.com|Quickbooks hosting]] |
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 phpunit
A 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.
Tips
- 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
phpunit LoggerLevelTest.php
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.
From Scratch
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)
MacPorts
I prefer MacPorts [1] 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 [2] 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.