Inheritance: implements Prooph\Common\Event\ActionEventListenerAggregate, use trait Prooph\Common\Event\DetachAggregateHandlers
示例#1
0
 /**
  * @test
  * @expectedException \Prooph\ServiceBus\Plugin\Guard\UnauthorizedException
  * @expectedExceptionMessage You are not authorized to access the resource "test_event"
  */
 public function it_stops_propagation_and_throws_unauthorizedexception_when_authorization_service_denies_access_with_deferred_and_exposes_message_name()
 {
     $authorizationService = $this->prophesize(AuthorizationService::class);
     $authorizationService->isGranted('test_event', 'result')->willReturn(false);
     $deferred = new Deferred();
     $deferred->resolve('result');
     $actionEvent = new DefaultActionEvent(QueryBus::EVENT_FINALIZE);
     $actionEvent->setParam(QueryBus::EVENT_PARAM_PROMISE, $deferred->promise());
     $actionEvent->setParam(QueryBus::EVENT_PARAM_MESSAGE_NAME, 'test_event');
     $routeGuard = new FinalizeGuard($authorizationService->reveal(), true);
     $routeGuard->onFinalize($actionEvent);
     $this->assertTrue($actionEvent->propagationIsStopped());
     $actionEvent->getParam(QueryBus::EVENT_PARAM_PROMISE)->done();
 }
示例#2
0
 /**
  * @test
  * @expectedException Prooph\ServiceBus\Plugin\Guard\UnauthorizedException
  */
 public function it_stops_propagation_and_throws_unauthorizedexception_when_authorization_service_denies_access_with_deferred()
 {
     $authorizationService = $this->prophesize(AuthorizationService::class);
     $authorizationService->isGranted('test_event', 'result')->willReturn(false);
     $deferred = new Deferred();
     $deferred->resolve('result');
     $actionEvent = $this->prophesize(ActionEvent::class);
     $actionEvent->getParam('query-deferred')->willReturn($deferred);
     $actionEvent->getParam(MessageBus::EVENT_PARAM_MESSAGE_NAME)->willReturn('test_event');
     $actionEvent->stopPropagation(true)->willReturn(null);
     $routeGuard = new FinalizeGuard($authorizationService->reveal());
     $routeGuard->onFinalize($actionEvent->reveal());
 }