/** * Paints a failing test. * * @param PHPUnit_Framework_AssertionFailedError $message Failure object displayed in * the context of the other tests. * @return void */ public function paintFail($message) { $context = $message->getTrace(); $realContext = $context[3]; $context = $context[2]; printf("FAIL on line %s\n%s in\n%s %s()\n\n", $context['line'], $message->toString(), $context['file'], $realContext['function']); }
/** * A failure occurred. * * @param PHPUnit_Framework_Test $test * @param PHPUnit_Framework_AssertionFailedError $e * @param float $time * @return void * @author Karsten Dambekalns <*****@*****.**> */ public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time) { $testCaseTraceArr = $this->getFirstNonPHPUnitTrace($e->getTrace()); $fileName = $testCaseTraceArr['file']; echo '<script type="text/javascript">document.getElementById("progress-bar").style.backgroundImage = "url(_Resources/Static/Packages/Testing/Media/indicator_red.gif)";</script> <div class="test failure"><strong>Failure</strong> in <em>' . $test->getName() . '</em> ' . '<img src="_Resources/Static/Packages/Testing/Media/failure.png" alt="Detail" onclick="if(document.getElementById(\'test' . $this->currentTestNumber . '\').style.display==\'none\') document.getElementById(\'test' . $this->currentTestNumber . '\').style.display=\'block\'; else document.getElementById(\'test' . $this->currentTestNumber . '\').style.display=\'none\'" />' . '<div class="testdetail" id="test' . $this->currentTestNumber . '">' . $fileName . ':' . $testCaseTraceArr['line'] . '<br />' . htmlspecialchars($e->getMessage()) . '<br /><div class="testoutput">' . $this->getTestOutput() . '</div></div></div>'; $this->resultArray['failure']++; $this->flushOutputBuffer(); }
private function printFailure(PHPUnit_Framework_AssertionFailedError $e) { YTestLogger::indent(); YTestLogger::say($e->getMessage() . "\n"); foreach ($e->getTrace() as $frame) { if (array_key_exists('file', $frame)) { $file = $frame['file']; if (strpos($file, 'PHPUnit/') || strpos($file, 'CustomTestCase')) { break; } YTestLogger::say($file . ":" . $frame['line'] . "\n"); } } YTestLogger::dedent(); }
/** * A test has failed. * * @param PHPUnit_Framework_Test $test the test that has failed * @param PHPUnit_Framework_AssertionFailedError $e the failed assertion * @param float $time ? * * @return void * * @throws InvalidArgumentException */ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { if (!$test instanceof PHPUnit_Framework_TestCase) { throw new InvalidArgumentException('addFailure needs $test to be a PHPUnit_Framework_TestCase.', 1334308954); } /** @var PHPUnit_Framework_TestCase $test */ $testCaseTraceArr = $this->getFirstNonPhpUnitTrace($e->getTrace()); $fileName = str_replace(PATH_site, '', $testCaseTraceArr['file']); $this->outputService->output('<script type="text/javascript">/*<![CDATA[*/setProgressBarClass("hadFailure");/*]]>*/</script>' . '<script type="text/javascript">/*<![CDATA[*/setClass("testcaseNum-' . $this->currentTestNumber . '_' . $this->currentDataProviderNumber . '","testcaseFailure");/*]]>*/</script>' . '<strong>Failure</strong> in test case <em>' . htmlspecialchars($test->getName()) . '</em>' . '<br />File: <em>' . $fileName . '</em>' . '<br />Line: <em>' . $testCaseTraceArr['line'] . '</em>'); if (method_exists($e, 'getDescription')) { $message = $e->getDescription(); } else { $message = $e->getMessage(); } $this->outputService->output('<div class="message">' . nl2br(htmlspecialchars($message)) . '</div>'); if ($e instanceof PHPUnit_Framework_ExpectationFailedException) { /** @var PHPUnit_Framework_ExpectationFailedException $e */ $comparisonFailure = $e->getComparisonFailure(); if ($comparisonFailure instanceof ComparisonFailure) { /** @var ComparisonFailure $comparisonFailure */ $expected = $comparisonFailure->getExpectedAsString(); $actual = $comparisonFailure->getActualAsString(); /** @var DiffUtility $diff */ $diff = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Utility\\DiffUtility'); $this->outputService->output('<code>' . $diff->makeDiffDisplay($actual, $expected) . '</code>'); } } }
/** * Function to extract our test file information from the $e stack trace. * Makes the error reporting more readable, since it filters out all of the PHPUnit files. * * @param PHPUnit_Framework_AssertionFailedError $e * @return string with selected files based on path */ public function getTraceFiles($e) { $trace = $e->getTrace(); $path = $this->cfg->folder . $this->cfg->path; $path = str_replace('\\', '/', $path); $message = ''; foreach ($trace as $traceLine) { if (isset($traceLine['file'])) { $file = str_replace('\\', '/', $traceLine['file']); if (stripos($file, $path) !== false) { $message .= "\n" . $traceLine['file'] . '(' . $traceLine['line'] . '): ' . $traceLine['class'] . $traceLine['type'] . $traceLine['function']; } } } return $e->toString() . $message; }
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { if ($test instanceof PHPUnit_Framework_Warning) { return; } $message = $e->getMessage(); print traceCommand("testFailed", "name", $test->getName(), "message", $message, "details", getTraceMessage($e->getTrace(), $this->myfilename)); flush(); }