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);
     }
 }
 /**
  * @depends testCanPublishEachEventThroughTheEventBusItWasRegisteredWith
  */
 public function testShouldBeClearedAfterEventsWerePublished(StagingEventContainer $container)
 {
     $this->assertEmpty($container->all());
 }