Home > php教程 > PHP开发 > body text

Code for testing php functions

黄舟
Release: 2016-12-14 10:21:06
Original
1141 people have browsed it

/**
* Description of parameter array $ParamList
*
* The first dimension index of the array is the parameter name of the function that needs to be tested. Each element of the second dimension is the possible value of the parameter that needs to be tested. The element value can be an array.
*/

$ParamList = array("Param1" => array(3,4,3,2,1),
"Param2" => array( 3,2,5),
"Param3" => array(0,0.5,1,1.5));

// Test function
sysTestFunction("Test", $ParamList);


// To be tested Function
function Test($Param1, $Param2, $Param3)
{
       return $Param1 . "|" . $Param2 . "|" . $Param3;
}


/**
* Automatic test
* @param string $FunctionName Function name
* @param array $ParamList Parameter list
* @return array
*/
Function SystemSxStfunction ($ FunctionName, $ Paramlist) {
IF (EMPTY ($ FunctionName)) {

{


}}


if (
}}} Array (Current ($ Paramlist) )
{h {o "parameter is not a 2 -dimensional array";
Return false;

}

$ testparamlist = syscombinearray ($ Paramlist);


Echo ". T; ";
      foreach($TestParamList as $Key => $TestParamInfo)
                                                                                                                                                                                                                                                              ​ 

                                                                                                                                                                                  if(is_array($ Param))
                                                                                                                                                                                                                                                   }
              elseif(is_bool($Param))
{O echo "parameter". $ Paramkey. ", The type is BOLL:";
if ($ Param) {
echo "true";
                                                                                                                                                                                         t;";
                                                                                                                                                     , ", $TempParamList);
    unset($TempParamList);
EVAL ("$ TestreturnResult =". $ FunctionName. "(". $ Params. ");); ; "; print_r($TestReturnResult);                                                            echo "The function returns true"; }

                                                                                                                                                                                                                                                                         .
}
}

/**
* Function to calculate combination
*
* @param array $CombinList 2-dimensional array to be arranged and combined
* @return array The combined array
* /Function SysCombinearray ($ CombinList) {
if (! Is! Is_array ($ compinlist)) {
Echo "The parameter is not a 2 -dimensional array";
Return false; Calculate C(a,1) * C(b, 1) * ... * The value of C(n, 1)*/
$CombineCount = 1;
foreach($CombinList as $Key => $Value)
{
          $CombineCount *= count($Value); The maximum number of repetitions that appear vertically after the Position = $StartPosition;

                       $SpaceCount = $CombineCount / count($ParamList) / $RepeatTime;

for($J = 1; $J <= $SpaceCount; $J ++)
RepeatTime; $I ++)
                                                                                Position += $RepeatTime * count($ParamList);
              }

                        $StartPosition += $RepeatTime;

}
}

  return $Result;
}
?>

The above is the code to test the php function. I hope it can help you. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template