Laravel TestCase not sending Authorization headers (JWT Token)
I tried the following code in Controller constructor:
if (env('APP_ENV') == 'testing'
&& array_key_exists("HTTP_AUTHORIZATION", request()->server())) {
JWTAuth::setRequest(\Route::getCurrentRequest());
}
We faced a similar issue when writing tests on Laravel 4.2, exceptionally we added this lines when running the application on the testing environment:
// This will only work when unit testing
if ((\App::environment() == 'testing') && array_key_exists("HTTP_Authorization", LRequest::server())) {
$headers['Authorization'] = LRequest::server()["HTTP_Authorization"];
}