コード例 #1
0
 public function testConstructWithHistoryEvents()
 {
     $historyEvents = array();
     $userNameChangedEvent = new UserNameChangedEvent(array('oldName' => null, 'newName' => 'Malocher'));
     $userNameChangedEvent->setSourceId(1);
     $userNameChangedEvent->setSourceVersion(1);
     $historyEvents[] = $userNameChangedEvent;
     $userEmailChangedEvent = new UserEmailChangedEvent(array('oldEmail' => null, 'newEmail' => 'my.mail@getmalocher.org'));
     $userEmailChangedEvent->setSourceId(1);
     $userEmailChangedEvent->setSourceVersion(2);
     $historyEvents[] = $userEmailChangedEvent;
     $decorator = new ProtectedAccessDecorator();
     $decorator->constructManagedObjectFromHistory('Malocher\\EventStoreTest\\Coverage\\Mock\\User', '1', $historyEvents);
     $mockUser = $decorator->getManagedObject();
     $this->assertEquals(2, $mockUser->getSourceVersion());
     $this->assertEquals('Malocher', $mockUser->getName());
     $this->assertEquals('my.mail@getmalocher.org', $mockUser->getEmail());
     //history events must not be treated as events that have to be stored
     $this->assertEquals(0, count($decorator->getPendingEvents()));
 }
コード例 #2
0
 public function testLoadStreamFromVersionOn()
 {
     $yesterdayTimestamp = time() - 86400;
     $userNameChangedEvent = new UserNameChangedEvent(array('name' => 'Malocher'), '100', $yesterdayTimestamp, 2.0);
     $userNameChangedEvent->setSourceId('1');
     $userNameChangedEvent->setSourceVersion(1);
     $userEmailChangedEvent = new UserEmailChangedEvent(array('email' => 'my.mail@getmalocher.org'), '101', $yesterdayTimestamp, 2.0);
     $userEmailChangedEvent->setSourceId('1');
     $userEmailChangedEvent->setSourceVersion(2);
     $this->doctrineDbalAdapter->addToStream('User', '1', array($userNameChangedEvent, $userEmailChangedEvent));
     $snapshotEvent = new SnapshotEvent(array('name' => 'Malocher', 'email' => 'my.mail@getmalocher.org'), '102', $yesterdayTimestamp, 2.0);
     $snapshotEvent->setSourceId('1');
     $snapshotEvent->setSourceVersion(3);
     $this->doctrineDbalAdapter->createSnapshot('User', '1', $snapshotEvent);
     $userEmailChangedEvent2 = new UserEmailChangedEvent(array('email' => 'contact@getmalocher.org'), '103', $yesterdayTimestamp, 2.0);
     $userEmailChangedEvent2->setSourceId('1');
     $userEmailChangedEvent2->setSourceVersion(4);
     $this->doctrineDbalAdapter->addToStream('User', '1', array($userEmailChangedEvent2));
     $this->assertEquals(array($snapshotEvent, $userEmailChangedEvent2), $this->doctrineDbalAdapter->loadStream('User', '1', $this->doctrineDbalAdapter->getCurrentSnapshotVersion('User', '1')));
 }