public function test_that_create_returns_exception_instance()
 {
     $exception = StreamNotFoundException::create('Stream not found');
     $this->assertInstanceOf('Novuso\\Common\\Domain\\EventStore\\Exception\\StreamNotFoundException', $exception);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function loadStream(Identifier $aggregateId, Type $aggregateType, $first = null, $last = null)
 {
     $id = $aggregateId->toString();
     $type = $aggregateType->toString();
     if (!$this->hasStream($aggregateId, $aggregateType)) {
         $message = sprintf('Stream not found for [%s]{%s}', $type, $id);
         throw StreamNotFoundException::create($message);
     }
     $streamData = $this->streamData[$type][$id];
     $count = count($streamData);
     $first = $this->normalizeFirst($first);
     $last = $this->normalizeLast($last, $count);
     $version = $streamData->getVersion();
     $messages = [];
     foreach ($streamData->getEvents() as $storedEvent) {
         $sequence = $storedEvent->getSequence();
         if ($sequence >= $first && $sequence <= $last) {
             $messages[] = $storedEvent->toEventMessage();
         }
     }
     return new DomainEventStream($aggregateId, $aggregateType, $version, $version, $messages);
 }