目前项目里开发使用的测试方法都是php unit,不像之前埋个日至或者 用chrome 以及postman模拟请求。
在testcase继承了之后,然后新类直接继承父类,重写身份验证的方法,直接返回uid,然后直接调用get或者post方法。
还有个php的mock方法。继续深入学习和了解当中
地下是一个简单的demo
<?php
/**
* Created by PhpStorm.
* User: MeetYou
* Date: 2018/9/7
* Time: 15:12
*/
namespace Api\Controllers;
use PHPUnit\Framework\TestCase;
class HxwDemoTest extends TestCase
{
public function testSay()
{
$hxwDemo = new HxwDemo();
$result = $hxwDemo->say();
$this->assertEquals('one', $result);
// $this->assertEquals();
}
}
然后直接运行,最好是直接用如上图,phpunit自带的测试方法,