public function it_can_rollBack_on_error_during_update_user(User $user) { $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'); $this->pdo->beginTransaction()->shouldBeCalled(); $exception = new \RuntimeException(); $this->pdo->prepare(new Argument\Token\StringContainsToken('UPDATE users'))->willThrow($exception); $this->pdo->rollBack()->shouldBeCalled(); $this->shouldThrow($exception)->duringUpdate($user); }
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; } }
public function createTokenForUser(User $user) { $token = new Token(Uuid::uuid4(), $this->generatePassCode(), $user->getUuid(), $this->generateExpires()); $this->tokenRepository->create($token); return $token; }
public function it_can_create_tokens_for_users(User $user) { $user->getUuid()->willReturn(Uuid::uuid4()); $this->tokenRepository->create(new Argument\Token\TypeToken(Token::class))->shouldBeCalled(); $this->createTokenForUser($user)->shouldHaveType(Token::class); }