route() public method

public route ( string $eventName )
$eventName string
 /**
  * @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);
 }
Esempio n. 2
0
 /**
  * @test
  */
 public function it_can_route_a_second_event_after_the_first_one_is_routed_to_at_least_one_listener()
 {
     $router = new EventRouter();
     $router->route('SomethingDone')->to('a_listener');
     $router->route('AnotherEvent');
     //no exception occurred
     $this->assertTrue(true);
 }