public function testExamQuestionAnswering()
 {
     $exam = new Exam();
     $exam->start();
     // Add ten questions to this exam
     $questions = array();
     for ($i = 1; $i <= 10; $i++) {
         $question = \Mockery::mock('Question');
         // Expect question number 2 to be answered later.
         if ($i == 2) {
             $question->shouldReceive('answer')->once()->andReturn();
             $question->shouldReceive('wasAnswered')->once()->andReturn(TRUE);
         } else {
             // Other questions should not be answered
             $question->shouldReceive('answer')->times(0)->andReturn();
             $question->shouldReceive('wasAnswered')->once()->andReturn(FALSE);
         }
         $questions[] = $question;
     }
     $exam->setQuestions($questions);
     // Questions are number starting by 0, the second question has 1 has ID.
     $exam->answerQuestion(1, array('my answer'));
     // Only one question should be answered
     $this->assertEquals($exam->questionsAnswered(), 1);
 }
 /**
  * @expectedException mdagostino\MultipleChoiceExams\ExpiredTimeException
  * @expectedExceptionMessage There is no left time to complete the exam.
  */
 public function testTimeLeftZero()
 {
     // This test checks if the questions are not available to be answered
     // when the time to complete the exam is exactly the duration of the exam.
     $exam = new Exam();
     $exam->setDuration(30);
     $examTimer = \Mockery::mock('ExamTimer');
     // The time is in seconds, 30 minutes are 1800 seconds.
     $examTimer->shouldReceive('getTime')->andReturn(0, 1000, 1800);
     $exam->setTimer($examTimer);
     for ($i = 0; $i < 10; $i++) {
         $available_answers = array('one', 'two', 'three');
         $right_answers = array('one', 'three');
         $question = new Question();
         $question->setTitle('Question ' . $i)->setDescription('Description for question ' . $i)->setAvailableAnswers($available_answers)->setRightAnswers($right_answers);
         $questions[] = $question;
     }
     $exam->setQuestions($questions);
     $exam->start();
     $exam->answerQuestion(0, array('one'));
     $exam->answerQuestion(1, array('one', 'two'));
     $exam->answerQuestion(2, array('one', 'three'));
     $exam->finalize();
     $this->assertFalse($exam->isApproved());
 }