lukeraymonddowning / poser

Create class based model factories in Laravel applications in seconds.
MIT License
277 stars 10 forks source link

Add `disableEvents()` helper #62

Closed minthemiddle closed 4 years ago

minthemiddle commented 4 years ago

In some tests, you may have side-effect events that you might want to switch off. An example is mails that are being sent after a model creation. You might not want to assert them with every test on this model.

I'm using a Factory macro by Paulund to append ->disableEvents() to all factories where I don't want the events to fire.

It would be nice to have an disableEvents() or withouthEvents() (seems closer to your naming schema) for Poser.

So it would result in:

UserFactory::new()->withoutEvents()->create();

lukeraymonddowning commented 4 years ago

@minthemiddle, thanks for this. I've created a pull request to address it. As I've done it, events will continue to fire after the model is created, but during creation, no events will fire. This should assure that you can use the models as expected after world-building.