Closed ndench closed 1 year ago
Hello,
This would be indeed a nice addition! Maybe we could create a method Configuration::disablePersist()
and then set Factory::$persist
in the factory's constructor depending on that?
but since Configuration
is internal, we have to find another place where we can call Configuration::disablePersist()
. Maybe a method disablePersit()
in Factories
trait? or a static method Factory::disablePersist()
?
any thoughts @kbond?
Maybe a method disablePersit() in Factories trait?
This was my first thought, then auto-re-enable after each test?
yep we can do this in a @after
hook
or a static method Factory::disablePersist()?
I'd say let's try and keep it to the test trait for now but this could be a possibility if this functionality is required outside of tests.
some thoughts about this: we should also throw an exception if Configuration::disablePersist()
has been called, and if some method like Factory::repository()
on Factory::find()
is used
I'll work on this task soon, since I think it will be a nice addition!
Foundry is a great bundle! We had a custom builder pattern we were using before, but are in the process of moving everything to Foundry.
We have some use cases where we want nothing to persist, but there currently doesn't seem to be a way to globally disable persisting (without putting
->withoutPersisting()
in our AbstractFactory).Our use cases are:
Our "solution" to item 1 has been to call the internal
TestState::bootFoundryForUnitTests()
method in thesetUp()
method of our contract tests. This creates Foundry without an entity manager, so the entities aren't persisted even though we're technically in a KernelTestCase.However, we don't have a solution for item 2. It would be great to be able to use
TestState::configure()
orTestState::disablePersist()
at runtime before we instantiate any factories.Has anyone else had similar use cases? Do you think this would be a valuable addition to the library?