I am trying to run HTTP tests on my Passport API Controllers but can't seem to access the Controller methods. I have the API setup and working fine when i access the API through Postman when using a personal access token.
When i try and call the same API controllers when running the HTTP test i created i.e. when running the phpunit command from the command line, the test never gets to the required API controller method. I think it's probably an issue with API authentication.
As per the documentation the HTTP test is calling the API endpoint with a GET request and also sending a header with the Authorization Token
@ronanh It’s probably an idea to follow the docs more closely.
If it’s an API endpoint, then you probably want to be calling your route with getJson instead. Otherwise, if there’s an authentication issue, Laravel is going to redirect rather than send a JSON response, and your test is going to fail.
Passport also has helpers so you don’t have to pass access tokens manually using withHeaders. You can call actingAs instead. So your test should look something like this: