ManagerTest.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * 后台管理员测试.
  4. *
  5. * @author nj <nj@gmail.com>
  6. * @date 2020-01-23 00:12:48
  7. */
  8. declare(strict_types=1);
  9. namespace HyperfTest\Features\Manage;
  10. use App\Repositories\ManagerRepository;
  11. use App\Repositories\UserRepository;
  12. use Carbon\Carbon;
  13. use HyperfTest\HttpTestCase;
  14. use Swoole\Coroutine;
  15. class ManagerTest extends HttpTestCase
  16. {
  17. /**
  18. * 用户仓库.
  19. *
  20. * @var UserRepository|null
  21. */
  22. private $userRepo = null;
  23. private $managerRepo = null;
  24. /**
  25. * 测试之前执行.
  26. */
  27. public function setUp(): void
  28. {
  29. parent::setUp();
  30. $this->userRepo = make(UserRepository::class);
  31. $this->managerRepo = make(ManagerRepository::class);
  32. }
  33. /**
  34. * 测试完毕后执行.
  35. */
  36. public function tearDown(): void
  37. {
  38. parent::tearDown();
  39. }
  40. /**
  41. * 创建新mock用户
  42. */
  43. public function testCreateMockManagers()
  44. {
  45. $createNum = 5; // 生成的数量.
  46. $arrDeviceType = [
  47. 'I', 'A', 'H',
  48. ];
  49. for ($i = 0; $i < $createNum; $i++) {
  50. $username = strtolower(rand_letter(1) . random(13));
  51. $nick = $this->userRepo->randGenerateNick();
  52. $roleId = mt_rand(1, 10);
  53. $roleName = '角色名称';
  54. $salt = random(6);
  55. $plainPassword = 't88888888';
  56. $password = $this->managerRepo->generatePassword($plainPassword, $salt);
  57. $email = random(12) . '@test.com';
  58. $loginAt = Carbon::now()->toDateTimeString();
  59. $setarr = [
  60. 'username' => $username,
  61. 'nick' => $nick,
  62. 'role_id' => $roleId,
  63. 'role_name' => $roleName,
  64. 'salt' => $salt,
  65. 'password' => $password,
  66. 'email' => $email,
  67. 'login_at' => $loginAt,
  68. ];
  69. $this->managerRepo->create($setarr);
  70. Coroutine::sleep(0.1);
  71. }
  72. $this->assertEquals(true, true);
  73. }
  74. }