/** * @test */ public function it_can_mark_new_events_as_processed() { $newEvent = \Phake::mock('LiteCQRS\\DomainEvent'); $uuid = Uuid::uuid4(); $stream = new EventStream('stdClass', $uuid, array()); $stream->addEvent($newEvent); $stream->markNewEventsProcessed(); $this->assertEquals(0, count($stream->newEvents())); }
public function loadFromEventStream(EventStream $eventStream) { if ($this->events) { throw new RuntimeException("AggregateRoot was already created from event stream and cannot be hydrated again."); } $this->setId($eventStream->getUuid()); foreach ($eventStream as $event) { $this->executeEvent($event); } }
/** * Commit the event stream to persistence. * * @return Transaction */ public function commit(EventStream $stream) { $newEvents = $stream->newEvents(); if (count($newEvents) === 0) { return new Transaction($stream, $newEvents); } $id = (string) $stream->getUuid(); $currentVersion = $stream->getVersion(); $nextVersion = $currentVersion + count($newEvents); $eventData = isset($this->eventsData[$id]) ? $this->eventsData[$id] : array(); foreach ($newEvents as $newEvent) { $eventData[] = $this->serializer->toArray($newEvent); } $this->storage->store($id, $stream->getClassName(), $eventData, $nextVersion, $currentVersion); $stream->markNewEventsProcessed($nextVersion); return new Transaction($stream, $newEvents); }
protected function thenStorageContains(EventStream $stream) { $this->assertTrue($this->storage->contains((string) $stream->getUuid())); }
private function givenGameIsCreated(EventStream $eventStream, DiscardPile $discardPile, Player $human, Player $bank) { $eventStream->getUuid()->willReturn(Uuid::uuid1()); $eventStream->getIterator()->willReturn(new \ArrayIterator(array(new GameCreated(array($human->getWrappedObject(), $bank->getWrappedObject()), $discardPile->getWrappedObject(), 2)))); $this->loadFromEventStream($eventStream); }