Author: Alexander Miertsch (kontakt@codeliner.ws)
Inheritance: implements Prooph\ServiceBus\Plugin\Router\MessageBusRouterPlugin, implements Prooph\Common\Event\ActionEventListenerAggregate, use trait Prooph\Common\Event\DetachAggregateHandlers
 /**
  * @test
  */
 public function it_confirms_select_one_action_event_after_the_other()
 {
     $actionEvent = $this->prophesize(ActionEvent::class);
     $iterator = new \ArrayIterator(['foo', 'bar']);
     $actionEvent->getParam('recordedEvents', new \ArrayIterator())->willReturn($iterator)->shouldBeCalled();
     $producer = $this->prophesize(Producer::class);
     $producer->startTransaction()->shouldBeCalledTimes(2);
     $producer->commitTransaction()->shouldBeCalledTimes(2);
     $eventBus = new EventBus();
     $plugin = new TransactionalEventPublisher($eventBus, $producer->reveal());
     $eventBusCalls = [];
     $eventRouter = new EventRouter();
     $eventRouter->route('foo')->to(function ($event) use($plugin, &$eventBusCalls) {
         $eventBusCalls[] = $event;
         $actionEvent = new DefaultActionEvent($event, null, ['recordedEvents' => new \ArrayIterator(['baz', 'bam', 'bat'])]);
         $plugin->onEventStoreCommitPost($actionEvent);
     });
     $eventRouter->route('bar')->to(function ($event) use(&$eventBusCalls) {
         $eventBusCalls[] = $event;
     });
     $eventRouter->route('baz')->to(function ($event) use(&$eventBusCalls) {
         $eventBusCalls[] = $event;
     });
     $eventRouter->route('bam')->to(function ($event) use(&$eventBusCalls) {
         $eventBusCalls[] = $event;
     });
     $eventRouter->route('bat')->to(function ($event) use(&$eventBusCalls) {
         $eventBusCalls[] = $event;
     });
     $eventBus->utilize($eventRouter);
     $plugin->onEventStoreCommitPost($actionEvent->reveal());
     $this->assertEquals(['foo', 'bar', 'baz', 'bam', 'bat'], $eventBusCalls);
 }
Example #2
0
 /**
  * @test
  */
 public function it_returns_early_on_route_event_when_message_name_is_not_in_event_map()
 {
     $router = new EventRouter(['SomethingDone' => ['SomethingDoneListener1', 'SomethingDoneListener2']]);
     $actionEvent = new DefaultActionEvent(MessageBus::EVENT_ROUTE, new EventBus(), [MessageBus::EVENT_PARAM_MESSAGE_NAME => 'unknown']);
     $router->onRouteMessage($actionEvent);
     $listeners = $actionEvent->getParam(EventBus::EVENT_PARAM_EVENT_LISTENERS);
     $this->assertEmpty($listeners);
 }