-
Notifications
You must be signed in to change notification settings - Fork 28
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
Add DatabaseTransactions trait for transactional events #28
Conversation
Hey, as far as I understand you need this. That's what we use in our project in order to normally dispatch events if we assert them.
|
Yeah, isn't that the same code as in my PR? 😄 |
@mfn sry, i obviously missed that this was a PR instead of an issue. Sorry for that. But I can confirm this code works :D for better clarity I would name the trait |
But that's not what the trait does 🤔 It actually is there to handle them, because otherwise you use the vanilla trait then they won't work. |
Hello @mfn, TL;DR: The
The You just need to use the custom trait provided by this package if you're running a Laravel version that does not have my fix applied. (This fix is available since Laravel 5.6.16) The thing is that every transaction used for keeping the database clean fires events that interfer with the behavior of this package. Concretely, as each test runs under a transaction managed by utility traits and the application-specific transactional events are actually dispatched only after the root transaction commits, the expected events are never dispatched because the root transaction (managed by utility traits) rolls back in the end. |
I can't use As such, I can only use But the vanilla one does not work with this package and I needed the same adjustments for that trait as this package has in Is it maybe because your past PR https://github.com/laravel/framework/pull/23832/files#diff-13ccf3cc47ede3e4128a008b8547ade0R70 only targeted |
Humm, I see. Ok, I will approve this as a temporary fix for people who use Thank you for your PR! Next week I will release a new version, also ready for Laravel 6. |
In my test suite I'm not using
RefreshDatabase
butDatabaseTransactions
.The reason is that I've a custom system in place which primes the database once before all tests are run and not for every tests. Because I can't use sqlite but the actual DB driver, this is much more faster.
With this trait I can replace the vanilla one and transactional events and their effect can be tested like anything else.
Mildly related question
I've a question regarding https://github.com/fntneves/laravel-transactional-events#known-issues though: I re-read the paragraph multiple times but TBH, it's not clear whether this packages
RefreshDatabase
is basically required to be used or not.I saw that you landed laravel/framework#23832 some time ago but this package actually does not use any of this:
(I can't test this, not using it)
unsetEventDispatcher
is also not used anywhereCan you clarify: if it recommended/required to use this package
RefreshDatabase
trait?If so, I think the README could be clarified and also if this PR gets accepted, this should be added too (willing to do in this PR once this is cleared up for me).
If not so, then I don't understand why it exists :-)
I certainly needed this modified
DatabaseTransactions
otherwise the actual transactional events where never dispatched in tests.