Created
February 23, 2022 06:59
-
-
Save johnroyer/f1403c976ca2b165c28c515f8b711c42 to your computer and use it in GitHub Desktop.
Customize HTTP header in Lumen unit test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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