コード例 #1
0
 /**
  * @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()));
 }
コード例 #2
0
 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);
     }
 }
コード例 #3
0
 /**
  * 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);
 }
コード例 #4
0
 protected function thenStorageContains(EventStream $stream)
 {
     $this->assertTrue($this->storage->contains((string) $stream->getUuid()));
 }
コード例 #5
0
 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);
 }