TestCase.php 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace Tests;
  3. use App\Models\User\UserModel;
  4. use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
  5. use Tymon\JWTAuth\Facades\JWTAuth;
  6. abstract class TestCase extends BaseTestCase
  7. {
  8. use CreatesApplication;
  9. public $token;
  10. /**
  11. * 构建headers
  12. * @param array $headers
  13. * @return array
  14. */
  15. public function headers(array $headers = array())
  16. {
  17. $headers['authorization'] = $this->token;
  18. $headers['appid'] = "gh_appid";
  19. $headers['paltform'] = 'wx';
  20. return $headers;
  21. }
  22. public function setUp()
  23. {
  24. parent::setUp();
  25. /** @var UserModel $user */
  26. $user = UserModel::where('uid', 50)->inRandomOrder()->first();
  27. if (collect($user)->isEmpty()) {
  28. exit("基境初始化失败");
  29. }
  30. if ($token = JWTAuth::attempt(['auth_key' => $user->phone, 'password' => $user->phone])) {
  31. dump($token);
  32. $this->token = "bearer{$token}";
  33. } else {
  34. exit("基境初始化失败");
  35. }
  36. }
  37. }