php 测试类

 今天写了一个测试的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                 $actualcall_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  "<span style='color:green'>Passed Result: $functionName expected: $expected vs actual  $actual</span><br/>";
25         }
26         else
27         {
28             echo  " <span style='color:red'>Failed</span> Result: $functionName  expected:  $expected vs actual $actual</span><br/>";
29         }
30     }
31 
32  
45     #endregion

posted @ 2012-08-04 23:29  chinajinwanjun  Views(220)  Comments(0)    收藏  举报