hasib32 / rest-api-with-lumen

Rest API boilerplate for Lumen micro-framework.
487 stars 143 forks source link

Problem with Mocking Repository Model #22

Closed ibpavlov closed 7 years ago

ibpavlov commented 7 years ago

I have a problem mocking the Model of a Repository. Now the class is directly used in your code and the only way to Mock it is to overwrite it using Reflection, which is not the best practice.

protected $modelName = User::class;

Isn't it better to use the assignment in the construction like:

public function __construct(Model $model)
{
    $this->model = $model;
    $this->loggedInUser = $this->getLoggedInUser();
}

Please tell me what you think about this approach.

shahriar1 commented 7 years ago

@ibpavlov I think you're right about it - here it'd be better to use the constructor to initialize the model.

@hasib32 you should update the AbstractEloquentRepository class to reflect this change

hasib32 commented 7 years ago

@ibpavlov Thanks for the recommendation. If you want you can create a pull request for the change.