LEN

PHP http 接口 简单测试用例
<?php #开发环境 $url = 'http://work.com/index.php/Home/sp...
扫描右侧二维码阅读全文
03
2017/05

PHP http 接口 简单测试用例

<?php

#开发环境
$url = 'http://work.com/index.php/Home/sportEvaluationC/getFilialeRanking';

$post = array(
    'c_id' => 36,
    'date' => '2016-11'
);

ksort($post);
$postStr = '';
foreach($post as $key => $val) {
    $postStr .= '&'.$key.'='.$val;
}
$postStr = ltrim($postStr, '&');

echo "\r\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
//curl_setopt($ch, CURLOPT_HEADER, 0);//设置头文件的信息作为数据流输出    
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postStr);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);

$start = microtime_float();
$return = curl_exec($ch);
curl_close($ch);
$end = microtime_float();
print_r($return);
echo PHP_EOL,'计时:',$end - $start,PHP_EOL;

function microtime_float() {
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}
<?php

#自动化测试工具
$scriptList = getFile('./');
$log = __DIR__.'/autoTest.log';
$data = array();


foreach($scriptList as $file) {

    if(substr_count($file, 'autoTest')) continue;
    if(substr_count($file, '.log')) continue;
    /*$tmp = '------------------------'. $file.' start ---------------------------'."\r\n";
    exec("/usr/local/php7/bin/php $file", $data);
    foreach($data as $value) {
        echo $value,PHP_EOL;
        $tmp .= $value."\r\n";
    }
    $tmp .= '---------------------------'.$file.' end ---------------------------'."\r\n";
    echo file_put_contents($log, $tmp, FILE_APPEND),PHP_EOL;
     */
    echo '---------------------------'.$file.' start ---------------------------',PHP_EOL;
    passthru("/usr/local/php7/bin/php $file", $status);
    echo '---------------------------'.$file.' end ---------------------------',PHP_EOL;
    echo file_put_contents($log, $tmp, FILE_APPEND),PHP_EOL;
    sleep(1);
}

//获取文件列表
function getFile($dir) {

    $fileArray[] = NULL;
    if (false != ($handle = opendir ( $dir ))) {
        $i=0;
        while ( false !== ($file = readdir ( $handle )) ) {
            //去掉"“.”、“..”以及带“.xxx”后缀的文件
            if ($file != "." && $file != ".."&&strpos($file,".")) {
                $fileArray[$i]=__DIR__."/".$file;
                if($i == 100){
                    break;
                }
                $i++;
            }
        }
        //关闭句柄
        closedir ( $handle );
    }

    return $fileArray;
}
Last modification:November 27th, 2018 at 11:12 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment