public function runStep(Step $step) { $result = null; $this->fire(Events::STEP_BEFORE, new StepEvent($this, $step)); try { $result = $step->run($this->moduleContainer); } catch (ConditionalAssertionFailed $f) { $this->testResult->addFailure(clone $this, $f, $this->testResult->time()); } catch (\Exception $e) { $this->fire(Events::STEP_AFTER, new StepEvent($this, $step)); throw $e; } $this->fire(Events::STEP_AFTER, new StepEvent($this, $step)); return $result; }
/** * Paints the end of the test with a summary of * the passes and failures. * * @param PHPUnit_Framework_TestResult $result Result object * * @return void */ public function paintFooter($result) { ob_end_flush(); $colour = $result->failureCount() + $result->errorCount() > 0 ? "red" : "green"; echo "</ul>\n"; echo "<div style=\""; echo "padding: 8px; margin: 1em 0; background-color: {$colour}; color: white;"; echo "\">"; echo $result->count() - $result->skippedCount() . "/" . $result->count(); echo " test methods complete:\n"; echo "<strong>" . count($result->passed()) . "</strong> passes, "; echo "<strong>" . $result->failureCount() . "</strong> fails, "; echo "<strong>" . $this->numAssertions . "</strong> assertions and "; echo "<strong>" . $result->errorCount() . "</strong> exceptions."; echo "</div>\n"; echo '<div style="padding:0 0 5px;">'; echo '<p><strong>Time:</strong> ' . $result->time() . ' seconds</p>'; echo '<p><strong>Peak memory:</strong> ' . number_format(memory_get_peak_usage()) . ' bytes</p>'; echo $this->_paintLinks(); echo '</div>'; if (isset($this->params['codeCoverage']) && $this->params['codeCoverage']) { $coverage = $result->getCodeCoverage(); if (method_exists($coverage, 'getSummary')) { $report = $coverage->getSummary(); echo $this->paintCoverage($report); } if (method_exists($coverage, 'getData')) { $report = $coverage->getData(); echo $this->paintCoverage($report); } } $this->paintDocumentEnd(); }
/** * Renders the summary of test passes and failures. * * @param PHPUnit_Framework_TestResult $result Result object * * @return void */ public function paintFooter($result) { ob_end_flush(); echo '</ul>'; if ($result->failureCount() + $result->errorCount() > 0) { echo '<div class="alert-box alert radius">'; } else { echo '<div class="alert-box success radius">'; } echo $result->count() - $result->skippedCount() . ' of '; echo $result->count() . ' test methods complete: '; echo count($result->passed()) . ' passes, '; echo $result->failureCount() . ' fails, '; echo $this->numAssertions . ' assertions and '; echo $result->errorCount() . ' exceptions.'; echo '</div>'; echo '<p><strong>Time:</strong> ' . __('%0.5f seconds', $result->time()) . '</p>'; echo '<p><strong>Peak Memory:</strong> ' . number_format(memory_get_peak_usage()) . ' bytes</p>'; $this->_paintLinks(); if (isset($this->params['codeCoverage']) && $this->params['codeCoverage']) { $coverage = $result->getCodeCoverage(); if (method_exists($coverage, 'getSummary')) { $report = $coverage->getSummary(); $this->paintCoverage($report); } if (method_exists($coverage, 'getData')) { $report = $coverage->getData(); $this->paintCoverage($report); } } $this->paintDocumentEnd(); }
/** * @param \PHPUnit_Framework_TestResult $result */ public function printResult(\PHPUnit_Framework_TestResult $result) { if (!$this->silent) { $this->printHeader($result->time()); if ($result->errorCount() > 0) { $this->printErrors($result); } if ($result->failureCount() > 0) { if ($result->errorCount() > 0) { print "\n--\n\n"; } $this->printFailures($result); } if ($result->notImplementedCount() > 0) { if ($result->failureCount() > 0) { print "\n--\n\n"; } $this->printIncompletes($result); } if ($result->skippedCount() > 0) { if ($result->notImplementedCount() > 0) { print "\n--\n\n"; } $this->printSkipped($result); } } $this->printFooter($result); }
/** * @param PHPUnit_Framework_TestResult $result * @access public */ public function printResult(PHPUnit_Framework_TestResult $result) { $this->printHeader($result->time()); $this->printBody($result); $this->printFooter($result); $this->printErrors($result); $this->printFailures($result); $this->printIncompletes($result); $this->printSkipped($result); echo $this->buffer; }
/** * Paints the end of the test with a summary of * the passes and failures. * * @param PHPUnit_Framework_TestResult $result Result object * @return void */ public function paintFooter($result) { if ($result->failureCount() + $result->errorCount() == 0) { echo "\nOK\n"; } else { echo "FAILURES!!!\n"; } echo "Test cases run: " . $result->count() . "/" . ($result->count() - $result->skippedCount()) . ', Passes: ' . $this->numAssertions . ', Failures: ' . $result->failureCount() . ', Exceptions: ' . $result->errorCount() . "\n"; echo 'Time: ' . $result->time() . " seconds\n"; echo 'Peak memory: ' . number_format(memory_get_peak_usage()) . " bytes\n"; if (isset($this->params['codeCoverage']) && $this->params['codeCoverage']) { $coverage = $result->getCodeCoverageInformation(); echo $this->paintCoverage($coverage); } }
/** * Creates a Streamwide_PHPUnit_Runner_TestCaseResult from a PHPUnit_Framework_TestResult. * * @param Streamwide_PHPUnit_Runner_TestCase $testCase test case * @param PHPUnit_Framework_TestResult $testResult test result * @return Streamwide_PHPUnit_Runner_TestCaseResult test case result */ public static function fromPHPUnitTestResult(Streamwide_PHPUnit_Runner_TestCase $testCase, PHPUnit_Framework_TestResult $testResult) { $passed = $testResult->passed(); $skipped = $testResult->skipped(); $errors = $testResult->errors(); $failures = $testResult->failures(); $notImplemented = $testResult->notImplemented(); $time = $testResult->time(); $statusMessage = null; $codeCoverage = null; if (!empty($passed)) { $status = Streamwide_PHPUnit_Runner_TestCaseResult::PASSED; $codeCoverage = $testResult->getCodeCoverageInformation(); } else { if (!empty($skipped)) { $status = Streamwide_PHPUnit_Runner_TestCaseResult::SKIPPED; $statusMessage = $skipped[0]->toStringVerbose(true); } else { if (!empty($notImplemented)) { $status = Streamwide_PHPUnit_Runner_TestCaseResult::NOT_IMPLEMENTED; $statusMessage = $notImplemented[0]->toStringVerbose(true); } else { if (!empty($errors)) { $status = Streamwide_PHPUnit_Runner_TestCaseResult::ERROR; $statusMessage = $errors[0]->toStringVerbose(true) . PHPUnit_Util_Filter::getFilteredStacktrace($errors[0]->thrownException()); } else { if (!empty($failures)) { $status = Streamwide_PHPUnit_Runner_TestCaseResult::FAILED; $statusMessage = $failures[0]->toStringVerbose(true) . PHPUnit_Util_Filter::getFilteredStacktrace($failures[0]->thrownException()); } } } } } $testCaseResult = new Streamwide_PHPUnit_Runner_TestCaseResult($testCase, $status, $statusMessage, null, $time, $codeCoverage); return $testCaseResult; }
/** * @param PHPUnit_Framework_TestResult $result * @access public */ public function printResult(PHPUnit_Framework_TestResult $result) { $this->printHeader($result->time()); $this->printErrors($result); $this->printFailures($result); if ($this->verbose) { $this->printIncompletes($result); $this->printSkipped($result); } $this->printFooter($result); }
public function printResult(\PHPUnit_Framework_TestResult $result) { $upLine = str_repeat($this->colors ? '▁' : '-', $this->maxColumns); $dnLine = str_repeat($this->colors ? '▔' : '-', $this->maxColumns); $arrow = $this->colors ? '❯' : '=>'; $this->printFailures(); if (!count($this->exceptions)) { $ch = $this->colors ? ' ✔' : ''; $upLine = "[32m" . $upLine . "\n[0m"; $dnLine = "[32m" . $dnLine . "\n[0m"; $str = "[32m{$ch}[0m OK {$arrow} Passed %s of %s"; $str = sprintf($str, count($result->passed()), $result->count()); } else { $ch = $this->colors ? ' ✖' : ''; $upLine = "[31m" . $upLine . "\n[0m"; $dnLine = "[31m" . $dnLine . "\n[0m"; $str = "[31m{$ch}[0m KO {$arrow} Failed %s of %s"; $str = sprintf($str, $result->failureCount() + $result->errorCount(), $result->count()); } if (!$result->allCompletlyImplemented()) { $pair = array(); if ($result->notImplementedCount() > 0) { $pair[] = $result->notImplementedCount() . ' not implemented'; } if ($result->skippedCount() > 0) { $pair[] = $result->skippedCount() . ' skipped'; } $str .= " with " . implode(' and ', $pair); } // Calculate time and peak memory usage $time = number_format($result->time(), 2); $mem = memory_get_peak_usage(); $mem = round($mem / 1024 / 1024); // Add time spent $str .= " [30;1m({$time}s {$mem}Mb)\n[0m"; // Clean up the line above and print there $this->write("[1A[2K"); $this->write($upLine); $this->write($str); $this->write($dnLine); }
/** * Parse the test suite result * * @param \PHPUnit_Framework_TestResult $result * @return array<string,double|integer|array> */ private function parseTestSuite($result) { $passed = 0; $error = 0; $failed = 0; $notImplemented = 0; $skipped = 0; $tests = []; foreach ($result->passed() as $key => $value) { $tests[] = $this->parseTest('passed', $key); $passed++; } foreach ($result->failures() as $obj) { $tests[] = $this->parseTest('failed', $obj); $failed++; } foreach ($result->skipped() as $obj) { $tests[] = $this->parseTest('skipped', $obj); $skipped++; } foreach ($result->notImplemented() as $obj) { $tests[] = $this->parseTest('notImplemented', $obj); $notImplemented++; } foreach ($result->errors() as $obj) { $tests[] = $this->parseTest('error', $obj); $error++; } usort($tests, function ($a, $b) { return strnatcmp($a['class'], $b['class']); }); return ['time' => $result->time(), 'total' => count($tests), 'passed' => $passed, 'error' => $error, 'failed' => $failed, 'notImplemented' => $notImplemented, 'skipped' => $skipped, 'tests' => $tests]; }
public function printResult(PHPUnit_Framework_TestResult $result) { echo '<h1>QCubed ' . QCUBED_VERSION_NUMBER_ONLY . ' Unit Tests - PHPUnit ' . PHPUnit_Runner_Version::id() . '</h1>'; foreach ($this->results as $suiteName => $suite) { $strHtml = "<b>{$suiteName}</b><br />"; foreach ($suite as $testName => $test) { $status = $test['status']; $status = ucfirst($status); if ($test['status'] !== 'passed') { $status = '<span style="color:red">' . $status . '</span>'; } else { $status = '<span style="color:green">' . $status . '</span>'; } $strHtml .= "{$status}: {$testName}"; $strHtml = "{$strHtml}<br />"; if (isset($test['errors'])) { foreach ($test['errors'] as $error) { $strHtml .= nl2br(htmlentities($error['e']->__toString())) . '<br />'; } } if (isset($test['results'])) { foreach ($test['results'] as $error) { $strMessage = $error['e']->toString() . "\n"; // get first line $lines = explode("\n", PHPUnit_Util_Filter::getFilteredStacktrace($error['e'])); $strMessage .= $lines[0] . "\n"; $strHtml .= nl2br(htmlentities($strMessage)) . '<br />'; } } } echo $strHtml; } $str = "\nRan " . $result->count() . " tests in " . $result->time() . " seconds.\n"; $str .= $result->failureCount() . " assertions failed.\n"; $str .= $result->errorCount() . " exceptions were thrown.\n"; echo nl2br($str); }