I have the exact same issue after upgrading to Lumen 5.4 today!
Jan 30, 2017
7
Level 6
Lumen 5.4 doesn't seem to be sending test headers
AuthServiceProvider
<?php
$this->app['auth']->viaRequest('api', function ($request) {
if ($request->hasHeader('Authorization')) {
return User::where('api_token', $request->bearerToken())->first();
}
});
Lumen 5.3; test is green
<?php
/** @test */
public function user_can_access_own_endpoint_with_bearer_token()
{
$user = factory(App\User::class)->create([
'email' => '[email protected]',
'api_token' => 123456,
]);
$this->get('users/' . $user->id, [
'Authorization' => 'Bearer ' . $user->api_token
])->seeJson([
'email' => '[email protected]',
]);
}
Lumen 5.4; test is red
<?php
/** @test */
public function user_can_access_own_endpoint_with_bearer_token()
{
// throws unauthenticated exception because Authorization header is not visible to AuthServiceProvider
}
Note I tried the following and got the same result.
$this->call('GET', '/users/' . $user->id,[],[],[], ['HTTP_Authorization' => $user->api_token]);
I also did a sanity check in Postman with the Authorization header and it worked as expected in 5.4, therefore I concluded that the 5.4 testing framework is the problem.
I considered it was maybe something to do with laravel/dusk, but Lumen does not mention any requirements to import dusk or change tests, so I assume it has no relevance.
Please or to participate in this conversation.