コード例 #1
0
ファイル: UnitOfWorkTest.php プロジェクト: potfur/journal
 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();
 }
コード例 #2
0
ファイル: IntegrationTest.php プロジェクト: potfur/journal
 public function testEventsWillBeEmitted()
 {
     $contract = Contract::fromClass(DomainEvent::class);
     $identifier = EventIdentifier::fromString('1');
     $eventStreamId = EventStreamIdentifier::fromString('test');
     $event = $this->getMock(DomainEvent::class);
     $event->expects($this->any())->method('getIdentifier')->willReturn($identifier);
     $aggregateRoot = $this->getMock(AggregateRoot::class);
     $aggregateRoot->expects($this->any())->method('getRecordedEvents')->willReturn([$event]);
     $this->persistence->expects($this->any())->method('fetch')->willReturn([]);
     $this->eventEmitter->expects($this->once())->method('emit')->with($this->callback(function ($subject) {
         return $subject instanceof DomainEvents && count($subject) == 1;
     }));
     $this->uow->track($contract, $eventStreamId, $aggregateRoot);
     $this->uow->commit();
 }