/** * @param AggregateRoot $aggregateRoot * @param int $expectedPlayHead * @return void * @throws ConcurrencyException */ public function store(AggregateRoot $aggregateRoot, int $expectedPlayHead = -1) { $this->eventStore->save($aggregateRoot->getId(), $this->factory->getAggregateType(), $aggregateRoot->getUncommittedChanges(), $expectedPlayHead); $aggregateRoot->markChangesCommitted(); }
/** * @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); }