1
0
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:
Franz Liedke
2020-03-20 18:22:52 +01:00
parent a13c0bb612
commit 25f772c1ea
3 changed files with 19 additions and 72 deletions

View File

@@ -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(