Exemplo 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();
 }
Exemplo n.º 2
0
 public function testFetchExistingStreamEnvelopes()
 {
     $contract = Contract::fromClass(\stdClass::class);
     $identifier = EventStreamIdentifier::fromString('Foo');
     $event = $this->getMock(DomainEvent::class);
     $this->persistence->commit($contract, $identifier, 0, new EventCollection([$event]));
     $result = $this->persistence->fetch($contract, $identifier);
     $this->assertEquals([$event], $result);
 }
Exemplo n.º 3
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());
 }
Exemplo n.º 4
0
$dispatcher->addSubscriber($accountHistory);
$dispatcher->addSubscriber($accountBalance);
$dispatcher->addSubscriber($transferManager);
/*
 * Normal event propagation
 *
 * When commands trigger actions on Account, domain events will be emitted
 * As reaction to those events, projectors will create data for data models
 */
$bus->handle(new OpenAccountCommand('Foo', 'EUR'));
$bus->handle(new DepositCommand('Foo', 20));
$bus->handle(new OpenAccountCommand('Bar', 'EUR'));
$bus->handle(new TransferCommand('Foo', 'Bar', 10));
$bus->handle(new WithdrawCommand('Foo', 10));
$bus->handle(new WithdrawCommand('Bar', 10));
var_dump($accountBalance, $accountHistory, $transferManager, $persistence);
/*
 * Introducing new projector
 *
 * New projector needs to catch up
 * Separate emitter is created - just for new projector - it will emit all historical events
 */
$dispatcher = new EventDispatcher();
$eventEmitter = new DispatcherEmitter($dispatcher);
$export = new AccountExportProjector();
$dispatcher->addSubscriber($export);
$stream = $eventStore->openStream(Contract::fromClass(Account::class), EventStreamIdentifier::fromString('Foo'));
$eventEmitter->emit(new EventCollection($stream->all()));
$stream = $eventStore->openStream(Contract::fromClass(Account::class), EventStreamIdentifier::fromString('Bar'));
$eventEmitter->emit(new EventCollection($stream->all()));
var_dump($export);
Exemplo n.º 5
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));
 }
Exemplo n.º 6
0
 /**
  * Check if aggregate is identified by contract and identifier
  *
  * @param Contract   $contract
  * @param Identifier $identifier
  *
  * @return bool
  */
 public function isIdentifiedBy(Contract $contract, Identifier $identifier)
 {
     return $this->contract->equals($contract) && $this->identifier->equals($identifier);
 }
Exemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function getAccount(AccountNumber $accountNumber)
 {
     return $this->uow->get(Contract::fromClass(Account::class), EventStreamIdentifier::fromString($accountNumber));
 }
Exemplo n.º 8
0
 public function testIsNotIdentifiedBecauseOfDifferentContract()
 {
     $this->identifier->expects($this->any())->method('equals')->willReturn(true);
     $this->assertFalse($this->aggregate->isIdentifiedBy(Contract::fromString('foo'), $this->identifier));
 }
Exemplo n.º 9
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();
 }