public function testCanNotifyCleanupToListeners() { $unitOfWork = $this->unitOfWorkMock(); // Todo: We should test that the listeners are triggered in the reversed order of registering. $this->listener1->expects($this->once())->method('onCleanup')->with($this->identicalTo($unitOfWork)); $this->listener2->expects($this->once())->method('onCleanup')->with($this->identicalTo($unitOfWork)); $this->listeners->onCleanup($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); } }