| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <?php
- /**
- * 后台管理员测试.
- *
- * @author nj <nj@gmail.com>
- * @date 2020-01-23 00:12:48
- */
- declare(strict_types=1);
- namespace HyperfTest\Features\Manage;
- use App\Repositories\ManagerRepository;
- use App\Repositories\UserRepository;
- use Carbon\Carbon;
- use HyperfTest\HttpTestCase;
- use Swoole\Coroutine;
- class ManagerTest extends HttpTestCase
- {
- /**
- * 用户仓库.
- *
- * @var UserRepository|null
- */
- private $userRepo = null;
- private $managerRepo = null;
- /**
- * 测试之前执行.
- */
- public function setUp(): void
- {
- parent::setUp();
- $this->userRepo = make(UserRepository::class);
- $this->managerRepo = make(ManagerRepository::class);
- }
- /**
- * 测试完毕后执行.
- */
- public function tearDown(): void
- {
- parent::tearDown();
- }
- /**
- * 创建新mock用户
- */
- public function testCreateMockManagers()
- {
- $createNum = 5; // 生成的数量.
- $arrDeviceType = [
- 'I', 'A', 'H',
- ];
- for ($i = 0; $i < $createNum; $i++) {
- $username = strtolower(rand_letter(1) . random(13));
- $nick = $this->userRepo->randGenerateNick();
- $roleId = mt_rand(1, 10);
- $roleName = '角色名称';
- $salt = random(6);
- $plainPassword = 't88888888';
- $password = $this->managerRepo->generatePassword($plainPassword, $salt);
- $email = random(12) . '@test.com';
- $loginAt = Carbon::now()->toDateTimeString();
- $setarr = [
- 'username' => $username,
- 'nick' => $nick,
- 'role_id' => $roleId,
- 'role_name' => $roleName,
- 'salt' => $salt,
- 'password' => $password,
- 'email' => $email,
- 'login_at' => $loginAt,
- ];
- $this->managerRepo->create($setarr);
- Coroutine::sleep(0.1);
- }
- $this->assertEquals(true, true);
- }
- }
|