|
Debugging PHP
Oier Blasco
Introduction
The debugging process is a time consuming activity. When the project is a
small group of scripts all is easy, but when the size and complexity of
the project grows, the debugging time increases dramatically. With PhpUnit
you can speed up your debugging process.
PhpUnit is a PHP port of JUnit test framework wrote by Fred Yankowski
, you can download it from
http://www.ontosys.com/phiki/PhpUnit.
With PhpUnit you can write a suite of tests to check the correctness of your
code like a security harness. After the creation of the test suite you can
run all the tests automatically in a single step.
When you detect a bug, you can write a test to catch it. If the same bug is
introduced again you will detect it as soon as you run your test suite. If
you run the test suite frequently your will increase the robustness of your
code.
Getting started
Suppose we want to write a test suite for our simple Account class.
<?php
class Account{
var $balance;
function Account($initialBalance=0){
$this->balance = $initialBalance;
}
function withdraw($amount){
$this->balance -= $amount;
}
function deposit($amount){
$this->balance += $amount;
}
function getBalance(){
return $this->balance;
}
function transferFrom(&$sourceAccount,$amount){
$sourceAccount->withdraw($amount);
$this->deposit($amount);
}
?>
| Comments: | ||
| Problem with PhpUnit | Shaji Mathew | 02/15/02 06:59 |
| "enhanced" phpunit | Adrian Kubala | 07/18/01 11:07 |
| RE: What if I don't know the result? | Oier Blasco | 06/13/01 01:50 |
| What about the Zend de bugger | Mooza | 05/25/01 13:04 |
| What if I don't know the result? | Ken Egervari | 04/12/01 06:03 |
| This WILL save you time and heartache | Adam Jeffery | 04/11/01 12:28 |
| PhpUnit.sourceforge.net now hosts PhpUnit cod | Fred Yankowski | 04/10/01 10:37 |
| see PhpUnit.sourceforge.net | Fred Yankowski | 04/09/01 19:31 |
| download of class TestCase | Daniel Hopp | 04/09/01 09:42 |
| followed the link but no joy | Darren Christie | 04/09/01 04:02 |
| This type of development is worth the time. | Robert Nickens | 04/07/01 11:04 |
|
If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly. | ||


