/** * @test */ public function it_invokes_a_finder_which_has_method_named_like_the_query() { $finder = new Finder(); $this->actionEvent->setParam(QueryBus::EVENT_PARAM_MESSAGE_HANDLER, $finder); $invokeStrategy = $this->finderInvokeStrategy; $invokeStrategy($this->actionEvent); $this->assertSame($this->actionEvent->getParam(QueryBus::EVENT_PARAM_MESSAGE), $finder->getLastMessage()); $this->assertSame($this->actionEvent->getParam(QueryBus::EVENT_PARAM_DEFERRED), $finder->getLastDeferred()); }
/** * @test */ public function it_will_skip_handling_success_if_exception_exists_on_event() { $this->logger->info(Argument::any())->shouldNotBeCalled(); $event = new DefaultActionEvent('test'); $event->setParam(MessageBus::EVENT_PARAM_EXCEPTION, new \Exception()); $this->SUT->onFinalizeCommand($event); }
/** * @test */ public function it_returns_early_if_command_was_null_when_handling_events() { //Step 1: Create null command $command = null; $initializeActionEvent = $this->prophesize(ActionEvent::class); $initializeActionEvent->getParam(CommandBus::EVENT_PARAM_MESSAGE)->willReturn($command); $eventStoreMock = $this->getEventStoreObjectProphecy(); $eventStoreMock->beginTransaction()->shouldBeCalled(); $transactionManager = new TransactionManager(); $transactionManager->setUp($eventStoreMock->reveal()); $transactionManager->onInvokeHandler($initializeActionEvent->reveal()); $recordedEvent = $this->prophesize(Message::class); $recordedEvent->withAddedMetadata('causation_id', Argument::any())->shouldNotBeCalled(); $stream = new Stream(new StreamName('event_stream'), new \ArrayIterator([$recordedEvent->reveal()])); $createStreamActionEvent = new DefaultActionEvent('test'); $createStreamActionEvent->setParam('stream', $stream); $transactionManager->onEventStoreCreateStream($createStreamActionEvent); $this->assertEquals($stream, $createStreamActionEvent->getParam('stream')); }
/** * @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(); }