thephpleague / factory-muffin

Enables the rapid creation of objects for testing
https://factory-muffin.thephpleague.com/
MIT License
531 stars 72 forks source link

Add accessors for League\FactoryMuffin\Factory::$saved #411

Closed curtis1000 closed 8 years ago

curtis1000 commented 8 years ago

My suite automatically runs FactoryMuffin::deleteSaved() to clean up models after tests have run.

I run into trouble when I have a test that need to delete models manually as a part of the test. A DeletingFailedException is being thrown, and I do understand why that's happening.

Since my test needs to delete a model manually, I need a way to tell FactoryMuffin that a certain model should be skipped over when it attempts to deleteSaved().

That could be a accomplished a few different ways. It could be an option passed into the create() method, or it could be simply adding a getter/setter for the $saved collection, allowing my test to do the work of filtering the list of objects to be deleted later.

GrahamCampbell commented 8 years ago

Just catch the exception?

GrahamCampbell commented 8 years ago

The exception doesn't stop the rest of the deletions from happening, we continue deleting, then throw at the end.

GrahamCampbell commented 8 years ago

https://github.com/thephpleague/factory-muffin/blob/master/src/Exceptions/DeletingFailedException.php#L80

GrahamCampbell commented 8 years ago

You could also make an assertion on the number of failures.

curtis1000 commented 8 years ago

I will assert the number of failures, that should clear things up, thank you!