vendredi 30 octobre 2015

Test Failure Missing Attribute From Disabled Middleware Laravel Lumen

I'm trying to create some tests for a Controller in my Laravel Lumen application, but I have been having a problem with a missing attribute that I has set in the Middleware.

So in my middleware I set a attribute to then use in my controller after.

//Save data user data into userdata attribute
$request->userdata = $user_session[0];

Then I use the attribute to select my data needed.

//Select current user data
$user = app('db')->select('SELECT * FROM users 
                           WHERE id='.$request->userdata->user_id);

The Problem I'm facing is when I want to build a test for my controller.

$this->app->instance('middleware.disable', true);
$response = $this->call('GET', '/v1/user/me');

I disabled the middleware as I cannot use it for the test. But I was wonder if I can solve my problem by mocking the attribute in some way.

Any help would be greatly appreciated, thanks all.

Aucun commentaire:

Enregistrer un commentaire