Skip to content

Instantly share code, notes, and snippets.

@johnroyer
Created February 23, 2022 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnroyer/f1403c976ca2b165c28c515f8b711c42 to your computer and use it in GitHub Desktop.
Save johnroyer/f1403c976ca2b165c28c515f8b711c42 to your computer and use it in GitHub Desktop.
Customize HTTP header in Lumen unit test
<?php
use Illuminate\Testing\TestResponse;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
trait ApiTokenRequestTrait
{
public function call($method, $uri, $parameters = [], $cookies = [], $files = [], $server = [], $content = null, $headers = [])
{
$symfonyRequest = SymfonyRequest::create(
$uri,
$method,
$parameters,
$cookies,
$files,
$server,
$content
);
foreach ($headers as $key => $value) {
$symfonyRequest->headers->set($key, $value);
}
$this->app['request'] = \Laravel\Lumen\Http\Request::createFromBase($symfonyRequest);
return TestResponse::fromBaseResponse(
$this->app->prepareResponse($this->app->handle($this->app['request']))
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment