function it_updates(SqlManager $pdo, \PDOStatement $statement, User $user, UserId $userId, UserEmail $email)
 {
     $user->id()->shouldBeCalled()->willReturn($userId);
     $userId->id()->shouldBeCalled()->willReturn('theid');
     $user->email()->shouldBeCalled()->willReturn($email);
     $email->getValue()->shouldBeCalled()->willReturn('*****@*****.**');
     $user->password()->shouldBeCalled()->willReturn('password');
     $pdo->execute(sprintf('SELECT COUNT(*) FROM %s WHERE id = :id', SqlUserRepository::TABLE_NAME), [':id' => 'theid'])->shouldBeCalled()->willReturn($statement);
     $statement->fetchColumn()->shouldBeCalled()->willReturn(1);
     $pdo->execute(sprintf('UPDATE %s SET email = :email, password = :password WHERE id = :id', SqlUserRepository::TABLE_NAME), ['id' => 'theid', 'email' => '*****@*****.**', 'password' => 'password'])->shouldBeCalled()->willReturn($statement);
     $this->save($user);
 }
예제 #2
0
 /**
  * Executes the sql given and returns the result in array of users.
  *
  * @param string $sql        The sql query
  * @param array  $parameters Array which contains the parameters
  *
  * @return array
  */
 private function retrieveAll($sql, array $parameters = [])
 {
     $statement = $this->pdo->execute($sql, $parameters);
     return array_map(function ($row) {
         return $this->buildUser($row);
     }, $statement->fetchAll(\PDO::FETCH_ASSOC));
 }
 function its_size(SqlManager $pdo, \PDOStatement $statement, SqlUserSpecification $specification)
 {
     $pdo->execute(sprintf('SELECT COUNT(*) FROM %s', SqlUserRepository::TABLE_NAME))->shouldBeCalled()->willReturn($statement);
     $statement->fetchColumn()->shouldBeCalled()->willReturn(2);
     $this->size()->shouldReturn(2);
 }