protected function setUp() { $this->eventStore = new EventStore(new InMemoryEventStorage(), new NullBus(), new InMemoryIdentityMap()); $this->repository = new CustomerRepository($this->eventStore); $this->commandBus = new SymfonyEventDispatcherBus(new EventDispatcher()); $this->commandBus->subscribe(new CreateCustomerCommandHandler($this->repository)); $this->commandBus->subscribe(new ChangeCustomerNameCommandHandler($this->repository)); }
/** * {@inheritdoc} */ public function commit() { if ($this->eventStorage instanceof TransactionalInterface) { $this->eventStorage->beginTransaction(); } foreach ($this->identityMap as $eventStream) { $this->eventStorage->saveUncommittedEventStream($eventStream); $this->eventBus->publish(new MessageStream($eventStream)); } if ($this->eventStorage instanceof TransactionalInterface) { $this->eventStorage->commit(); } $this->eventBus->commit(); $this->identityMap->clear(); }