<?php

namespace Tests;

use App\Models\User\UserModel;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
use Tymon\JWTAuth\Facades\JWTAuth;

abstract class TestCase extends BaseTestCase
{
    use CreatesApplication;

    public $token;

    /**
     * 构建headers
     * @param  array  $headers
     * @return array
     */
    public function headers(array $headers = array())
    {
        $headers['authorization'] = $this->token;
        $headers['appid'] = "gh_appid";
        $headers['paltform'] = 'wx';
        return $headers;
    }

    public function setUp()
    {
        parent::setUp();
        /** @var UserModel $user */
        $user = UserModel::where('uid', 50)->inRandomOrder()->first();
        if (collect($user)->isEmpty()) {
            exit("基境初始化失败");
        }
        if ($token = JWTAuth::attempt(['auth_key' => $user->phone, 'password' => $user->phone])) {
            dump($token);
            $this->token = "bearer{$token}";
        } else {
            exit("基境初始化失败");
        }
    }
}
