/** * {@inheritdoc} */ public function onFinish(ResultsCollection $results) { if ($results->getUnknownCount() > 0) { $this->sendEmail($results); return; } if ($results->getWarningCount() > 0 && $this->sendOnWarning) { $this->sendEmail($results); return; } if ($results->getFailureCount() > 0) { $this->sendEmail($results); return; } }
/** * {@inheritDoc} */ public function onFinish(ResultsCollection $results) { if ($results->getFailureCount() > 0 || $results->getWarningCount() > 0 || $results->getUnknownCount() > 0) { $body = ''; foreach ($results as $check) { /* @var $check CheckInterface */ /* @var $result ResultInterface */ $result = isset($results[$check]) ? $results[$check] : null; if ($result instanceof ResultInterface) { $body .= sprintf("Check: %s\n", $check->getLabel()); $body .= sprintf("Message: %s\n\n", $result->getMessage()); } } $message = Swift_Message::newInstance()->setSubject($this->subject)->setFrom($this->sender)->setTo($this->recipient)->setBody($body); $this->mailer->send($message); } }
public function testIteration() { $tests = $results = array(); $test = $result = null; for ($x = 0; $x < 10; $x++) { $test = new AlwaysSuccess(); $result = new Success(); $tests[] = $test; $results[] = $result; $this->collection[$test] = $result; } $x = 0; $this->collection->rewind(); foreach ($this->collection as $test) { $this->assertSame($tests[$x], $test); $this->assertSame($results[$x], $this->collection[$test]); $x++; } }
/** * @param Collection $results * @return array */ protected function getResultCollectionToArray(Collection $results) { foreach ($results as $item) { $result = $results[$item]; $data[$item->getLabel()] = array('result' => $this->getResultName($result), 'message' => $result->getMessage(), 'data' => $result->getData()); } return array('details' => $data, 'success' => $results->getSuccessCount(), 'warning' => $results->getWarningCount(), 'failure' => $results->getFailureCount(), 'skip' => $results->getSkipCount(), 'unknown' => $results->getUnknownCount(), 'passed' => $results->getFailureCount() === 0); }
/** * This method is called when Runner has finished its run. * * @param ResultsCollection $results Collection of Results for performed Checks. * @return void */ public function onFinish(ResultsCollection $results) { $this->console->writeLine(); // Display information that the check has been aborted. if ($this->stopped) { $this->console->writeLine('Diagnostics aborted because of a failure.', Color::RED); } // Display a summary line if ($results->getFailureCount() == 0 && $results->getWarningCount() == 0 && $results->getUnknownCount() == 0) { $line = 'OK (' . $this->total . ' diagnostic checks)'; $this->console->writeLine(str_pad($line, $this->width - 1, ' ', STR_PAD_RIGHT), Color::NORMAL, Color::GREEN); } elseif ($results->getFailureCount() == 0) { $line = $results->getWarningCount() . ' warnings, '; $line .= $results->getSuccessCount() . ' successful checks'; if ($results->getSkipCount() > 0) { $line .= ', ' . $results->getSkipCount() . ' skipped checks'; } if ($results->getUnknownCount() > 0) { $line .= ', ' . $results->getUnknownCount() . ' unknown check results'; } $line .= '.'; $this->console->writeLine(str_pad($line, $this->width - 1, ' ', STR_PAD_RIGHT), Color::NORMAL, Color::YELLOW); } else { $line = $results->getFailureCount() . ' failures, '; $line .= $results->getWarningCount() . ' warnings, '; $line .= $results->getSuccessCount() . ' successful checks'; if ($results->getSkipCount() > 0) { $line .= ', ' . $results->getSkipCount() . ' skipped checks'; } if ($results->getUnknownCount() > 0) { $line .= ', ' . $results->getUnknownCount() . ' unknown check results'; } $line .= '.'; $this->console->writeLine(str_pad($line, $this->width, ' ', STR_PAD_RIGHT), Color::NORMAL, Color::RED); } $this->console->writeLine(); }
/** * @see \ZendDiagnostics\Runner\Reporter\ReporterInterface * @param ResultsCollection $results */ public function onFinish(ResultsCollection $results) { $this->consoleWriteLn(); $this->consoleWriteLn(); // Display a summary line if ($results->getFailureCount() == 0 && $results->getWarningCount() == 0 && $results->getUnknownCount() == 0 && $results->getSkipCount() == 0) { $line = 'OK (' . $this->total . ' diagnostic tests)'; $this->consoleWrite(str_pad($line, $this->width - 1, ' ', STR_PAD_RIGHT)); } elseif ($results->getFailureCount() == 0) { $line = $results->getWarningCount() . ' warnings, '; $line .= $results->getSuccessCount() . ' successful tests'; if ($results->getSkipCount() > 0) { $line .= ', ' . $results->getSkipCount() . ' skipped tests'; } if ($results->getUnknownCount() > 0) { $line .= ', ' . $results->getUnknownCount() . ' unknown test results'; } $line .= '.'; $this->consoleWrite(str_pad($line, $this->width - 1, ' ', STR_PAD_RIGHT)); } else { $line = $results->getFailureCount() . ' failures, '; $line .= $results->getWarningCount() . ' warnings, '; $line .= $results->getSuccessCount() . ' successful tests'; if ($results->getSkipCount() > 0) { $line .= ', ' . $results->getSkipCount() . ' skipped tests'; } if ($results->getUnknownCount() > 0) { $line .= ', ' . $results->getUnknownCount() . ' unknown test results'; } $line .= '.'; $this->consoleWrite(str_pad($line, $this->width, ' ', STR_PAD_RIGHT)); } $this->consoleWriteLn(); $this->consoleWriteLn(); // Display a list of failures and warnings foreach ($results as $check) { /* @var $check \ZendDiagnostics\Check\CheckInterface */ /* @var $result \ZendDiagnostics\Result\ResultInterface */ $result = $results[$check]; if ($result instanceof FailureInterface) { $this->consoleWriteLn('Failure: ' . $check->getLabel()); $message = $result->getMessage(); if ($message) { $this->consoleWriteLn($message); } $this->consoleWriteLn(); } elseif ($result instanceof WarningInterface) { $this->consoleWriteLn('Warning: ' . $check->getLabel()); $message = $result->getMessage(); if ($message) { $this->consoleWriteLn($message); } $this->consoleWriteLn(); } elseif (!$result instanceof SuccessInterface) { $this->consoleWriteLn('Unknown result ' . get_class($result) . ': ' . $check->getLabel()); $message = $result->getMessage(); if ($message) { $this->consoleWriteLn($message); } $this->consoleWriteLn(); } } // Display information that the test has been aborted. if ($this->stopped) { $this->consoleWriteLn('Diagnostics aborted because of a failure.'); } }
/** * This method is called when Runner has finished its run. * * @param ResultsCollection $results Collection of Results for performed Checks. * @return void */ public function onFinish(ResultsCollection $results) { /* @var $results \ZendDiagnostics\Result\Collection */ $this->console->writeLine(); $this->console->writeLine(); // Display a summary line if ($results->getFailureCount() == 0 && $results->getWarningCount() == 0 && $results->getUnknownCount() == 0 && $results->getSkipCount() == 0) { $line = 'OK (' . $this->total . ' diagnostic checks)'; $this->console->writeLine(str_pad($line, $this->width - 1, ' ', STR_PAD_RIGHT), Color::NORMAL, Color::GREEN); } elseif ($results->getFailureCount() == 0) { $line = $results->getWarningCount() . ' warnings'; if ($results->getSkipCount() > 0) { $line .= ', ' . $results->getSkipCount() . ' skipped checks'; } if ($results->getUnknownCount() > 0) { $line .= ', ' . $results->getUnknownCount() . ' unknown check results'; } $line .= ', ' . $results->getSuccessCount() . ' successful checks'; $line .= '.'; $this->console->writeLine(str_pad($line, $this->width - 1, ' ', STR_PAD_RIGHT), Color::NORMAL, Color::YELLOW); } else { $line = $results->getFailureCount() . ' failures, '; $line .= $results->getWarningCount() . ' warnings'; if ($results->getSkipCount() > 0) { $line .= ', ' . $results->getSkipCount() . ' skipped checks'; } if ($results->getUnknownCount() > 0) { $line .= ', ' . $results->getUnknownCount() . ' unknown check results'; } $line .= ', ' . $results->getSuccessCount() . ' successful checks'; $line .= '.'; $this->console->writeLine(str_pad($line, $this->width, ' ', STR_PAD_RIGHT), Color::NORMAL, Color::RED); } $this->console->writeLine(); // Display a list of failures and warnings foreach ($results as $check) { /* @var $check CheckInterface */ /* @var $result ResultInterface */ $result = $results[$check]; if ($result instanceof Failure) { $this->console->writeLine('Failure: ' . $check->getLabel(), Color::RED); $message = $result->getMessage(); if ($message) { $this->console->writeLine($message, Color::RED); } $this->console->writeLine(); } elseif ($result instanceof Warning) { $this->console->writeLine('Warning: ' . $check->getLabel(), Color::YELLOW); $message = $result->getMessage(); if ($message) { $this->console->writeLine($message, Color::YELLOW); } $this->console->writeLine(); } elseif ($result instanceof Skip) { $this->console->writeLine('Skipped: ' . $check->getLabel(), Color::YELLOW); $message = $result->getMessage(); if ($message) { $this->console->writeLine($message, Color::YELLOW); } $this->console->writeLine(); } elseif (!$result instanceof Success) { $this->console->writeLine('Unknown result ' . get_class($result) . ': ' . $check->getLabel(), Color::YELLOW); $message = $result->getMessage(); if ($message) { $this->console->writeLine($message, Color::YELLOW); } $this->console->writeLine(); } } // Display information that the check has been aborted. if ($this->stopped) { $this->console->writeLine('Diagnostics aborted because of a failure.', Color::RED); } }