/** * Tests answers methods */ public function testAnswers() { $this->set->setAnswer(0, 'my first answer'); $this->set->setAnswer(1, 'my second answer'); $this->assertCount(2, $this->set->getAnswers()); $this->assertEquals('my first answer', $this->set->getAnswer(0)); $this->assertEquals('my second answer', $this->set->getAnswer(1)); }
/** * Returns results * * @param Set $set A Certificationy questions Set instance * @param OutputInterface $output A Symfony Console output instance */ protected function displayResults(Set $set, OutputInterface $output) { $results = array(); $questionCount = 1; foreach ($set->getQuestions() as $key => $question) { $isCorrect = $set->isCorrect($key); $label = wordwrap($question->getQuestion(), self::WORDWRAP_NUMBER, "\n"); $results[] = array(sprintf('<comment>#%d</comment> %s', $questionCount++, $label), wordwrap(implode(', ', $question->getCorrectAnswersValues()), self::WORDWRAP_NUMBER, "\n"), $isCorrect ? '<info>✔</info>' : '<error>✗</error>'); } if ($results) { $tableHelper = $this->getHelper('table'); $tableHelper->setHeaders(array('Question', 'Correct answer', 'Result'))->setRows($results); $tableHelper->render($output); $output->writeln(sprintf('<comment>Results</comment>: <error>errors: %s</error> - <info>correct: %s</info>', $set->getErrorsNumber(), $set->getValidNumber())); } }