/** * @test */ public function playPublishesEachEvent() { $eventBus = $this->getMockBuilder(EventBus::class)->getMockForAbstractClass(); $events = new Events([new EventPlayerTest_Event(), new EventPlayerTest_Event()]); $eventBus->expects(self::exactly($events->size()))->method('publish'); $eventPlayer = new EventPlayer($eventBus); $eventPlayer->play($events); }
/** * @param Events $history */ public function loadFromHistory(Events $history) { if ($history->size() == 0) { return; } foreach ($history->getIterator() as $event) { $this->internalApplyChange($event, false); } $historyCopy = $history->getArrayCopy(); /* @var $lastEvent Event */ $lastEvent = end($historyCopy); $this->version = $lastEvent->getVersion(); }
/** * @test */ public function saveEventsForAggregateAppendsEventsToStorageForExistingAggregate() { $eventBus = $this->getEventBus(); $storage = $this->getEventStorage(); $serializer = $this->getSerializer(); $eventMap = $this->getEventMap(); $aggregateId = Identity::createNew(); $events = new Events([new EventStoreTest_Event1(), new EventStoreTest_Event2()]); $descriptors = [EventDescriptor::reconstructFromArray(['identity' => $aggregateId->getValue(), 'type' => 'aggregateType', 'event' => EventStoreTest_Event1::getName(), 'payload' => '{}', 'playHead' => 1, 'recorded' => date('r')])]; $storage->expects(self::once())->method('find')->with($aggregateId->getValue())->willReturn($descriptors); $storage->expects(self::exactly($events->size()))->method('append'); $serializer->expects(self::exactly($events->size()))->method('serialize')->willReturn('{}'); $eventStore = new EventStore($eventBus, $storage, $serializer, $eventMap); $eventStore->save($aggregateId, 'type', $events, 1); }