common/config.php 常量模块
common/net.php 网络通信模块 要安装curl模块
$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //execute post $result = curl_exec($ch); //close connection curl_close($ch); return $result;}?>
api.php 被测功能模块
urlencode($username), 'password'=>urlencode($password), 'appkey'=>urlencode(APP_KEY), ); $result=json_decode(post($url,$fields)); return $result; }function register($username,$password,$email){ $url = REGISTER_ADDR; $fields = array( 'email'=>urlencode($email), 'username'=>urlencode($username), 'password'=>urlencode($password), 'appkey'=>urlencode(APP_KEY), 'projectId'=>urlencode(PROJECT_ID), ); $result=json_decode(post($url,$fields)); return $result;}function apply($token,$projectId){ $url = APPLY_ADDR; $fields = array( 'token'=>urlencode($token), 'projectId'=>urlencode($projectId), ); $result=json_decode(post($url,$fields)); return $result;}?>
test.php 自动化测试模块
assertEquals("ok", $a1->result); } */ public function testLogin() { $a = login("test3@qq.com","123456"); echo $a->result.""; echo $a->message.""; echo $a->token.""; } public function testApply() { $a = login("test3@qq.com","123456"); echo $a->result.""; $a1 = apply($a->token,4277); echo $a1->result.""; echo "message is :".$a1->message.""; } }?>
$phpunit test.php