/**
  * @param EventStreamInterface $eventStream
  * @return void
  * @throws SerializationException
  */
 public function append(EventStreamInterface $eventStream)
 {
     $events = collect(iterator_to_array($eventStream))->map(function ($event) {
         /** @var EventInterface $event */
         return ['aggregate_root_id' => (string) $event->getAggregateRootId(), 'type' => get_class($event), 'payload' => $this->serializer->serialize($event)];
     });
     $this->db->table('events')->insert($events->toArray());
 }
 /**
  * @test
  */
 public function it_appends_events()
 {
     $event = new PointsWereAdded(100);
     $stream = new EventStream($event);
     $eventData = ['aggregate_root_id' => 'BarId', 'type' => PointsWereAdded::class, 'payload' => ['amount' => '100']];
     $this->db->table('events')->willReturn($this->queryBuilder);
     $this->serializer->serialize($event)->willReturn(['amount' => '100']);
     $this->queryBuilder->insert([$eventData])->willReturn(true);
     $this->eventStore->append($stream);
 }