예제 #1
0
 public function it_can_update_a_user(User $user, \PDOStatement $statement)
 {
     $user->getUuid()->willReturn($uuid = Uuid::uuid4());
     $user->getEmailAddress()->willReturn(EmailAddress::get($email = '*****@*****.**'));
     $user->getPassword()->willReturn($password = password_hash('no.jedi.please', PASSWORD_BCRYPT));
     $user->getDisplayName()->willReturn($displayName = 'Nute Gunray');
     $user->metaDataSetUpdateTimestamp(new Argument\Token\TypeToken(\DateTimeInterface::class))->shouldBeCalled();
     $this->pdo->beginTransaction()->shouldBeCalled();
     $this->pdo->prepare(new Argument\Token\StringContainsToken('UPDATE users'))->willReturn($statement);
     $statement->execute(['user_uuid' => $uuid->getBytes(), 'email_address' => $email, 'password' => $password, 'display_name' => $displayName])->shouldBeCalled();
     $statement->rowCount()->willReturn(1);
     $this->objectRepository->update(User::TYPE, $uuid)->shouldBeCalled();
     $this->pdo->commit()->shouldBeCalled();
     $this->update($user);
 }
예제 #2
0
 public function update(User $user)
 {
     $this->pdo->beginTransaction();
     try {
         $query = $this->executeSql('
             UPDATE users
                SET email_address = :email_address,
                    password = :password,
                    display_name = :display_name
              WHERE user_uuid = :user_uuid
         ', ['user_uuid' => $user->getUuid()->getBytes(), 'email_address' => $user->getEmailAddress()->toString(), 'password' => $user->getPassword(), 'display_name' => $user->getDisplayName()]);
         // When at least one of the fields changes, the rowCount will be 1 and an update occurred
         if ($query->rowCount() === 1) {
             $this->objectRepository->update(User::TYPE, $user->getUuid());
             $user->metaDataSetUpdateTimestamp(new \DateTimeImmutable());
         }
         $this->pdo->commit();
     } catch (\Throwable $exception) {
         $this->pdo->rollBack();
         throw $exception;
     }
 }