博客列表 >编写测试用例 phpunit

编写测试用例 phpunit

php开发大牛
php开发大牛原创
2018年04月19日 16:01:32728浏览

<?php

$basedir = dirname(__FILE__);

require_once($basedir . '/lib/basetestdev.php');

define("PHONE", "xxx");

define("PWD", "xxx");

define("POSTURL","xxx");

class TestAPI extends PHPUnit_Framework_TestCase {

    private function call_http($path, $param, $expect = 'ok') {

        $_param = build_get_param($param);

        $url = PREFIX . "$path?" . $_param;

        $buf = do_Get($url);

        $obj = json_decode($buf, True);

        $this->assertEquals($obj['retval'], $expect);

        return $obj;

    }

    private function call_https($path, $param, $expect = 'ok') {

        $_param = build_get_param($param);

        $url = HTTPSPREFIX . "$path?" . $_param;

        $buf = do_Get($url);

        $obj = json_decode($buf, True);

        $this->assertEquals($obj['retval'], $expect);

        return $obj;

    }

  public function testLogin(){

    $param = array(

      'type' => 'phone'

      ,'token' => PHONE

      ,'password' => PWD

    );

    $url = 'login';

    return $this->call_http($url, $param);

  }

  /**

   * @depends testLogin

   */

  public function testInfo(array $user){

    $session = $user['retinfo']['session'];

    $param = array(

      'session' => $session

    );

    $url ='info';

    return $this->call_http($url, $param);

  }


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议