8
votes

I have a Laravel 5.3 app.

Inside my api.php file, there's a route for posting an answer within a poll.

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

The route is part of a group, restricted by the auth:api middleware, using Laravel's Passport engine.

When calling this route from Postman or any other tool to test APIs, I get 401 which is ok because I'm not attaching the token.

But when unit testing this call using PHPUnit, it returns 500. I have no idea why.

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

I'm probably missing a configuration or setup instruction.

Any ideas?

1
The first think you should start is looking at Laravel's log file.This should help you to identify the issue. If it doesn't help you should at least include this in your question.Marcin Nabiałek
You were right. It was an error with not including the app key inside the .env.testing file. Thanks for pointing that out.Felipe Peña

1 Answers

4
votes

The 500 error was occurring because I forgot to add an app key to the .env.testing file.

It got solved after adding that.