public function it_passes_queued_commands_to_command_dispatch_exception_in_case_of_an_error()
{
$messageHandler = new MessageHandler();
$this->commandBus->utilize((new CommandRouter())->route(CustomMessage::class)->to($messageHandler)->route('initial message')->to(function () use($messageHandler) {
$delayedMessage = new CustomMessage("delayed message");
$this->commandBus->dispatch($delayedMessage);
throw new \Exception("Ka Boom");
}));
$commandDispatchException = null;
try {
$this->commandBus->dispatch('initial message');
} catch (CommandDispatchException $ex) {
$commandDispatchException = $ex;
}
$this->assertInstanceOf(CommandDispatchException::class, $commandDispatchException);
$this->assertSame(1, count($commandDispatchException->getPendingCommands()));
$this->assertSame(CustomMessage::class, get_class($commandDispatchException->getPendingCommands()[0]));
}