UserTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * 功能测试-用户.
  4. *
  5. * @author nj <nj@gmail.com>
  6. * @date 2020-01-21 20:46:13
  7. * 命令行: /usr/local/Cellar/php/7.3.10/bin/php /Users/mac/works/projects/douyin-lite/vendor/bin/co-phpunit --configuration /Users/mac/works/projects/douyin-lite/phpunit.xml --filter "/(::testCreateMockUsers)( .*)?$/" HyperfTest\Features\UserTest /Users/mac/works/projects/douyin-lite/test/Features/UserTest.php --teamcity
  8. */
  9. declare(strict_types=1);
  10. namespace HyperfTest\Features;
  11. use App\Repositories\UserRepository;
  12. use Carbon\Carbon;
  13. use HyperfTest\HttpTestCase;
  14. use Swoole\Coroutine;
  15. class UserTest extends HttpTestCase
  16. {
  17. /**
  18. * 属性描述.
  19. *
  20. * @var UserRepository
  21. */
  22. private $userRepo = null;
  23. /**
  24. * 测试之前执行.
  25. */
  26. public function setUp(): void
  27. {
  28. parent::setUp();
  29. $this->userRepo = make(UserRepository::class);
  30. }
  31. /**
  32. * 测试完毕后执行.
  33. */
  34. public function tearDown(): void
  35. {
  36. parent::tearDown();
  37. }
  38. /**
  39. * 创建新mock用户
  40. */
  41. public function testCreateMockUsers()
  42. {
  43. $createNum = 10; // 生成的数量.
  44. $arrDeviceType = [
  45. 'I', 'A', 'H',
  46. ];
  47. for ($i = 0; $i < $createNum; $i++) {
  48. $nick = $this->userRepo->randGenerateNick();
  49. $deviceNo = $this->userRepo->randGenerateDeviceNo();
  50. $regionCode = '+86';
  51. $mobile = '1' . mt_rand(3, 8) . random(9, 1);
  52. $coins = mt_rand(0, 100);
  53. $surplus = mt_rand(0, 100);
  54. $birth = mt_rand(1979, 2000) . '-' . str_pad((string)mt_rand(1, 12), 2, '0', STR_PAD_LEFT)
  55. . '-' . str_pad((string)mt_rand(1, 26), 2, '0', STR_PAD_LEFT);
  56. $gender = mt_rand(1, 2);
  57. $status = 1;
  58. $ip = mt_rand(199, 244). '.' . mt_rand(199, 244) . '.'. mt_rand(199, 244) . '.'. mt_rand(199, 244);
  59. $inviteCode = strtoupper(random(10));
  60. $deviceType = $arrDeviceType[mt_rand(0, 2)];
  61. $channelId = strtoupper(random(12));
  62. $maxView = 3;
  63. $viewedNum = intval(3 - mt_rand(0, 3));
  64. $vipExpired = Carbon::now()->addDays(mt_rand(1, 365))->toDateTimeString();
  65. $avatarPath = '/dfhhead2/tx_'.mt_rand(1, 20).'.jpg';
  66. $setarr = [
  67. 'nick' => $nick,
  68. 'area_code' => $regionCode,
  69. 'mobile' => $mobile,
  70. 'avatar' => $avatarPath,
  71. 'coins' => $coins,
  72. 'balance' => $surplus,
  73. 'birth' => $birth,
  74. 'gender' => $gender,
  75. 'status' => $status,
  76. 'ip' => $ip,
  77. // 'invite_code' => $inviteCode,
  78. 'device_no' => $deviceNo,
  79. 'device_type' => $deviceType,
  80. 'channel_id' => $channelId,
  81. 'max_view' => $maxView,
  82. 'viewed_num' => $viewedNum,
  83. 'vip_expired' => $vipExpired,
  84. ];
  85. $this->userRepo->create($setarr);
  86. Coroutine::sleep(0.1);
  87. }
  88. $this->assertEquals(true, true);
  89. }
  90. }