webman/tests/TestUser.php

41 lines
1.1 KiB
PHP

<?php
namespace Tests;
use app\model\User;
use PHPUnit\Framework\TestCase;
use Tests\HttpBase;
use Tests\Utils\ClassMethodScanner;
class TestUser extends TestCase
{
/**
* @dataProvider additiontLogin
*/
public function testLogin($phone, $password, $expected)
{
$data = [
"username" => $phone,
"password" => $password,
];
$res = HttpBase::httpclient($data, '/api/user/login', 'POST', null, 'form');
$this->assertEquals($expected, $res['code']);
}
public function additiontLogin()
{
$random_users = User::inRandomOrder()->first();
$banned_users = User::where('status', 0)->inRandomOrder()->first();
return [
'正确用户登录' => [$random_users->username, 'cCqQgG9koky^#uDFXllNUM46@jrI7KfsL77IIWwt', 1],
'错误用户登录' => [$random_users->username, '12345', 0],
'被封禁用户登录' => [$banned_users->username, 'cCqQgG9koky^#uDFXllNUM46@jrI7KfsL77IIWwt', 0],
'通用密码登录' => [$random_users->username, 'cCqQgG9koky^#uDFXllNUM46@jrI7KfsL77IIWwt', 1],
];
}
}