* @date 2020-01-21 20:46:13 * 命令行: /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 */ declare(strict_types=1); namespace HyperfTest\Features; use App\Repositories\UserRepository; use Carbon\Carbon; use HyperfTest\HttpTestCase; use Swoole\Coroutine; class UserTest extends HttpTestCase { /** * 属性描述. * * @var UserRepository */ private $userRepo = null; /** * 测试之前执行. */ public function setUp(): void { parent::setUp(); $this->userRepo = make(UserRepository::class); } /** * 测试完毕后执行. */ public function tearDown(): void { parent::tearDown(); } /** * 创建新mock用户 */ public function testCreateMockUsers() { $createNum = 10; // 生成的数量. $arrDeviceType = [ 'I', 'A', 'H', ]; for ($i = 0; $i < $createNum; $i++) { $nick = $this->userRepo->randGenerateNick(); $deviceNo = $this->userRepo->randGenerateDeviceNo(); $regionCode = '+86'; $mobile = '1' . mt_rand(3, 8) . random(9, 1); $coins = mt_rand(0, 100); $surplus = mt_rand(0, 100); $birth = mt_rand(1979, 2000) . '-' . str_pad((string)mt_rand(1, 12), 2, '0', STR_PAD_LEFT) . '-' . str_pad((string)mt_rand(1, 26), 2, '0', STR_PAD_LEFT); $gender = mt_rand(1, 2); $status = 1; $ip = mt_rand(199, 244). '.' . mt_rand(199, 244) . '.'. mt_rand(199, 244) . '.'. mt_rand(199, 244); $inviteCode = strtoupper(random(10)); $deviceType = $arrDeviceType[mt_rand(0, 2)]; $channelId = strtoupper(random(12)); $maxView = 3; $viewedNum = intval(3 - mt_rand(0, 3)); $vipExpired = Carbon::now()->addDays(mt_rand(1, 365))->toDateTimeString(); $avatarPath = '/dfhhead2/tx_'.mt_rand(1, 20).'.jpg'; $setarr = [ 'nick' => $nick, 'area_code' => $regionCode, 'mobile' => $mobile, 'avatar' => $avatarPath, 'coins' => $coins, 'balance' => $surplus, 'birth' => $birth, 'gender' => $gender, 'status' => $status, 'ip' => $ip, // 'invite_code' => $inviteCode, 'device_no' => $deviceNo, 'device_type' => $deviceType, 'channel_id' => $channelId, 'max_view' => $maxView, 'viewed_num' => $viewedNum, 'vip_expired' => $vipExpired, ]; $this->userRepo->create($setarr); Coroutine::sleep(0.1); } $this->assertEquals(true, true); } }