public function testGetAndSetSnapshot()
 {
     $this->eventSourcedObject->changeName('Malocher');
     $this->eventSourcedObject->changeEmail('*****@*****.**');
     $decorator = new ProtectedAccessDecorator();
     $decorator->manageObject($this->eventSourcedObject);
     $snapshotEvent = $decorator->getSnapshot();
     $this->assertEquals($this->eventSourcedObject->getSourceVersion(), $snapshotEvent->getSourceVersion());
     $this->assertEquals($this->eventSourcedObject->getId(), $snapshotEvent->getSourceId());
     $payloadCheck = array('name' => 'Malocher', 'email' => '*****@*****.**');
     $this->assertEquals($payloadCheck, $snapshotEvent->getPayload());
     $history = array($snapshotEvent);
     $decorator = new ProtectedAccessDecorator();
     $decorator->constructManagedObjectFromHistory('Malocher\\EventStoreTest\\Coverage\\Mock\\User', '1', $history);
     $mockUser = $decorator->getManagedObject();
     $this->assertEquals($this->eventSourcedObject->getSourceVersion(), $mockUser->getSourceVersion());
     $this->assertEquals('Malocher', $mockUser->getName());
     $this->assertEquals('*****@*****.**', $mockUser->getEmail());
 }
Esempio n. 2
0
 /**
  * Load an EventSourcedObject by it's FQCN and id
  * 
  * @param string $sourceFQCN
  * @param string $sourceId
  * 
  * @return EventSourcedObject|null
  */
 public function find($sourceFQCN, $sourceId)
 {
     $hash = $this->getIdentityHash($sourceFQCN, $sourceId);
     if (isset($this->identityMap[$hash])) {
         return $this->identityMap[$hash];
     }
     $snapshotVersion = null;
     if ($this->lookupSnapshots) {
         $snapshotVersion = $this->adapter->getCurrentSnapshotVersion($sourceFQCN, $sourceId);
     }
     $historyEvents = $this->adapter->loadStream($sourceFQCN, $sourceId, $snapshotVersion);
     if (count($historyEvents) === 0) {
         return null;
     }
     $decoratedObject = new ProtectedAccessDecorator();
     $decoratedObject->constructManagedObjectFromHistory($sourceFQCN, $sourceId, $historyEvents);
     return $decoratedObject->getManagedObject();
 }