/** * Tests getters and setters */ public function testGettersSetters() { $this->assertCount(2, $this->set->getQuestions()); foreach ($this->set->getQuestions() as $question) { $this->assertInstanceOf('Certificationy\\Certification\\Question', $question); } $this->assertInstanceOf('Certificationy\\Certification\\Question', $this->set->getQuestion(0)); $this->assertEquals('my first question', $this->set->getQuestion(0)->getQuestion()); $this->assertEquals('my second question', $this->set->getQuestion(1)->getQuestion()); }
/** * 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())); } }