/**
  * @test
  */
 public function itEnrichesMetadataWithARondomString()
 {
     $id = BasketId::fromString('some-id');
     $envelope = $this->testHelper->getEventStreamEnvelopeOne($id);
     $enricher = new EnrichesMetadataWithARandomString();
     $enrichedEnvelope = $enricher->enrich($envelope);
     $metadata = $enrichedEnvelope->metadata();
     $this->assertArrayHasKey('random_string', $metadata);
     $this->assertInternalType('string', $metadata['random_string']);
 }
 /**
  * @test
  */
 public function itEnrichesMetadataWhenEventsAreCommittedBeforePassingThemToTheNextEventStore()
 {
     $id = BasketId::fromString('some-id');
     $eventStream = $this->testHelper->getEventStream($id);
     $envelopeOne = $this->testHelper->getEventStreamEnvelopeOne($id);
     $envelopeTwo = $this->testHelper->getEventStreamEnvelopeTwo($id);
     $envelopeThree = $this->testHelper->getEventStreamEnvelopeThree($id);
     $this->metadataEnricher->expects($this->exactly(3))->method('enrich')->withConsecutive([$this->equalTo($envelopeOne)], [$this->equalTo($envelopeTwo)], [$this->equalTo($envelopeThree)])->will($this->returnArgument(0));
     $this->nextEventStore->expects($this->once())->method('commit')->with($this->isInstanceOf('SimpleES\\EventSourcing\\Event\\EventStream'));
     $this->eventStore->commit($eventStream);
 }
 /**
  * @test
  */
 public function itGetsEventsOfASingleAggregate()
 {
     $id = BasketId::fromString('id-1');
     $eventStream = $this->eventStore->read($id);
     $envelopes = iterator_to_array($eventStream);
     $this->assertInstanceOf('SimpleES\\EventSourcing\\Event\\EventStream', $eventStream);
     $this->assertCount(3, $eventStream);
     $envelopeOne = $this->testHelper->getEventStreamEnvelopeOne($id);
     $envelopeTwo = $this->testHelper->getEventStreamEnvelopeTwo($id);
     $envelopeThree = $this->testHelper->getEventStreamEnvelopeThree($id);
     $this->assertSame($envelopeOne, $envelopes[0]);
     $this->assertSame($envelopeTwo, $envelopes[1]);
     $this->assertSame($envelopeThree, $envelopes[2]);
 }
 /**
  * @test
  * @expectedException \SimpleES\EventSourcing\Exception\EventStreamIsCorrupt
  */
 public function itContainsOnlyEnvelopesWithTheSameAggregateIdAsItself()
 {
     $id = BasketId::fromString('some-id');
     $otherId = BasketId::fromString('other-id');
     new EventStream($id, [$this->testHelper->getEventStreamEnvelopeOne($otherId)]);
 }