/**
* @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);
}