From a216ac08ee4d126913b5427060e88d975afc97fe Mon Sep 17 00:00:00 2001 From: prolic Date: Tue, 26 Dec 2017 18:11:01 +0800 Subject: [PATCH 1/2] fix FinalizeGuard resolves https://github.com/prooph/service-bus/issues/177 --- src/Plugin/Guard/FinalizeGuard.php | 5 +++-- tests/Plugin/Guard/FinalizeGuardTest.php | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Plugin/Guard/FinalizeGuard.php b/src/Plugin/Guard/FinalizeGuard.php index daf75e3..bb47f52 100644 --- a/src/Plugin/Guard/FinalizeGuard.php +++ b/src/Plugin/Guard/FinalizeGuard.php @@ -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); @@ -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); diff --git a/tests/Plugin/Guard/FinalizeGuardTest.php b/tests/Plugin/Guard/FinalizeGuardTest.php index 61eaeed..0e0a807 100644 --- a/tests/Plugin/Guard/FinalizeGuardTest.php +++ b/tests/Plugin/Guard/FinalizeGuardTest.php @@ -20,7 +20,9 @@ use Prooph\ServiceBus\Plugin\Guard\AuthorizationService; use Prooph\ServiceBus\Plugin\Guard\FinalizeGuard; use Prooph\ServiceBus\Plugin\Guard\UnauthorizedException; +use Prooph\ServiceBus\Plugin\Router\QueryRouter; use Prooph\ServiceBus\QueryBus; +use React\Promise\Deferred; class FinalizeGuardTest extends TestCase { @@ -72,7 +74,10 @@ function (ActionEvent $actionEvent): void { ); $promise = $this->messageBus->dispatch('test_event'); - $promise->done(); + $promise->done(function ($result) { + $this->assertNotNull($result); + $this->assertEquals('result', $result); + }); } /** From 9c1f69d2a71d528b6557270929694ac06ee03d67 Mon Sep 17 00:00:00 2001 From: prolic Date: Tue, 26 Dec 2017 18:25:09 +0800 Subject: [PATCH 2/2] apply php cs fixes --- tests/Plugin/Guard/FinalizeGuardTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/Plugin/Guard/FinalizeGuardTest.php b/tests/Plugin/Guard/FinalizeGuardTest.php index 0e0a807..5a16f41 100644 --- a/tests/Plugin/Guard/FinalizeGuardTest.php +++ b/tests/Plugin/Guard/FinalizeGuardTest.php @@ -20,9 +20,7 @@ use Prooph\ServiceBus\Plugin\Guard\AuthorizationService; use Prooph\ServiceBus\Plugin\Guard\FinalizeGuard; use Prooph\ServiceBus\Plugin\Guard\UnauthorizedException; -use Prooph\ServiceBus\Plugin\Router\QueryRouter; use Prooph\ServiceBus\QueryBus; -use React\Promise\Deferred; class FinalizeGuardTest extends TestCase {