Author: Alexander Miertsch (kontakt@codeliner.ws)
Inheritance: extends Prooph\EventSourcing\AggregateRoot
 /**
  * @return AggregateRootDecorator
  */
 public function getAggregateRootDecorator()
 {
     if (is_null($this->aggregateRootDecorator)) {
         $this->aggregateRootDecorator = AggregateRootDecorator::newInstance();
     }
     return $this->aggregateRootDecorator;
 }
Ejemplo n.º 2
0
 /**
  * @return AggregateRootDecorator
  */
 private function getArTranslator()
 {
     if (is_null($this->arTranslator)) {
         $this->arTranslator = AggregateRootDecorator::newInstance();
     }
     return $this->arTranslator;
 }
 /**
  * @test
  */
 public function it_reconstructs_itself_from_history()
 {
     $user = User::nameNew('John');
     $recordedEvents = $user->accessRecordedEvents();
     AggregateRootDecorator::newInstance()->replayStreamEvents($user, new \ArrayIterator($recordedEvents));
     $user->changeName('Max');
     $additionalRecordedEvents = $user->accessRecordedEvents();
     AggregateRootDecorator::newInstance()->replayStreamEvents($user, new \ArrayIterator($additionalRecordedEvents));
     $historyEvents = new \ArrayIterator(array_merge($recordedEvents, $additionalRecordedEvents));
     $sameUser = User::fromHistory($historyEvents);
     $this->assertEquals($user->id(), $sameUser->id());
     $this->assertEquals($user->name(), $sameUser->name());
 }
 /**
  * @test
  * @expectedException RuntimeException
  * @expectedExceptionMessage Aggregate root class UnknownClass cannot be found
  */
 public function it_throws_exception_when_reconstitute_from_history_with_invalid_class()
 {
     $decorator = AggregateRootDecorator::newInstance();
     $decorator->fromHistory('UnknownClass', new \ArrayIterator([]));
 }