当前位置:Gxlcms > PHP教程 > php测试类

php测试类

时间:2021-07-01 10:21:17 帮助过:9人阅读

今天写了一个测试的php类。

这个对于单元测试很方便。 但是对于参数的处理,我感觉代码很丑陋,有没有高手帮忙,美化一下。

参数始终不可以动态。

//调用 Test("365",$className , "DateDiff",array( "2013-8-4","2012-8-4"));

1#region Test 2 3
4 function Test($expected,$className,$functionName,$parameteres )
5 {
6
7 switch(sizeof($parameteres))
8 {
9 case 0:
10 $actual= call_user_func(array($className,$functionName) );
11 break;
12 case 1:
13 $actual= call_user_func(array($className,$functionName),$parameteres[0] );
14 break;
15 case 2:
16 $actual= call_user_func(array($className,$functionName),$parameteres[0],$parameteres[1] );
17 break;
18 case 3:
19 $actual= call_user_func(array($className,$functionName),$parameteres[0],$parameteres[1],$parameteres[2] );
20 break;
21 }
22 if($expected==$actual )
23 {
24 echo "Passed Result: $functionName expected: $expected vs actual $actual
";
25 }
26 else
27 {
28 echo " Failed Result: $functionName expected: $expected vs actual $actual
";
29 }
30 }
31
32
45 #endregion

人气教程排行