Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel & PHPUnit: Getting 500 when unit testing "Passport" restricted route

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?

like image 578
Felipe Peña Avatar asked Jan 09 '17 05:01

Felipe Peña


1 Answers

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

It got solved after adding that.

like image 98
Felipe Peña Avatar answered Oct 19 '22 13:10

Felipe Peña