thinkphp6 单元测试

<?php
declare(strict_types=1);
namespace tests;

use app\Request;
/**
 * @mixin BaseTest
 **/
trait HttpRun
{
    public function jsonPost(string $controller,string $action,array $data){
        $request = new Request();
        $request->setPathinfo('/'.$controller.'/'.$action);
        $request->withHeader(['HTTP_ACCEPT' => 'application/json',]);
        $request->withServer(['REQUEST_METHOD'=>'POST']);
        $request->withPost($data);
        $response = $this->app->http->run($request);
        $response->send();
        $this->app->http->end($response);
   return $response->getContent()
    }

}

  

  

posted @ 2022-07-21 11:04  kaycn  阅读(135)  评论(0)    收藏  举报