public function testCanNotifyCommitPreparationToListeners() { $unitOfWork = $this->unitOfWorkMock(); $this->listener1->expects($this->once())->method('onPrepareCommit')->with($this->identicalTo($unitOfWork), [], []); $this->listener2->expects($this->once())->method('onPrepareCommit')->with($this->identicalTo($unitOfWork), [], []); $this->listeners->onPrepareCommit($unitOfWork, [], []); }
public function commit() { $this->assertHasStarted(); try { $this->listeners->onPrepareCommit($this, $this->registeredAggregates->all(), $this->stagingEvents->all()); $this->registeredAggregates->saveAggregateRoots(); $this->stagingEvents->publishEvents(); $this->commitTransaction(); $this->listeners->afterCommit($this); } catch (\RuntimeException $exception) { $this->rollback($exception); throw $exception; } finally { $this->stop(); $this->listeners->onCleanup($this); } }
public function commit() { if (!$this->hasStarted()) { throw new \Exception('The unit of work has not been started.'); } try { $this->listeners->onPrepareCommit($this, $this->registeredAggregates->all(), $this->stagingEvents->all()); $this->registeredAggregates->saveAggregateRoots(); $this->stagingEvents->publishEvents(); if ($this->isTransactional()) { $this->listeners->onPrepareTransactionCommit($this); $this->transactionManager->commitTransaction(); } $this->listeners->afterCommit($this); } catch (\Exception $exception) { $this->rollback($exception); throw $exception; } finally { $this->stop(); $this->listeners->onCleanup($this); } }