public function testCommitEmpty() { $identifier = EventStreamIdentifier::fromString('Foo'); $contract = Contract::fromClass(\stdClass::class); $this->persistence->expects($this->never())->method('commit'); $stream = EventStream::create($this->persistence, $contract, $identifier); $stream->commit(); }
public function testOpenExistingStream() { $contract = Contract::fromClass(\stdClass::class); $identifier = EventStreamIdentifier::fromString('Foo'); $this->persistence->expects($this->once())->method('fetch')->with($contract, $identifier)->willReturn([]); $stream = $this->eventStore->openStream($contract, $identifier); $this->assertInstanceOf(EventStream::class, $stream); $this->assertEquals([], $stream->all()); }
public function testRootWillBeReconstitutedFromStream() { $contract = Contract::fromClass(AggregateRootDouble::class); $eventStreamId = EventStreamIdentifier::fromString('test'); $event = $this->getMock(DomainEvent::class); $this->persistence->expects($this->any())->method('fetch')->willReturn([$event]); $aggregate = $this->uow->get($contract, $eventStreamId); $this->assertEquals([$event], iterator_to_array($aggregate->events)); }
/** * Persist streams envelopes */ public function commit() { if (empty($this->pending)) { return; } $this->persistence->commit($this->aggregateContract, $this->aggregateIdentifier, count($this->committed), new EventCollection($this->pending)); $this->committed = array_merge($this->committed, $this->pending); $this->pending = []; }
public function testCommitStreamWithoutChanges() { $contract = Contract::fromClass(static::class); $identifier = EventStreamIdentifier::fromString('foo'); $root = $this->getMock(AggregateRoot::class); $root->expects($this->any())->method('getRecordedEvents')->willReturn([]); $this->persistence->expects($this->any())->method('fetch')->willReturn([]); $this->persistence->expects($this->never())->method('commit'); $this->eventEmitter->expects($this->never())->method('emit'); $this->uow->track($contract, $identifier, $root); $this->uow->commit(); }