public function testSaveAndFind()
 {
     $user = new User('1');
     $user->changeName('Malocher');
     $user->changeEmail('*****@*****.**');
     $this->repository->save($user);
     $checkUser = $this->repository->find('1');
     $this->assertEquals($user->getName(), $checkUser->getName());
 }
 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());
 }
示例#3
0
 public function testDispatchPreCommitEvent()
 {
     $this->eventStore->beginTransaction();
     $user = new User('1');
     $user->changeName('Malocher');
     $user->changeEmail('*****@*****.**');
     $persistedEventList = array();
     $this->eventStore->events()->addListener(PostPersistEvent::NAME, function (PostPersistEvent $e) use(&$persistedEventList) {
         foreach ($e->getPersistedEvents() as $persistedEvent) {
             $persistedEventList[] = get_class($persistedEvent);
         }
     });
     $this->eventStore->events()->addListener(PreCommitEvent::NAME, function (PreCommitEvent $e) use($user) {
         $e->getEventStore()->save($user);
     });
     $this->eventStore->commit();
     $check = array('Malocher\\EventStoreTest\\Coverage\\Mock\\Event\\UserNameChangedEvent', 'Malocher\\EventStoreTest\\Coverage\\Mock\\Event\\UserEmailChangedEvent');
     $this->assertEquals($check, $persistedEventList);
 }