$middleware =
new DispatchAfterCurrentBusMiddleware();
$handlingMiddleware =
$this->
createMock(MiddlewareInterface::
class);
$eventBus =
new MessageBus([ $middleware,
$handlingMiddleware,
]);
$messageBus =
new MessageBus([ $middleware,
new DispatchingMiddleware($eventBus,
[ new Envelope($firstEvent,
[new DispatchAfterCurrentBusStamp()]),
new Envelope($secondEvent,
[new DispatchAfterCurrentBusStamp()]),
$thirdEvent, // Not in a new transaction
]),
$handlingMiddleware,
]);
$series =
[ // Third event is dispatch within main dispatch, but before its handling:
$thirdEvent,
// Then expect main dispatched message to be handled first:
$message,