Today received a task, need to calculate the number, because it involves integers, decimal, and scientific counting methods and many other conditions, so the manual test is very troublesome, so think of the PHP Unit test tool PHPUnit, so write a document for future reference.
After reading PHPUnit's document, I have some basic understanding,
http://pear.php.net/manual/en/packages.php.phpunit.intro.php
The work flow is as follows:
1. Design your CLASS/API
2. Create a test assembly
3. Realize Class/api
4. Run the test
5. Fix test failure or error, back to step 4th.
Let me give you an example:
Here is the class you want to test, where the FORMATN function is a function that takes a 5-digit valid number of any number.
----------format_number.php-----------
class fo {
function fo() {
}
function formatn($num) {
$num = rtrim($num,"0");
$pos = strpos($num,".");
$num = str_replace(".","",$num);
$count1 = strlen($num);
$num = ltrim($num,"0");
$count2 = strlen($num);
$zeroc = $count1 - $count2;
$num = substr($num,0,6);
$num = round($num/10);
//$num = str_pad($num, 5, "0");
if ($pos !== false) {
$num = str_pad($num, (strlen($num)+$zeroc), "0", STR_PAD_LEFT);
$dotl = substr($num,0,$pos);
$dotr = substr($num,$pos);
$num = $dotl.".".$dotr;
}
return $num;
}
}
}