/**
  * @param ChangeSet $changeSet
  * @uses UserRepository::handleCreateUserChange
  * @throws MethodNotImplementedDomainException
  */
 public function save(ChangeSet $changeSet)
 {
     foreach ($changeSet->getChanges() as $change) {
         $methodName = 'handle' . $change->getChangeName();
         if (!method_exists($this, $methodName)) {
             throw new MethodNotImplementedDomainException();
         }
         $this->{$methodName}($change);
     }
 }
Exemple #2
0
 /**
  * @test
  */
 public function updateGeneratesUserChangeSet()
 {
     $user = $this->createUser();
     $user->updateUser(new UserUpdateCommand('de305d54-75b4-431b-adb2-eb6b9e546013', 'NewName', false));
     $user->updateUserPassword(new UserPasswordUpdateCommand('de305d54-75b4-431b-adb2-eb6b9e546013', '-PASSWORD-'));
     $changeSet = static::readAttribute(static::readAttribute($user, 'changeSet'), 'changes');
     $expectedChangeSet = new ChangeSet();
     $expectedChangeSet->addChange($this->getCreateUserChange($user));
     $expectedChangeSet->addChange(new UpdateUserChange($user->getUuid(), new UserName('NewName'), new UserActive(false)));
     $expectedChangeSet->addChange(new UpdateUserPasswordChange($user->getUuid(), static::readAttribute($changeSet[2], 'passwordHash')));
     static::assertEquals($expectedChangeSet, $user->flushChanges());
 }