/**
  * @dataProvider answersProvider
  * @param $numberOfGoodAnswers
  * @param $numberOfBadAnswers
  * @param $percentOfGoodAnswers
  */
 public function testItShould_updatePercentOfGoodAnswers($numberOfGoodAnswers, $numberOfBadAnswers, $percentOfGoodAnswers)
 {
     $exerciseResult = new ExerciseResult();
     $exerciseResult->number_of_good_answers = $numberOfGoodAnswers;
     $exerciseResult->number_of_bad_answers = $numberOfBadAnswers;
     $exerciseResult->updatePercentOfGoodAnswers();
     $this->assertEquals($percentOfGoodAnswers, $exerciseResult->percent_of_good_answers);
 }
 /**
  * @param int $exerciseId
  * @param int $userId
  * @param string $field
  */
 private function increaseNumberOfAnswersOfUser(int $exerciseId, int $userId, string $field)
 {
     $exerciseResult = $this->exerciseResult($exerciseId, $userId);
     if (is_null($exerciseResult)) {
         $exerciseResult = new ExerciseResult();
         $exerciseResult->user_id = $userId;
         $exerciseResult->exercise_id = $exerciseId;
         $exerciseResult->{$field} = 1;
         $exerciseResult->save();
     } else {
         // raw db call to avoid MassAssignmentException
         DB::table('exercise_results')->where('id', '=', $exerciseResult->id)->update([$field => DB::raw($field . " + 1")]);
     }
     $exerciseResult->updatePercentOfGoodAnswers();
 }