/**
  * Commit the event stream to persistence.
  *
  * @return Transaction
  */
 public function commit(EventStream $stream)
 {
     $newEvents = $stream->newEvents();
     if (count($newEvents) === 0) {
         return new Transaction($stream, $newEvents);
     }
     $id = (string) $stream->getUuid();
     $currentVersion = $stream->getVersion();
     $nextVersion = $currentVersion + count($newEvents);
     $eventData = isset($this->eventsData[$id]) ? $this->eventsData[$id] : array();
     foreach ($newEvents as $newEvent) {
         $eventData[] = $this->serializer->toArray($newEvent);
     }
     $this->storage->store($id, $stream->getClassName(), $eventData, $nextVersion, $currentVersion);
     $stream->markNewEventsProcessed($nextVersion);
     return new Transaction($stream, $newEvents);
 }
 protected function givenEventStoreContains(EventStore $eventStore, EventStream $eventStream)
 {
     $this->storage->store((string) $eventStream->getUuid(), $eventStream->getClassName(), array_map(array($this->serializer, 'toArray'), iterator_to_array($eventStream)), $eventStream->getVersion(), null);
 }