protected function onNotSuccessfulTest(\Exception $e) { if ($e instanceof PredictionException) { $e = new \PHPUnit_Framework_AssertionFailedError($e->getMessage(), $e->getCode(), $e); } return parent::onNotSuccessfulTest($e); }
/** * A failure occurred. * * @param PHPUnit_Framework_Test $test * @param PHPUnit_Framework_AssertionFailedError $e * @param float $time */ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { $this->write('fail: ' . $e->getMessage()); $trace = current(PHPUnit_Util_Filter::getFilteredStacktrace($e, FALSE)); $this->write('trace: ' . print_r($trace, 1)); $this->currentTestPass = FALSE; }
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { $class = get_class($test); $message = $this->escape($e->getMessage()); $trace = $this->escape($e->getTraceAsString()); echo "##teamcity[testFailed type='failure' name='{$class}.{$test->getName()}' message='{$message}'" . " details='{$trace}']\n"; }
/** * 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(); }
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { $this->_fails += 1; if ($this->_fails == 1) { echo "\n<div class=\"failure\">"; } printf("Test '%s' failed : %s.<br />\n<pre>%s</pre>\n", $test->getName(), htmlentities($e->getMessage()), (string) $e->getTraceAsString()); //echo("Failure $this->_fails : $t<br>\n"); }
/** * A failure occurred. * * @param PHPUnit_Framework_Test $test * @param PHPUnit_Framework_AssertionFailedError $e * @param float $time * @return void */ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { $message = sprintf("%s FAILURE: %s (Duration: %s sec)", str_repeat(' ', $this->level), str_replace("\n", " ", $e->getMessage()), $this->getDuration()); if ($this->colors) { $this->write("[41;37m{$message}[0m" . "\n"); } else { $this->write($message . "\n"); } $this->lastTestFailed = TRUE; }
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { if ($this->verbose) { echo " FAIL: '" . $e->getMessage() . "'\n" . $e->getTraceAsString(); } parent::addFailure($test, $e, $time); if ($this->_blDBResetPerTest && !isset($test->blNoDbResetAfterTest)) { $this->_oDBMaintenance->restoreDB($this->_iDBChangeMode, $this->_iDBChangeOutput); echo "|"; } }
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(); }
/** * Constructor. * * @param string $message * @param integer $code * @param string $file * @param integer $line * @param array $trace */ public function __construct($message, $code, $file, $line, $trace) { parent::__construct($message, $code); $this->syntheticFile = $file; $this->syntheticLine = $line; $this->syntheticTrace = $trace; }
public function __construct($description, PHPUnit_Framework_ComparisonFailure $comparisonFailure = NULL, $message = '') { $this->description = $description; $this->comparisonFailure = $comparisonFailure; if (!empty($message)) { $description .= "\n" . $message; } parent::__construct($description); }
public function __construct($message, Process $process) { if ($output = $process->getOutput()) { $message .= "\n\nCommand output:\n" . $output; } if ($stderr = $process->getErrorOutput()) { $message .= "\n\nCommand stderr:\n" . $stderr; } parent::__construct($message); }
/** * A failure occurred. * * @todo Add check that $test is instance of PHPUnit_Framework_TestCase * * @param PHPUnit_Framework_Test $test * @param PHPUnit_Framework_AssertionFailedError $e * @param float $time */ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { $failures = array(); $testResult = $test->getTestResultObject(); /** @var $failure PHPUnit_Framework_TestFailure */ foreach ($testResult->failures() as $failure) { $hash = "{$e->getMessage()} {$e->getTraceAsString()}"; if (isset($failures[$hash])) { continue; } $array = array('type' => self::MESSAGE_COMPARISON_FAILURE, 'name' => $test->getName(), 'message' => $e->getMessage(), 'details' => $e->getTraceAsString()); /** @var $exception PHPUnit_Framework_ExpectationFailedException */ $exception = $failure->thrownException(); $comparisonFailure = $exception->getComparisonFailure(); if ($comparisonFailure instanceof PHPUnit_Framework_ComparisonFailure) { $array += array('expected' => $comparisonFailure->getExpectedAsString(), 'actual' => $comparisonFailure->getActualAsString()); } $message = $this->getServiceMessage(self::MESSAGE_TEST_FAILED, $array); $this->write($message); $failures[$hash] = true; } }
public function __construct($selector, $message = null) { if (is_array($selector)) { $type = strtolower(key($selector)); $locator = $selector[$type]; parent::__construct("Element with {$type} '{$locator}' was not found."); return; } if ($selector instanceof \WebDriverBy) { $type = $selector->getMechanism(); $locator = $selector->getValue(); parent::__construct("Element with {$type} '{$locator}' was not found."); return; } parent::__construct($message . " '{$selector}' was not found."); }
/** * Adds the failure detail to the current test and increases the failure * count for the current suite * * @param PHPUnit_Framework_Test $test current test that is being run * @param PHPUnit_Framework_AssertionFailedError $e PHPUnit error * @param int $time */ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { if ($this->currentSuite) { $this->currentSuite['failures']++; } else { $this->currentSession['failures']++; } $this->addStatus(TEST_FAILURE, $e->toString(), $this->getTestException($test, $e), $e->getTrace()); }
/** * Runs a TestCase. * * @param PHPUnit_Framework_Test $test */ public function run(PHPUnit_Framework_Test $test) { PHPUnit_Framework_Assert::resetCount(); if ($test instanceof PHPUnit_Framework_TestCase) { $test->setRegisterMockObjectsFromTestArgumentsRecursively($this->registerMockObjectsFromTestArgumentsRecursively); } $error = false; $failure = false; $warning = false; $incomplete = false; $risky = false; $skipped = false; $this->startTest($test); $errorHandlerSet = false; if ($this->convertErrorsToExceptions) { $oldErrorHandler = set_error_handler(['PHPUnit_Util_ErrorHandler', 'handleError'], E_ALL | E_STRICT); if ($oldErrorHandler === null) { $errorHandlerSet = true; } else { restore_error_handler(); } } $collectCodeCoverage = $this->codeCoverage !== null && !$test instanceof PHPUnit_Framework_WarningTestCase; if ($collectCodeCoverage) { $this->codeCoverage->start($test); } $monitorFunctions = $this->beStrictAboutResourceUsageDuringSmallTests && !$test instanceof PHPUnit_Framework_WarningTestCase && $test->getSize() == PHPUnit_Util_Test::SMALL && function_exists('xdebug_start_function_monitor'); if ($monitorFunctions) { xdebug_start_function_monitor(ResourceOperations::getFunctions()); } PHP_Timer::start(); try { if (!$test instanceof PHPUnit_Framework_WarningTestCase && $test->getSize() != PHPUnit_Util_Test::UNKNOWN && $this->enforceTimeLimit && extension_loaded('pcntl') && class_exists('PHP_Invoker')) { switch ($test->getSize()) { case PHPUnit_Util_Test::SMALL: $_timeout = $this->timeoutForSmallTests; break; case PHPUnit_Util_Test::MEDIUM: $_timeout = $this->timeoutForMediumTests; break; case PHPUnit_Util_Test::LARGE: $_timeout = $this->timeoutForLargeTests; break; } $invoker = new PHP_Invoker(); $invoker->invoke([$test, 'runBare'], [], $_timeout); } else { $test->runBare(); } } catch (PHPUnit_Framework_MockObject_Exception $e) { $e = new PHPUnit_Framework_Warning($e->getMessage()); $warning = true; } catch (PHPUnit_Framework_AssertionFailedError $e) { $failure = true; if ($e instanceof PHPUnit_Framework_RiskyTestError) { $risky = true; } elseif ($e instanceof PHPUnit_Framework_IncompleteTestError) { $incomplete = true; } elseif ($e instanceof PHPUnit_Framework_SkippedTestError) { $skipped = true; } } catch (AssertionError $e) { $test->addToAssertionCount(1); $failure = true; $frame = $e->getTrace()[0]; $e = new PHPUnit_Framework_AssertionFailedError(sprintf('%s in %s:%s', $e->getMessage(), $frame['file'], $frame['line'])); } catch (PHPUnit_Framework_Warning $e) { $warning = true; } catch (PHPUnit_Framework_Exception $e) { $error = true; } catch (Throwable $e) { $e = new PHPUnit_Framework_ExceptionWrapper($e); $error = true; } $time = PHP_Timer::stop(); $test->addToAssertionCount(PHPUnit_Framework_Assert::getCount()); if ($monitorFunctions) { $blacklist = new PHPUnit_Util_Blacklist(); $functions = xdebug_get_monitored_functions(); xdebug_stop_function_monitor(); foreach ($functions as $function) { if (!$blacklist->isBlacklisted($function['filename'])) { $this->addFailure($test, new PHPUnit_Framework_RiskyTestError(sprintf('%s() used in %s:%s', $function['function'], $function['filename'], $function['lineno'])), $time); } } } if ($this->beStrictAboutTestsThatDoNotTestAnything && $test->getNumAssertions() == 0) { $risky = true; } if ($collectCodeCoverage) { $append = !$risky && !$incomplete && !$skipped; $linesToBeCovered = []; $linesToBeUsed = []; if ($append && $test instanceof PHPUnit_Framework_TestCase) { try { $linesToBeCovered = PHPUnit_Util_Test::getLinesToBeCovered(get_class($test), $test->getName(false)); $linesToBeUsed = PHPUnit_Util_Test::getLinesToBeUsed(get_class($test), $test->getName(false)); } catch (PHPUnit_Framework_InvalidCoversTargetException $cce) { $this->addWarning($test, new PHPUnit_Framework_Warning($cce->getMessage()), $time); } } try { $this->codeCoverage->stop($append, $linesToBeCovered, $linesToBeUsed); } catch (UnintentionallyCoveredCodeException $cce) { $this->addFailure($test, new PHPUnit_Framework_UnintentionallyCoveredCodeError('This test executed code that is not listed as code to be covered or used:' . PHP_EOL . $cce->getMessage()), $time); } catch (CoveredCodeNotExecutedException $cce) { $this->addFailure($test, new PHPUnit_Framework_CoveredCodeNotExecutedException('This test did not execute all the code that is listed as code to be covered:' . PHP_EOL . $cce->getMessage()), $time); } catch (MissingCoversAnnotationException $cce) { if ($linesToBeCovered !== false) { $this->addFailure($test, new PHPUnit_Framework_MissingCoversAnnotationException('This test does not have a @covers annotation but is expected to have one'), $time); } } catch (CodeCoverageException $cce) { $error = true; if (!isset($e)) { $e = $cce; } } } if ($errorHandlerSet === true) { restore_error_handler(); } if ($error === true) { $this->addError($test, $e, $time); } elseif ($failure === true) { $this->addFailure($test, $e, $time); } elseif ($warning === true) { $this->addWarning($test, $e, $time); } elseif ($this->beStrictAboutTestsThatDoNotTestAnything && !$test->doesNotPerformAssertions() && $test->getNumAssertions() == 0) { $this->addFailure($test, new PHPUnit_Framework_RiskyTestError('This test did not perform any assertions'), $time); } elseif ($this->beStrictAboutOutputDuringTests && $test->hasOutput()) { $this->addFailure($test, new PHPUnit_Framework_OutputError(sprintf('This test printed output: %s', $test->getActualOutput())), $time); } elseif ($this->beStrictAboutTodoAnnotatedTests && $test instanceof PHPUnit_Framework_TestCase) { $annotations = $test->getAnnotations(); if (isset($annotations['method']['todo'])) { $this->addFailure($test, new PHPUnit_Framework_RiskyTestError('Test method is annotated with @todo'), $time); } } $this->endTest($test, $time); }
/** * A failure occurred. * * @param PHPUnit_Framework_Test $test * @param PHPUnit_Framework_AssertionFailedError $e * @param float $time */ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { $this->_messages[] = "Test FAILED: " . $test->getName() . ": " . $e->getMessage(); }
/** * A failure occurred. * * @param PHPUnit_Framework_Test $test * @param PHPUnit_Framework_AssertionFailedError $e * @param float $time */ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { $this->log->err(sprintf('Test "%s" failed: %s', $test->getName(), $e->getMessage())); }
/** * Adds the failure detail to the current test and increases the failure * count for the current suite * * @access public * @param obj PHPUnit_Framework_Test, current test that is being run * @param obj PHPUnit_Framework_AssertationFailedError, PHPUnit error * @return void */ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { $this->currentSuite['failures']++; $this->currentTest['status'] = TEST_FAILURE; $this->currentTest['message'] = $e->toString(); $this->currentTest['exception'] = $this->getTestException($test, $e); $this->currentTest['trace'] = $e->getTrace(); }
/** * A failure occurred. * * @param \PHPUnit_Framework_Test $test * @param \PHPUnit_Framework_AssertionFailedError $e * @param float $time * * @return void */ public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time) { $testName = $test->getName(); $context = array('testName' => $testName, 'testDescriptionArr' => \PHPUnit_Util_Test::describe($test, false), 'testDescriptionStr' => $test->toString(), 'operation' => __FUNCTION__, 'reason' => $e->getMessage(), 'trace' => \PHPUnit_Util_Filter::getFilteredStacktrace($e, false)); $this->logger->error(sprintf("Test '%s' failed.", $testName), $context); }
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { $this->addTestResult($test, 'Failure [' . $e->toString() .']'); }
/** * A failure occurred. * * @param PHPUnit_Framework_Test $test * @param PHPUnit_Framework_AssertionFailedError $e * @param float $time */ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { $this->lastFailureMessage = "Test FAILURE (" . $test->getName() . "): " . $e->getMessage(); }
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { $this->logger->write('Failed: ' . $e->getMessage()); $this->tests_failed++; }
public function __construct($message, PHPUnit_Framework_ComparisonFailure $comparisonFailure = NULL) { $this->comparisonFailure = $comparisonFailure; parent::__construct($message); }
/** * 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; }
/** * A failure occurred. * * @param PHPUnit_Framework_Test $test * @param PHPUnit_Framework_AssertionFailedError $e * @param float $time */ public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time) { $this->failures[$test->toString()] = $e->getMessage(); parent::addFailure($test, $e, $time); }
public function __construct($message, SebastianBergmann\Comparator\ComparisonFailure $comparisonFailure = null, Exception $previous = null) { $this->comparisonFailure = $comparisonFailure; parent::__construct($message, 0, $previous); }
/** * 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>'); } } }
/** * Runs the bare test sequence. */ public function runBare() { $this->numAssertions = 0; $this->snapshotGlobalState(); $this->startOutputBuffering(); clearstatcache(); $currentWorkingDirectory = getcwd(); $hookMethods = PHPUnit_Util_Test::getHookMethods(get_class($this)); try { $hasMetRequirements = false; $this->checkRequirements(); $hasMetRequirements = true; if ($this->inIsolation) { foreach ($hookMethods['beforeClass'] as $method) { $this->{$method}(); } } $this->setExpectedExceptionFromAnnotation(); foreach ($hookMethods['before'] as $method) { $this->{$method}(); } $this->assertPreConditions(); $this->testResult = $this->runTest(); $this->verifyMockObjects(); $this->assertPostConditions(); $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_PASSED; } catch (PHPUnit_Framework_IncompleteTest $e) { $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE; $this->statusMessage = $e->getMessage(); } catch (PHPUnit_Framework_SkippedTest $e) { $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED; $this->statusMessage = $e->getMessage(); } catch (PHPUnit_Framework_AssertionFailedError $e) { $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE; $this->statusMessage = $e->getMessage(); } catch (PredictionException $e) { $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE; $this->statusMessage = $e->getMessage(); } catch (Exception $e) { $this->status = PHPUnit_Runner_BaseTestRunner::STATUS_ERROR; $this->statusMessage = $e->getMessage(); } // Clean up the mock objects. $this->mockObjects = array(); $this->prophet = null; // Tear down the fixture. An exception raised in tearDown() will be // caught and passed on when no exception was raised before. try { if ($hasMetRequirements) { foreach ($hookMethods['after'] as $method) { $this->{$method}(); } if ($this->inIsolation) { foreach ($hookMethods['afterClass'] as $method) { $this->{$method}(); } } } } catch (Exception $_e) { if (!isset($e)) { $e = $_e; } } try { $this->stopOutputBuffering(); } catch (PHPUnit_Framework_RiskyTestError $_e) { if (!isset($e)) { $e = $_e; } } clearstatcache(); if ($currentWorkingDirectory != getcwd()) { chdir($currentWorkingDirectory); } $this->restoreGlobalState(); // Clean up INI settings. foreach ($this->iniSettings as $varName => $oldValue) { ini_set($varName, $oldValue); } $this->iniSettings = array(); // Clean up locale settings. foreach ($this->locale as $category => $locale) { setlocale($category, $locale); } // Perform assertion on output. if (!isset($e)) { try { if ($this->outputExpectedRegex !== null) { $this->assertRegExp($this->outputExpectedRegex, $this->output); } elseif ($this->outputExpectedString !== null) { $this->assertEquals($this->outputExpectedString, $this->output); } } catch (Exception $_e) { $e = $_e; } } // Workaround for missing "finally". if (isset($e)) { if ($e instanceof PredictionException) { $e = new PHPUnit_Framework_AssertionFailedError($e->getMessage()); } $this->onNotSuccessfulTest($e); } }
public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { $name = strpos($test->getName(), '::') ? $test->getName() : $this->current_test_suite . '::' . $test->getName(); $this->failed_tests[$name] = $e->toString(); }