Beispiel #1
0
 /**
  * @param string $identity
  * @return EventDescriptor[]
  */
 public function find(string $identity) : array
 {
     $cursor = $this->collection->find([$this->identityField => $identity]);
     return array_map(function (BSONDocument $eventData) : EventDescriptor {
         return EventDescriptor::reconstructFromArray($eventData->getArrayCopy());
     }, $cursor->toArray());
 }
Beispiel #2
0
 /**
  * @param string $identity
  * @return EventDescriptor[]
  */
 public function find(string $identity) : array
 {
     if (!$this->contains($identity)) {
         return [];
     }
     return array_map(function (array $event) : EventDescriptor {
         return EventDescriptor::reconstructFromArray($event);
     }, $this->data[$identity]);
 }
Beispiel #3
0
 /**
  * @test
  */
 public function getEventsForAggregateRetrievesEventLog()
 {
     $eventBus = $this->getEventBus();
     $storage = $this->getEventStorage();
     $serializer = $this->getSerializer();
     $eventMap = $this->getEventMap();
     $aggregateId = Identity::createNew();
     $descriptors = [EventDescriptor::reconstructFromArray(['identity' => $aggregateId->getValue(), 'type' => 'aggregateType', 'event' => EventStoreTest_Event1::getName(), 'payload' => '{}', 'playHead' => 1, 'recorded' => date('r')]), EventDescriptor::reconstructFromArray(['identity' => $aggregateId->getValue(), 'type' => 'aggregateType', 'event' => EventStoreTest_Event2::getName(), 'payload' => '{}', 'playHead' => 2, 'recorded' => date('r')])];
     $eventMap->expects(self::exactly(count($descriptors)))->method('getClassByEventName')->willReturnOnConsecutiveCalls(EventStoreTest_Event1::class, EventStoreTest_Event2::class);
     $storage->expects(self::once())->method('contains')->willReturn(true);
     $storage->expects(self::once())->method('find')->with($aggregateId->getValue())->willReturn($descriptors);
     $serializer->expects(self::exactly(count($descriptors)))->method('deserialize')->willReturnOnConsecutiveCalls(new EventStoreTest_Event1(), new EventStoreTest_Event2());
     $eventStore = new EventStore($eventBus, $storage, $serializer, $eventMap);
     $events = $eventStore->getEventsForAggregate($aggregateId);
     self::assertCount(count($descriptors), $events->getIterator());
 }