Skip to content

Commit

Permalink
Merge pull request #178 from prooph/finalize_guard
Browse files Browse the repository at this point in the history
fix FinalizeGuard
  • Loading branch information
prolic authored Dec 26, 2017
2 parents c239acf + 9c1f69d commit fd83b41
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/Plugin/Guard/FinalizeGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function (ActionEvent $actionEvent): void {
$messageName = $actionEvent->getParam(MessageBus::EVENT_PARAM_MESSAGE_NAME);

if ($promise instanceof Promise) {
$newPromise = $promise->then(function ($result) use ($actionEvent, $messageName): void {
$newPromise = $promise->then(function ($result) use ($actionEvent, $messageName) {
if (! $this->authorizationService->isGranted($messageName, $result)) {
$actionEvent->stopPropagation(true);

Expand All @@ -55,8 +55,9 @@ function (ActionEvent $actionEvent): void {

throw new UnauthorizedException($messageName);
}
});

return $result;
});
$actionEvent->setParam(QueryBus::EVENT_PARAM_PROMISE, $newPromise);
} elseif (! $this->authorizationService->isGranted($messageName)) {
$actionEvent->stopPropagation(true);
Expand Down
5 changes: 4 additions & 1 deletion tests/Plugin/Guard/FinalizeGuardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ function (ActionEvent $actionEvent): void {
);

$promise = $this->messageBus->dispatch('test_event');
$promise->done();
$promise->done(function ($result) {
$this->assertNotNull($result);
$this->assertEquals('result', $result);
});
}

/**
Expand Down

0 comments on commit fd83b41

Please sign in to comment.