コード例 #1
0
 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());
 }
コード例 #2
0
 /**
  * @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]);
 }
コード例 #3
0
 /**
  * @param EventDescriptor $event
  * @return boolean
  */
 public function append(EventDescriptor $event)
 {
     $eventData = $event->toArray();
     $result = $this->collection->insert($eventData);
     return $result !== false;
 }
コード例 #4
0
 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());
 }
コード例 #5
0
ファイル: EventStore.php プロジェクト: EightArmCode/librarian
 /**
  * @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);
 }
コード例 #6
0
 public function testFindIdentitiesWillReturnAllIds()
 {
     $storage = new MemoryEventStorage();
     $storage->append(EventDescriptor::record('a', 'foo', 'bar', 1));
     self::assertEquals(['a'], $storage->findIdentities());
 }