public function it_can_insert_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->metaDataSetInsertTimestamp(new Argument\Token\TypeToken(\DateTimeInterface::class))->shouldBeCalled(); $this->pdo->beginTransaction()->shouldBeCalled(); $this->objectRepository->create(User::TYPE, $uuid); $this->pdo->prepare(new Argument\Token\StringContainsToken('INSERT INTO users'))->willReturn($statement); $statement->execute(['user_uuid' => $uuid->getBytes(), 'email_address' => $email, 'password' => $password, 'display_name' => $displayName])->shouldBeCalled(); $this->pdo->commit()->shouldBeCalled(); $this->create($user); }
public function create(User $user) { $this->pdo->beginTransaction(); try { $this->objectRepository->create(User::TYPE, $user->getUuid()); $this->executeSql(' INSERT INTO users (user_uuid, email_address, password, display_name) VALUES (:user_uuid, :email_address, :password, :display_name) ', ['user_uuid' => $user->getUuid()->getBytes(), 'email_address' => $user->getEmailAddress()->toString(), 'password' => $user->getPassword(), 'display_name' => $user->getDisplayName()]); $this->pdo->commit(); $user->metaDataSetInsertTimestamp(new \DateTimeImmutable()); } catch (\Throwable $exception) { $this->pdo->rollBack(); throw $exception; } }