/**
  * @param AggregateId $id
  * @return EventStream
  */
 private function createEventStream(AggregateId $id)
 {
     $envelope1 = EventEnvelope::envelop(EventId::fromString('event-1'), 'event_1', \Mockery::mock('SimpleES\\EventSourcing\\Event\\DomainEvent'), $id, 0);
     $envelope2 = EventEnvelope::envelop(EventId::fromString('event-2'), 'event_2', \Mockery::mock('SimpleES\\EventSourcing\\Event\\DomainEvent'), $id, 1);
     $envelope3 = EventEnvelope::envelop(EventId::fromString('event-3'), 'event_3', \Mockery::mock('SimpleES\\EventSourcing\\Event\\DomainEvent'), $id, 2);
     return new EventStream($id, [$envelope1, $envelope2, $envelope3]);
 }
 public function setUp()
 {
     $aggregateId = AggregateId::fromString('some-id');
     $eventId = EventId::fromString('some-id');
     $this->event = \Mockery::mock('SimpleES\\EventSourcing\\Event\\DomainEvent');
     $this->envelope = EventEnvelope::envelop($eventId, 'some_name', $this->event, $aggregateId, 123);
 }
 /**
  * {@inheritdoc}
  */
 public function read(Identifies $aggregateId)
 {
     $statement = $this->prepareSelectStatement();
     $statement->bindValue('aggregate_id', (string) $aggregateId, Type::GUID);
     $statement->execute();
     $envelopes = [];
     while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
         $eventName = $row['event_name'];
         $eventClass = $this->eventNameResolver->resolveEventClass($eventName);
         $event = $this->serializer->deserialize($row['event_payload'], $eventClass);
         $metadata = $this->serializer->deserialize($row['metadata'], 'SimpleES\\EventSourcing\\Metadata\\Metadata');
         $envelopes[] = EventEnvelope::fromStore(EventId::fromString($row['event_id']), $eventName, $event, $aggregateId, (int) $row['aggregate_version'], Timestamp::fromString($row['took_place_at']), $metadata);
     }
     if (!$envelopes) {
         throw AggregateIdNotFound::create($aggregateId);
     }
     return new EventStream($aggregateId, $envelopes);
 }
 /**
  * @param Identifies $aggregateId
  *
  * @return EventStream
  */
 private function createEventStream(Identifies $aggregateId)
 {
     $envelope1 = Mockery::mock('SimpleES\\EventSourcing\\Event\\Stream\\EnvelopsEvent');
     $envelope1->shouldReceive('eventId')->andReturn(EventId::fromString('event-1'));
     $envelope1->shouldReceive('eventName')->andReturn('an_event_happened');
     $envelope1->shouldReceive('event')->andReturn(Mockery::mock('SimpleES\\EventSourcing\\Event\\DomainEvent'));
     $envelope1->shouldReceive('aggregateId')->andReturn($aggregateId);
     $envelope1->shouldReceive('aggregateVersion')->andReturn(0);
     $envelope1->shouldReceive('tookPlaceAt')->andReturn(Timestamp::now());
     $envelope1->shouldReceive('metadata')->andReturn(new Metadata([]));
     $envelope2 = Mockery::mock('SimpleES\\EventSourcing\\Event\\Stream\\EnvelopsEvent');
     $envelope2->shouldReceive('eventId')->andReturn(EventId::fromString('event-2'));
     $envelope2->shouldReceive('eventName')->andReturn('another_event_happened');
     $envelope2->shouldReceive('event')->andReturn(Mockery::mock('SimpleES\\EventSourcing\\Event\\DomainEvent'));
     $envelope2->shouldReceive('aggregateId')->andReturn($aggregateId);
     $envelope2->shouldReceive('aggregateVersion')->andReturn(1);
     $envelope2->shouldReceive('tookPlaceAt')->andReturn(Timestamp::now());
     $envelope2->shouldReceive('metadata')->andReturn(new Metadata([]));
     $envelope3 = Mockery::mock('SimpleES\\EventSourcing\\Event\\Stream\\EnvelopsEvent');
     $envelope3->shouldReceive('eventId')->andReturn(EventId::fromString('event-3'));
     $envelope3->shouldReceive('eventName')->andReturn('yet_another_event_happened');
     $envelope3->shouldReceive('event')->andReturn(Mockery::mock('SimpleES\\EventSourcing\\Event\\DomainEvent'));
     $envelope3->shouldReceive('aggregateId')->andReturn($aggregateId);
     $envelope3->shouldReceive('aggregateVersion')->andReturn(2);
     $envelope3->shouldReceive('tookPlaceAt')->andReturn(Timestamp::now());
     $envelope3->shouldReceive('metadata')->andReturn(new Metadata([]));
     $eventStream = new EventStream($aggregateId, [$envelope1, $envelope2, $envelope3]);
     return $eventStream;
 }
 /**
  * @test
  */
 public function itExposesAnEventId()
 {
     $id = EventId::fromString('some-id');
     $exposedId = $this->envelope->eventId();
     $this->assertTrue($id->equals($exposedId));
 }
 /**
  * @param Identifies $aggregateId
  *
  * @return EventStream
  */
 private function createEventStream(Identifies $aggregateId)
 {
     $envelope1 = EventEnvelope::envelop(EventId::fromString('246cc06b-c60f-40da-ab58-ef7b5502eb74'), 'an_event_happened', Mockery::mock('SimpleES\\EventSourcing\\Event\\DomainEvent'), $aggregateId, 0);
     $envelope2 = EventEnvelope::envelop(EventId::fromString('4b4806a5-a99f-425f-b83e-ed49621d29d3'), 'another_event_happened', Mockery::mock('SimpleES\\EventSourcing\\Event\\DomainEvent'), $aggregateId, 1);
     $envelope3 = EventEnvelope::envelop(EventId::fromString('20454ed7-e524-469a-b7a9-5c42c94bdfdd'), 'yet_another_event_happened', Mockery::mock('SimpleES\\EventSourcing\\Event\\DomainEvent'), $aggregateId, 2);
     $eventStream = new EventStream($aggregateId, [$envelope1, $envelope2, $envelope3]);
     return $eventStream;
 }