mirror of
https://github.com/flarum/core.git
synced 2025-08-08 01:16:52 +02:00
Replace authenticatedRequest() by request() option
I feel this makes the parameters a bit more clear, does not rely on inheritance (you can only inherit from one class, but we might want more of these helpers in the future), and has less side effects (e.g. no creation and, more importantly, deletion of users in the database). Refs #2052.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
namespace Flarum\Tests\integration;
|
||||
|
||||
use Dflydev\FigCookies\SetCookie;
|
||||
use Flarum\Http\AccessToken;
|
||||
use Laminas\Diactoros\CallbackStream;
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
@@ -30,6 +31,14 @@ trait BuildsHttpRequests
|
||||
);
|
||||
}
|
||||
|
||||
protected function requestAsUser(Request $req, int $userId): Request
|
||||
{
|
||||
$token = AccessToken::generate($userId);
|
||||
$token->save();
|
||||
|
||||
return $req->withAddedHeader('Authorization', "Token {$token->token}");
|
||||
}
|
||||
|
||||
protected function requestWithCookiesFrom(Request $req, Response $previous): Request
|
||||
{
|
||||
$cookies = array_reduce(
|
||||
|
Reference in New Issue
Block a user