I'm trying to write tests to test API point on the legacy application I've been working on for some time. Route I have is protected by auth filter.
routes.php
$route->post('protected/route', ['before' => 'auth', 'uses' => 'ProtectedController@someProtectedTask']);
ProtectedControllerTest.php
public function testSomeProtectedTask {
$routePayload = [...];
$response = $this->call('POST', 'protected/route', [], [], [], $routePayload)
$this->assertResponseOk();
}
the response I get is "Expected status code 200, got 401" (Unauthorized).
I've tried to add
$this->app->forgetMiddleware('auth');
to setUp and testSomeProtectedTask methods without much success. Filters are supposed to be turned off in testing for Laravel but I'm not sure about that and I'm unable to find how to turn them off exactly.
Does anyone know how to turn off auth filter in testing without commenting it out before tests? Or is there a better way to test API endpoints in Laravel 4.2 and mock authentication somehow?
Aucun commentaire:
Enregistrer un commentaire