/**
  * {@inheritdoc}
  */
 public function save(User $user)
 {
     $stmt = $this->pdo->prepare('INSERT INTO users(`name`, `email`, `password`) VALUES (:name, :email, :password)');
     $result = $stmt->execute(['name' => $user->getName(), 'email' => $user->getEmail(), 'password' => $user->getPassword()]);
     if (!$result) {
         throw new RuntimeException('Unable to save User Entity! ' . $stmt->errorInfo()[2]);
     }
     $this->idSetter->setEntityId($user, (int) $this->pdo->lastInsertId());
     return $user;
 }
 public function testSave()
 {
     $user = new User(new Email('*****@*****.**'));
     $user->setPassword('savedPassword')->setName('Saved John');
     try {
         $toDelete = $this->userRepository->findByEmail($user->getEmail());
         $this->userRepository->delete($toDelete);
     } catch (OutOfBoundsException $e) {
     }
     $savedUser = $this->userRepository->save($user);
     $this->assertNotNull($savedUser->getId());
     $toDelete = $this->userRepository->findByEmail($user->getEmail());
     $this->userRepository->delete($toDelete);
 }
Пример #3
0
 public function testGetEmail()
 {
     $mockEmail = $this->getMockEmail();
     $user = new User($mockEmail);
     $this->assertSame($mockEmail, $user->getEmail());
 }