3 years ago

Event doesn't store model while unit testing

Posted 3 years ago by Clement_Te


I am facing a weird behavior while writing unit tests for my app. Basically, I have a model, that when it is created (saved into the database), a function is called that create and save another model in the database as well.

I do this using the events in Laravel 5.1 :

Although, when unit testing, I create the model in the setUp(), the method is called as the event calls it but no new data is added to the database (while the first model correctly is).

I hope I was able to explain my issue properly.

Is there anything that I would not be aware of while unit testing with events on models?

Thank you in advance for your help. Kind regards,

Please sign in or create an account to participate in this conversation.