非常简单的测试框架,有兴趣的朋友可以增加功能。

mahaixing 2004-04-22 05:36:47
<?php

/**
* Base test class
* All test case must extends from this class
*/
class test {

/* All construct method must inherited test() method.
* $name: The name of the test.
*/
function test($name) {
assert_options( ASSERT_CALLBACK, 'assert_callback');

$name = "PHP test \"".$name."\"";
echo "<table width=\"100%\">
<tr>
<td bgcolor=\"#C9C4C4\">
<div align=\"center\">
<font size=\"6\">".$name."</font>
</div></td>
</tr>
</table><br>";
}

/**
* initialize all class variable that needed.
*/
function setup() {

}

/**
* destrouct variables;
*/
function tear_down() {

}

/**
* run the test.
*/
function do_test() {
$functions = get_class_methods(&$this);
$this->setup();
while (list($k, $v) = each($functions)) {
switch ($v){
case "setup":
break;
case "test":
break;
case "tear_down":
break;
case "do_test":
break;
default:
if ($v != get_class($this)) {
echo "<font color=\"#FF00E6\"> *** Test method \"$v\" ***</font><br><br>";
call_user_func(array(&$this, $v));
echo "<font color=\"#4FAF2B\"> *** Success ! *** </font><br><br>";
}
}
}
$this->tear_down();
}
}

/**
* Function show array
* Show the content of $array;
*/
function show_array($array) {
echo "<pre>";
print_r($array);
echo "</pre>";
}

/**
* assert call back function.
*/
function assert_callback( $script, $line, $message ) {
echo '<font color="#FF0033">You have a design error in your script <b>', $script,'</b> : line <b>', $line,'</b> :<br />';
echo '<br />Source code: "<b>', ereg_replace( '^.*//\*', '', $message ), '"</b><br /><br />';
echo 'Open the source file and check it, because it\'s not a normal behaviour !</font>';
exit;
}
?>
...全文
50 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧