webman中如何集成单元测试?

码龍

我参照了thinkphp的集成单元测试。

可以测试服务类

但是无法测试http请求

test/BaseText.php


# DI
protected $container;

public function __construct($name = null, array $data = [], $dataName = '')
{
    parent::__construct($name, $data, $dataName);
    $builder = new \DI\ContainerBuilder();
    $builder->addDefinitions(config('dependence', []));
    $builder->useAutowiring(true);
    $builder->useAnnotations(true);
    $this->container = $builder->build();
}

public function __call($name, $arguments)
{
    return $this->container->{$name}(...$arguments);
}

test/ExampleText

use app\api\service\auth\Auth;

class ExampleTest extends BaseTest
{
    public function testExample()
    {
        $auth = $this->container->get(Auth::class);
        $this->assertInstanceOf(Auth::class, $auth);
        $row = $auth->login('admin', '123456');
        $this->assertIsNumeric($row->id);
        $token = $auth->getToken();
        $this->assertIsString($token);
        $boole = $auth->init($token);
        $this->assertIsBool($boole);
    }
}

截图

可以测试服务类 有不有办法测试控制器的返回呢

3454 1 2
1个回答

jeyfang

请教一下,你这里BaseText.php的完整代码是什么。它继承的是哪个类?另外你是如何实现单元测试可以自动加载项目类的?

  • 暂无评论
年代过于久远,无法发表回答
×
🔝