public function testCommittingEventStream()
 {
     $this->setUpContractResolver();
     $aggregateRootType = $this->contractResolver->resolveFromClassName(Account::class);
     $aggregateRootId = 123;
     $eventId = 456;
     $secondEventId = 789;
     $appendedEventEnvelopeOne = $this->createEventEnvelope($aggregateRootType, $aggregateRootId, $eventId, new AccountWasOpened('fixture-account-000', 25), 0);
     $appendedEventEnvelopeTwo = $this->createEventEnvelope($aggregateRootType, $aggregateRootId, $secondEventId, new AccountWasOpened('fixture-account-001', 35), 1);
     // Commit EventStream - First Time
     $commitIdOne = CommitId::fromString('first-time');
     // Commit EventStream - First Time
     $commitIdTwo = CommitId::fromString('second-time');
     $persistence = $this->getMockBuilder(Persistence::class)->getMock();
     $eventStream = EventStream::create($persistence, $aggregateRootType, $aggregateRootId);
     $persistence->expects($this->exactly(2))->method('commit')->withConsecutive(array($commitIdOne), array($commitIdTwo));
     // Append to EventStream
     $eventStream->append($appendedEventEnvelopeOne);
     $this->assertEquals($eventStream->all(), [$appendedEventEnvelopeOne]);
     $eventStream->commit($commitIdOne);
     $this->assertEquals($eventStream->all(), [$appendedEventEnvelopeOne]);
     $eventStream->append($appendedEventEnvelopeTwo);
     $this->assertEquals($eventStream->all(), [$appendedEventEnvelopeOne, $appendedEventEnvelopeTwo]);
     $eventStream->commit($commitIdTwo);
     $this->assertEquals($eventStream->all(), [$appendedEventEnvelopeOne, $appendedEventEnvelopeTwo]);
 }
 public function test()
 {
     $commitIdGenerator = new CallableCommitIdGenerator(function () {
         return CommitId::fromString('TEST123');
     });
     $commitId = $commitIdGenerator->generateCommitId();
     $this->assertEquals('TEST123', (string) $commitId);
 }
 private function deserializeCommittedEvent($row)
 {
     return new CommittedEvent(CommitId::fromString($row['commit_id']), DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $row['utc_committed_time']), new Contract($row['aggregate_root_type'], str_replace('.', '\\', $row['aggregate_root_type'])), $row['aggregate_root_id'], (int) $row['aggregate_root_version'], new EventEnvelope($this->eventContractResolver->resolveFromContractName($row['event_type']), $row['event_id'], $this->eventSerializer->deserialize($this->eventContractResolver->resolveFromContractName($row['event_type']), json_decode($row['event'], true)), (int) $row['event_version'], DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $row['when'])));
 }
 protected function createCommit(Persistence $persistence, $commitId, $aggregateClassName, $aggregateId, $expectedAggregateVersion, array $eventEnvelopes)
 {
     $persistence->commit(CommitId::fromString($commitId), $this->getContractResolver()->resolveFromClassName($aggregateClassName), $aggregateId, $expectedAggregateVersion, $eventEnvelopes);
 }