mirror of
https://github.com/flarum/framework.git
synced 2025-02-21 07:27:09 +08:00
Tests: Stop using Eloquent models for seeding data
This commit is contained in:
parent
b1a18971ca
commit
663f7a5d32
@ -9,8 +9,9 @@
|
||||
|
||||
namespace Flarum\Tests\integration;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Dflydev\FigCookies\SetCookie;
|
||||
use Flarum\Http\AccessToken;
|
||||
use Illuminate\Support\Str;
|
||||
use Laminas\Diactoros\CallbackStream;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
@ -33,10 +34,21 @@ trait BuildsHttpRequests
|
||||
|
||||
protected function requestAsUser(Request $req, int $userId): Request
|
||||
{
|
||||
$token = AccessToken::generate($userId);
|
||||
$token->save();
|
||||
$token = Str::random(40);
|
||||
|
||||
return $req->withAddedHeader('Authorization', "Token {$token->token}");
|
||||
/**
|
||||
* We insert this directly instead of via `prepareDatabase`
|
||||
* so that requests can be created/sent after the app is booted.
|
||||
*/
|
||||
$this->database()->table('access_tokens')->insert([
|
||||
'token' => $token,
|
||||
'user_id' => $userId,
|
||||
'created_at' => Carbon::now()->toDateTimeString(),
|
||||
'last_activity_at' => Carbon::now()->toDateTimeString(),
|
||||
'lifetime_seconds' => 3600
|
||||
]);
|
||||
|
||||
return $req->withAddedHeader('Authorization', "Token {$token}");
|
||||
}
|
||||
|
||||
protected function requestWithCookiesFrom(Request $req, Response $previous): Request
|
||||
|
Loading…
x
Reference in New Issue
Block a user