withHeader('Content-Type', 'application/json') ->withBody( new CallbackStream(function () use ($json) { return json_encode($json); }) ); } 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( $previous->getHeader('Set-Cookie'), function ($memo, $setCookieString) { $setCookie = SetCookie::fromSetCookieString($setCookieString); $memo[$setCookie->getName()] = $setCookie->getValue(); return $memo; }, [] ); return $req->withCookieParams($cookies); } }