Laravel & PHPUnit: Getting 500 for unit testing a Passport limited route

I have a Laravel 5.3 application.

Inside my api.php file api.php is a route for posting the response as part of the survey.

Route::group(['middleware' => 'auth:api'], function () { Route::post('/poll/answer', 'API\ PollsController@createAnswer '); });

The route is part of a group limited to the auth:api middleware using the Laravel Passport engine.

When calling this route from Postman or any other tool for testing the API, I get 401, which is normal, because I am not attaching a token.

But when the module tests this call with PHPUnit, it returns 500. I have no idea why.

$this->postJson('api/poll/answer');

I probably have no setup or setup instructions.

Any ideas?

+7
unit-testing phpunit laravel laravel-5
source share
1 answer

A 500 error occurred because I forgot to add the application key to the .env.testing file.

This was resolved after adding this.

+3
source share

All Articles