/** * @param Identity $aggregateId * @return Events * @throws AggregateNotFoundException */ public function getEventsForAggregate(Identity $aggregateId) : Events { if (!$this->storage->contains($aggregateId->getValue())) { throw new AggregateNotFoundException($aggregateId); } $eventData = $this->storage->find($aggregateId->getValue()); $events = array_map(function (EventDescriptor $data) : Event { return $this->serializer->deserialize($data->getPayload(), $this->eventMap->getClassByEventName($data->getEvent())); }, $eventData); return new Events($events); }
/** * @test * @expectedException \OutOfBoundsException */ public function getClassByNameThrowsExceptionIfEventNotInMap() { $map = new EventClassMap([]); $map->getClassByEventName('foo'); }