Ejemplo n.º 1
0
 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();
 }
Ejemplo n.º 2
0
 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());
 }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 4
0
 /**
  * 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 = [];
 }
Ejemplo n.º 5
0
 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();
 }