public function testFindIdentitiesWillReturnAllIds()
 {
     $collection = $this->getCollection();
     $collection->expects(self::once())->method('distinct')->will(self::returnValue(new ArrayIterator(['a'])));
     $storage = new MongoDbEventStorage($collection, 'identity');
     $storage->append(EventDescriptor::record('a', 'foo', 'bar', 1));
     self::assertEquals(['a'], $storage->findIdentities());
 }
 /**
  * @param string $identity
  * @return EventDescriptor[]
  */
 public function find($identity)
 {
     if (!$this->contains($identity)) {
         return [];
     }
     return array_map(function (array $eventData) {
         return EventDescriptor::reconstructFromArray($eventData);
     }, $this->data[$identity]);
 }
 /**
  * @param EventDescriptor $event
  * @return boolean
  */
 public function append(EventDescriptor $event)
 {
     $eventData = $event->toArray();
     $result = $this->collection->insert($eventData);
     return $result !== false;
 }
 public function testGetEventsForAggregateWillReturnEvents()
 {
     $id = Uuid::createNew();
     $eventBus = $this->getEventBus();
     $storage = $this->getStorage();
     $serializer = $this->getSerializer();
     $classMap = $this->getEventClassMap();
     $event = new BookAdded($id, [], 'foo', 'bar');
     $classMap->expects(self::any())->method('getClassByEventName')->with($event->getEventName())->will(self::returnValue(get_class($event)));
     $serializer->expects(self::any())->method('serialize')->will(self::returnValue(json_encode(['id' => $event->getId(), 'title' => $event->getTitle()])));
     $serializer->expects(self::any())->method('deserialize')->will(self::returnValue($event));
     $eventStructure = EventDescriptor::reconstructFromArray(['identity' => $id->getValue(), 'event' => $event->getEventName(), 'playhead' => $event->getVersion(), 'payload' => $serializer->serialize($event, 'json'), 'recorded' => date('r')]);
     $storage->expects(self::any())->method('contains')->with($id->getValue())->will(self::returnValue(true));
     $storage->expects(self::once())->method('find')->with($id->getValue())->will(self::returnValue([$eventStructure]));
     $store = new EventStore($eventBus, $storage, $serializer, $classMap);
     $events = $store->getEventsForAggregate($id);
     self::assertInstanceOf(Events::class, $events);
     self::assertCount(1, $events->getIterator());
 }
Beispiel #5
0
 /**
  * @param Uuid $aggregateId
  * @param Event $event
  */
 private function saveEvent(Uuid $aggregateId, Event $event)
 {
     $eventData = EventDescriptor::record($aggregateId->getValue(), $event->getEventName(), $this->serializer->serialize($event, 'json'), $event->getVersion());
     $this->storage->append($eventData);
 }
 public function testFindIdentitiesWillReturnAllIds()
 {
     $storage = new MemoryEventStorage();
     $storage->append(EventDescriptor::record('a', 'foo', 'bar', 1));
     self::assertEquals(['a'], $storage->findIdentities());
 }