Closed GeorgeInteli closed 8 months ago
@GeorgeInteli Hello. All events are sent when a transaction is committed. Add a check to your transaction level test, it must be 0 for the event to be sent.
I'm sure the test will fail, because... pest starts a transaction before the test starts and ends it after the test ends.
You need to call commit yourself before checking.
Hello @rez1dent3 , I can confirm that even on transaction level 0 the events are not dispaching.
It was level 1 inside pest, it is going to level 0 after commit, but the test still fails. The most confusing thing about all this is that balanceInt
is actually being updated, but the event is not fired.
Note that even if the events did fire i dont think reverting or commiting something outside the scope of the function is a solution. I am sure this was discussed before. Any best practices or solutions you might recommend? And what is the reasoning behind transaction level 0. I see it hard coded inside TransactionCommittedListener.php
(i read #412 and #455)
@GeorgeInteli The laravel architecture is such that if there is no listener, then the event is not sent.
Here you can see the tests of the package: https://github.com/bavix/laravel-wallet/blob/e8c70cc385319a2119fd1c4e2426ec1dddefff56/tests/Units/Domain/EventTest.php#L73-L88
https://github.com/bavix/laravel-wallet/blob/master/tests/Units/Domain/EventTest.php
And what is the reasoning behind transaction level 0
The transaction can be canceled and the event sent.
I checked locally again. Events are sent. Need more data.
@GeorgeInteli I didn't notice at first, but you're testing the implementation, not the interface. You need to check the contract itself, the trigger for it.
Hmmm i got nothing. Not seeing the event at all inside the dispatcher events stack.
I am seeing however our own Laravel defined events. There is something specific to this package events.
As I already wrote above, you need to determine the listener.
@GeorgeInteli Hello. I took some time and started debugging. The flush method is not implemented for Fake in laravel. You will not be able to implement your check.
Thank you @rez1dent3 Now we know what the issue is :) We will just have incomplete test for the moment.
@GeorgeInteli You can use it in a similar way to the tests in the package itself. Those,
this will give you the ability to write tests.
Look at the tests in the project: https://github.com/bavix/laravel-wallet/blob/master/tests/Units/Domain/EventTest.php
Describe the bug The events from the package are not dispatching.
To Reproduce Steps to reproduce the behavior:
Expected behavior After a deposit I expect to receive event on Balance change and Transaction created.
Screenshots Here is sample test
Server: