Example #1
0
 /**
  * @param BookAdded $event
  */
 public function onBookAdded(BookAdded $event)
 {
     $authors = array_map(function (AuthorAdded $author) {
         return new Author($author->getFirstName(), $author->getLastName());
     }, $event->getAuthors());
     $this->storage->upsert($event->getId()->getValue(), new Book($event->getId(), new Authors($authors), $event->getTitle(), $event->getISBN(), true, $event->getVersion()));
 }
 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());
 }
Example #3
0
 /**
  * @param BookAdded $event
  */
 protected function applyBookAdded(BookAdded $event)
 {
     $this->id = $event->getId();
 }