1 year ago

#372771

test-img

rahul anand

Mock Laravel Model in phpunit test

I am persuing unit test and here i don't want to use the database. And i am doing mocking of each and everything. But i am unable to mock Models. If i try to mock the model with override then it gives me this error: class already exists. And if i tried without overide then the mocking is not working. I also found a trait For it named laravel query factory, which helps me to give a dummy query builder. But i am facing one issue in it. When i use count funtion on model then it gives me following error: ErrorException: Undefined index: aggregate

Meanwhile i am not able to mock in any way, anyone please help me to do the same

Here is the model Query which i want to mock: MyModel::where('column_name', 12)->count();

laravel

unit-testing

mocking

phpunit

0 Answers

Your Answer

Accepted video resources