Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postpersist doesn't work for the 2nd time #292

Closed
ghostika opened this issue Aug 5, 2022 · 4 comments
Closed

Postpersist doesn't work for the 2nd time #292

ghostika opened this issue Aug 5, 2022 · 4 comments

Comments

@ghostika
Copy link

ghostika commented Aug 5, 2022

I use the bundle together with Behat. Behat has a beforeScenario step, to purge the DB.

I have for the given entity - for example User - post persist calculation and the postPersist contains a flush as well. For Foundry, Autofersh is set to true by default.

I create it like this for the user:

$user = UserFactory::new()->create()->disableAutoRefresh()

If I have 2 Behat scenario, for the first test, everything goes though without a problem, the flush goes through from the postPersist, but for the second scenario, it doesn't, so I had to call disableAutoRefresh after I created a new User with a factory.

I have nothing special set up for Foundry, just the default setting.

The problem comes, that in the function object() it checks, if there is something in the changeset, which is not yet saved. Eventghoug for the second run, the changes are there from the postPersist - not saved into the DB, even though the flush is in the code - if I call a $user->save() nothing is saved actually.

I can solve things also by disabling the listener, but the perfect solution would be, if they could run correctly and always, not just for the first Scenario.

@kbond
Copy link
Member

kbond commented Aug 5, 2022

Hey @ghostika, sounds a bit similar to #234. WDYT?

@ghostika
Copy link
Author

ghostika commented Aug 5, 2022

@kbond I've seen that ticket as well. I don't think that it's the same problem.
As I mentioned, the first time it works perfectly, even the post persist part is saved into the DB.
Then in the second scenario - in-between I purge the SQLite DB - the user fixture is loaded into the DB, it's there, but the part of the post persist doesn't work any more.

I tried that I booted Foundry with fromContainer and withConfiguration , but then I received an error like this:

Model Factories with dependencies (Model Factory services) cannot be used without the foundry bundle.

The UserFactory has a dependency.

@kbond
Copy link
Member

kbond commented Aug 5, 2022

I'm sort of thinking that somehow the object is still managed by doctrine in the second scenario, so when it tries to save, it see's it's already there (even though it's not).

Before creating the entity in the second scenario, can you try clearing the em?

@ghostika
Copy link
Author

ghostika commented Aug 5, 2022

Hm, accidentally I left the TestState::bootFromContainer($this->container); inside and re-enabled the FoundryBundle inside the bundles.php and that solved the previous Model Factories with dependencies ... issue, the rest worked then.

I think the ticket can be closed, but in any case, it's interesting; the DB is in sync with the changes from postPersist as well.

@ghostika ghostika closed this as completed Aug 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants