-
Notifications
You must be signed in to change notification settings - Fork 55
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
Finalize trigger enables propagation if it was stopped #184
Conversation
Please give me 2 hours to evaluate another test case that came to my mind. |
If I understand the logic of the finalize event correct, It's listeners should be always called. This would not be the case if the propagation is stopped but no exception has been thrown, only the first finalize listener is called: /**
* @test
*/
public function it_always_triggers_finalize_listeners_regardless_whether_the_propagation_of_the_event_has_been_stopped(): void
{
$messageBus = new CommandBus();
$messageBus->attach(CommandBus::EVENT_DISPATCH, function (ActionEvent $event) {
$event->setParam(CommandBus::EVENT_PARAM_MESSAGE_HANDLER, function () {
});
}, CommandBus::PRIORITY_LOCATE_HANDLER+1);
$messageBus->attach(CommandBus::EVENT_DISPATCH, function (ActionEvent $event) {
$event->stopPropagation();
}, CommandBus::PRIORITY_INVOKE_HANDLER-1);
$messageBus->attach(MessageBus::EVENT_FINALIZE, function () {
}, 3);
$finalizeHasBeenCalled = false;
$messageBus->attach(MessageBus::EVENT_FINALIZE, function () use (&$finalizeHasBeenCalled) {
$finalizeHasBeenCalled = true;
}, 2);
$messageBus->dispatch('a message');
self::assertTrue($finalizeHasBeenCalled);
} If my assumption is correct, additional tests for the CommandBus, EventBus and QueryBus are necessary and the protected function triggerFinalize(ActionEvent $actionEvent): void
{
$actionEvent->setName(self::EVENT_FINALIZE);
$actionEvent->stopPropagation(false);
$this->events->dispatch($actionEvent);
} |
@UFOMelkor I added further tests |
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.
In my understanding the tests must not fail without these three exceptions (and currently they would fail).
tests/QueryBusTest.php
Outdated
}, QueryBus::PRIORITY_LOCATE_HANDLER + 1); | ||
$this->queryBus->attach(QueryBus::EVENT_DISPATCH, function (ActionEvent $event): void { | ||
$event->stopPropagation(); | ||
throw new \RuntimeException('boom'); |
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.
3
tests/EventBusTest.php
Outdated
}, EventBus::PRIORITY_LOCATE_HANDLER + 1); | ||
$this->eventBus->attach(EventBus::EVENT_DISPATCH, function (ActionEvent $event): void { | ||
$event->stopPropagation(); | ||
throw new \RuntimeException('boom'); |
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.
2
tests/CommandBusTest.php
Outdated
}, CommandBus::PRIORITY_LOCATE_HANDLER + 1); | ||
$this->commandBus->attach(CommandBus::EVENT_DISPATCH, function (ActionEvent $event): void { | ||
$event->stopPropagation(); | ||
throw new \RuntimeException('boom'); |
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.
1
@UFOMelkor You're right, fixed! |
LGTM 👍 |
superseeds #183
/cc @UFOMelkor