-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
feature(doctrine events): allow factories to disable doctrine events. #216
Conversation
9e5943a
to
badd576
Compare
Thanks for working on this. Don't worry about the CS issues - I can fix before merging. Let me know if you need help with the test suite - it's a bit... complicated. |
@kbond actually I tried to build a docker environment to make tests works in local env, I partially succeed (I can't run functional tests). |
caab5e0
to
6052c8c
Compare
I set up a docker environment with php/pqsql/nginx, I configured it well, the DATABASE_URL is well set in the container, but I still don't succeed to run your test suite. I always have this error Except that, I can see that my functional tests doesn't work on the CI, my doctrine EventSubscriber fixture is not executed. |
Unfortunately, I don't have docker experience. I run everything locally. I was going to suggest doing what you did but am unsure why you're getting that error. Any more context? That error should output the command output. |
For the test event subscriber: try having it implement |
6052c8c
to
5412e78
Compare
Regarding running the tests locally, could https://github.com/nektos/act help? I haven't used it myself but see it referenced quite a bit. |
e768e13
to
aff8d0a
Compare
ok finally I succeed to make it run locally (with my docker setup), and it works locally with a php8. |
Great to hear. I'd like to make the test suite easier to run for contributors. Is there anything you can share that could help? Are there other/bundles libraries you know of that I can use as inspiration? |
5ea29bf
to
fbb9fcb
Compare
@kbond finally CI is ok (except scrutinizer, I don't know why, everything look green). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few comments:
- Relation factory's created during
create()
would currently have events called even if disabled by the parent. There are certain scenarios where they would be disabled though (ie if cascade: persist). - The
afterPersist
hook is called with disabled events re-enabled.
Are the above two things intentional or what are your thoughts on these?
If a user has chosen to disable events, I'm wondering if all of create should have events disabled. WDTY?
Just an idea but what do you think of this API: Factory::withoutDoctrineEvents(function() {
PostFactory::createOne(); // events disabled
PostFactory::createOne(); // events disabled
});
PostFactory::createOne(); // events enabled Can't disable on a factory-by-factory basis (ie you couldn't say "I always want this model factory created without events") but could solve some of the inconsistencies detailed above. |
No it was not intentional, I didn't really thought about it. Actually I thought to do it like the I think the functionality is good like that for some reasons:
|
FYI,
Is this what you're referring to?
If we merge as-is, then decide to disable events for the entire create, this would be a BC break. That being said, going from "all create", to just "save" would probably be more troublesome. There is currently an avenue to disable events on sub-factory's: set |
Ah ok I didn't notice, my bad. But when I said that, I thought more about different way to declare it in tests
Yes
Yeah true...
And what do you think about that ? You have a much better vision of this, and where does it go, so if you think it's better to follow the |
I'm a bit torn to be honest, you're right in that we couldn't provide a way to disable just for the primary factory but: PostFactory::new()->withoutDoctrineEvents()->create(); My initial instinct expects all doctrine events to be disabled during "create". |
ok let's do it like that (follow the disable to child factories) |
Let's sit on this for just a bit. I've asked some other foundry contributors to weigh in. |
Ok, yeah, I'm thinking let's disable events for all of create. The solution for allowing sub-factory's to be created with events will be to create them first: $categroy = CategoryFactory::createOne(); // created with events
PostFactory::new()->withoutDoctrineEvents()->create(['category' => $category]); WDYT? |
It's ok for me 👍 |
@kbond sorry it took me times to do it... Don't hesitate to tell me if something is not good for you. |
adf6aff
to
ffbcb02
Compare
@kbond I have a repository for a docker-compose environnement on php8/pgsql/nginx, and i made a specific branch for foundry. Tell me what do you think about it. Feel free to ask me some improvement on it. |
I'm not very familiar with docker but a few comments:
|
No worries and no pressure/rush - we're all doing this in our spare time! The test failures must be related to this PR but I can't see how. I merged a PR a few hours ago that didn't have failures. Maybe a rebase would fix? |
…before creation. (issue zenstruck#215)
…events before creation. (issue zenstruck#215)
…events before creation. (issue zenstruck#215)
…events before creation. (issue zenstruck#215)
ffbcb02
to
54ece31
Compare
I rebased it, but still fail, I don't really understand why... |
yeah true, I will remove nginx for this branch. It is a very simple docker-compose conf, to be able to execute the tests suite. You are right, a perfect configuration would be to have all different kind of database and all different php version handled by your project, but doing such environment will require to create a system to be able to switch between all of that. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small fix.
Since the failing test is happening when running the test suite with dama-doctrine-bundle, I wonder if messing with the events is breaking something. When I have a chance, I'll checkout the code and take a look.
Edit: I think this event is being removed and causing problems. We'll need to somehow only remove ORM events (this might be easier said than done).
src/Factory.php
Outdated
$proxy->save(); | ||
|
||
$proxy->withoutAutoRefresh(function(Proxy $proxy) use ($attributes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$proxy->save(); | |
$proxy->withoutAutoRefresh(function(Proxy $proxy) use ($attributes) { | |
$proxy->save()->withoutAutoRefresh(function(Proxy $proxy) use ($attributes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This don't solve the problem
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't think it would, this was just a minor thing.
…events before creation. (issue zenstruck#215)
hmm yeah I see. Maybe a more reasonable way to handle this functionality is to give explicitly the subscriber or listener to remove. like: |
I agree, while not ideal, I don't see an easy way to distinguish between ORM and DBAL events. |
…events before creation. (issue zenstruck#215)
e93005a
to
f0d96ff
Compare
I'm closing this as stale but do think it's a valid feature. Feel free to reopen! |
feature(doctrine events): allow factories to disable doctrine events before creation. (issue #215)