closeConnection(Doctrine_Manager::connection()); } public function testStartsEmpty() { $q = new App_Questioner(); $this->assertEquals(0, count($q->getAskedQuestions())); } public function testGetAnswers() { $this->loadData(); $question = array('id' => 1); $q = new App_Questioner(); $answers = $q->getAnswers($question, QuestionAnswer::CHOICE_YES); $this->assertNotEquals(0, count($answers)); $answers = $q->getAnswers($question, QuestionAnswer::CHOICE_NO); $this->assertNotEquals(0, count($answers)); } public function testGetQuestion() { $this->loadData(); $q = new App_Questioner(); $this->assertNotNull($q->getRandomQuestion()); } public function testGetsNotAskedQuestions() { $this->loadData(); $q = new App_Questioner(); $q->setAskedQuestions(array( array('id'=>1), array('id'=>2) )); for($i = 0; $i < 10; $i++) { $question = $q->getRandomQuestion(); $this->assertEquals(3, $question['id']); } } public function testCantGetBestIfNoQuestionsSet() { try { $q = new App_Questioner(); $q->getBestAnswer(); } catch(App_Questioner_Exception $e) { return; } $this->fail(); } public function testGetsBestAnswer() { $this->loadData(); $q = new App_Questioner(); $q->setAskedQuestions(array( array('id'=>2, 'choice'=>QuestionAnswer::CHOICE_YES) )); $answer = $q->getBestAnswer(); $this->assertTrue(isset($answer['id'])); $this->assertEquals(1, $answer['id']); } }