I have created my own authentication middleware that accepts an Authorization header which is used to query the api_tokens
table to find a matching token and checks expiry.
This is working fine when testing manually but the automated tests are doing something strange. My tests basically look like this:
public function testGetLocation()
{
$user = factory(\App\Models\User::class, 'userA')->create();
$token = factory(\App\Models\ApiToken::class, 'userA-token')-create();
$location = factory(\App\Models\Location::class, 'userA-location1')->create();
$this->json('GET', '/api/location/'.$location->id, [], ['Authorization' => 'Bearer '. $token->token])
->assertStatus(200);
}
However when I run the test I receive a 500 error saying that column users.api_token
doesn't exist. I have removed this column from the user table as it's not longer required. If I put it back in I don't receive an error but the test user can't authenticate. Obviously Laravel or phpunit are somehow ignoring the auth that I am trying to use. I can't see where.
After searching Google I have tried things others have mentioned such as adding actingAs($user)
and $this->be()
but this hasn't helped.
Any suggestions?
Aucun commentaire:
Enregistrer un commentaire