コード例 #1
0
 /**
  * @test
  * @covers ::findById
  */
 public function it_should_reconstitute_state_based_on_events()
 {
     $event = new Event('test', 1, []);
     $entryWithEvent = new EntryWithEvent(new Entry([]), $event);
     $expectedEntity = new \stdClass();
     $this->streamNameGenerator->shouldReceive('generate')->andReturn('stream.id');
     $this->eventStore->shouldReceive('forwardStreamFeedIterator')->andReturn([$entryWithEvent]);
     $this->eventSerializer->shouldReceive('unserialize')->with('test', [])->once()->andReturn($expectedEntity);
     $this->assertEquals(new AggregateMock(), $this->repository->findById('1'));
 }
コード例 #2
0
 /**
  * @param object|IsEventSourced $aggregateRoot
  *
  * @return array
  */
 private function getWriteableEventsFromAggregate($aggregateRoot)
 {
     $domainEvents = $aggregateRoot->extractRecordedEvents();
     $eventsArray = [];
     foreach ($domainEvents as $event) {
         $metadata = [];
         if ($this->metadataStore) {
             $metadata = $this->metadataStore->metadata($event);
         }
         $eventsArray[] = WritableEvent::newInstance(get_class($event), $this->eventSerializer->serialize($event), $metadata);
     }
     return $eventsArray;
 }