1

このphpコードの単体テストをセットアップするのを手伝ってくれませんか?試してみましたが、まだ解決策が見つかりません. 私は開発者チームからこのコードを受け取りました.Imはユニットテストを作成することになっています.これについてのアイデアはありますか?

function checkbrute($user_id, $mysqli) {
   // Get timestamp of current time
   $now = time();
   // All login attempts are counted from the past 2 hours. 
   $valid_attempts = $now - (2 * 60 * 60); 

   if ($stmt = $mysqli->prepare("SELECT time FROM login_attempts WHERE user_id = ? AND time > '$valid_attempts'")) { `enter code here`
      $stmt->bind_param('i', $user_id); 
      // Execute the prepared query.
      $stmt->execute();
      $stmt->store_result();
      // If there has been more than 5 failed logins
      if($stmt->num_rows > 5) {
         return true;
      } else {
         return false;
      }
   }
}
4

2 に答える 2