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 testAppendingEventEnvelopeToOpenedEventStore() { $this->setUpContractResolver(); $contract = $this->contractResolver->resolveFromClassName(Account::class); $existingEventEnvelope = $this->createEventEnvelope(123, new AccountWasOpened('fixture-account-000', 25), 0); $persistence = $this->getMockBuilder(Persistence::class)->getMock(); $persistence->expects($this->once())->method('fetch')->with($this->equalTo($contract), $this->equalTo(123))->will($this->returnValue([$existingEventEnvelope])); $eventStore = new EventStore($persistence); $eventStream = $eventStore->open($contract, 123); $appendedEventEnvelope = $this->createEventEnvelope(124, new AccountBalanceIncreased('fixture-account-000', 10), 1); $eventStream->append($appendedEventEnvelope); $this->assertEquals($eventStream->all(), [$existingEventEnvelope, $appendedEventEnvelope]); }