Exemplo n.º 1
0
 public function testCreateUserSucceeds()
 {
     $passwordHash = 'Corned beef password hash';
     $this->dao->expects($this->once())->method('createUser')->with($this->user['email'], $this->matchesRegularExpression('/^\\$2y\\$10\\$[a-zA-Z0-9\\.\\/]*$/'))->will($this->returnValue($this->user));
     $user = $this->service->createUser($this->user['email'], 'password', 'password');
     $this->assertEquals($this->user, $user);
 }
Exemplo n.º 2
0
 /**
  * Creates a new user
  *
  * @param  string $email    Email address
  * @param  string $password Password
  * @param  string $confirm  Password confirmation
  * @return array  User data
  */
 public function createUser($email, $password, $confirm)
 {
     if (!$password || !$confirm) {
         throw new \InvalidArgumentException('Password and confirm password are both required.');
     }
     if ($password !== $confirm) {
         throw new \InvalidArgumentException('Passwords must match.');
     }
     if (strlen($password) < 8) {
         throw new \InvalidArgumentException('Password must be at least 8 characters in length.');
     }
     $passwordHash = password_hash($password, PASSWORD_DEFAULT);
     $user = $this->dao->createUser($email, $passwordHash);
     unset($user['password_hash']);
     return $user;
 }
Exemplo n.º 3
0
 /**
  * This should cover the possibility of a malfunciton in password_hash
  */
 public function testCreateUserFailsWithNullHash()
 {
     $this->setExpectedException('InvalidArgumentException', 'Password hash must not be null');
     $user = $this->dao->createUser('*****@*****.**', null);
 }