_quiz = new App_QuizHandler(); } public function testStore() { $store = new Zend_Session_Namespace(__CLASS__); $this->_quiz->setStore($store); $this->assertSame($store, $this->_quiz->getStore()); } public function testQuestioner() { $questioner = new App_Questioner(); $this->_quiz->setQuestioner($questioner); $this->assertSame($questioner, $this->_quiz->getQuestioner()); } public function testGettingBestAnswer() { $q = $this->getMock('App_Questioner', array('getBestAnswer')); $q->expects($this->once()) ->method('getBestAnswer') ->will($this->returnValue('answer')); $this->_quiz->setQuestioner($q); $this->assertEquals('answer', $this->_quiz->getBestAnswer()); } public function testGettingQuestionCount() { $this->_quiz->getTotalQuestionsAsked(); } public function testGetsNewQuestionAfterAnswer() { $store = new Zend_Session_Namespace(__FUNCTION__); $this->_quiz->setStore($store); //Shouldn't access dao's directly, but use getRandomQuestion $mockFactory = $this->getMock('App_DaoFactory'); $mockFactory->expects($this->never()) ->method('getQuestionDao'); App_DaoFactory::setFactory($mockFactory); $returnQuestion = new Quiz_Question(); $otherReturnQuestion = new Quiz_Question(); $q = $this->getMock('App_Questioner'); $q->expects($this->exactly(2)) ->method('getRandomQuestion') ->will($this->onConsecutiveCalls($returnQuestion, $otherReturnQuestion)); $this->_quiz->setQuestioner($q); $question = $this->_quiz->getAQuestion(); $this->_quiz->answerCurrentQuestion(QuestionAnswer::CHOICE_DONTKNOW); $otherQuestion = $this->_quiz->getAQuestion(); $this->assertNotSame($question, $otherQuestion); } public function testReturnsNullIfNoQuestionFound() { $store = new Zend_Session_Namespace(__FUNCTION__); $this->_quiz->setStore($store); $q = $this->getMock('App_Questioner'); $q->expects($this->once()) ->method('getRandomQuestion') ->will($this->returnValue(null)); $this->_quiz->setQuestioner($q); $question = $this->_quiz->getAQuestion(); $this->assertNull($question); } }