diff --git a/php-packages/testing/tests/integration/BuildsHttpRequests.php b/php-packages/testing/tests/integration/BuildsHttpRequests.php index 09704de8b..410d67b56 100644 --- a/php-packages/testing/tests/integration/BuildsHttpRequests.php +++ b/php-packages/testing/tests/integration/BuildsHttpRequests.php @@ -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