Пример #1
0
 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";
 }
 /**
  * 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;
 }
Пример #3
0
 protected function onNotSuccessfulTest(\Exception $e)
 {
     if ($e instanceof PredictionException) {
         $e = new \PHPUnit_Framework_AssertionFailedError($e->getMessage(), $e->getCode(), $e);
     }
     return parent::onNotSuccessfulTest($e);
 }
Пример #4
0
    /**
     * 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");
 }
Пример #6
0
 /**
  * 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("{$message}" . "\n");
     } else {
         $this->write($message . "\n");
     }
     $this->lastTestFailed = TRUE;
 }
Пример #7
0
 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 "|";
     }
 }
 /**
  * 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;
     }
 }
Пример #9
0
 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();
 }
Пример #10
0
 public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
 {
     $this->error = true;
     echo self::TERM_RED, 'failed: ', $e->getMessage(), ' (took ', $time, 's).', self::TERM_END, "\n";
 }
 /**
  * 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)
 {
     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();
 }
 /**
  * Implement PHPUnit_Framework_TestListener, save driver content if there was an error
  * @param \PHPUnit_Framework_Test                 $test
  * @param \PHPUnit_Framework_AssertionFailedError $failure
  * @param integer                                 $time
  */
 public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $failure, $time)
 {
     if ($test instanceof Testcase_Spiderling and $test->is_driver_active() and $test->driver()->is_page_active()) {
         $this->save_driver_content($test->driver(), get_class($test) . '_' . $test->getName(FALSE), $failure->getMessage());
     }
 }
Пример #14
0
 /**
  * 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);
 }
Пример #15
0
 /**
  * Returns "..." in place of common prefix and "..." in
  * place of common suffix between expected and actual.
  *
  * @return string
  * @access public
  */
 public function toString()
 {
     if ($this->fExpected == null && $this->fActual == null) {
         return PHPUnit_Framework_Assert::format($this->fExpected, $this->fActual, parent::getMessage());
     }
     $end = min(strlen($this->fExpected), strlen($this->fActual));
     $i = 0;
     $j = strlen($this->fExpected) - 1;
     $k = strlen($this->fActual) - 1;
     for (; $i < $end; $i++) {
         if ($this->fExpected[$i] != $this->fActual[$i]) {
             break;
         }
     }
     for (; $k >= $i && $j >= $i; $k--, $j--) {
         if ($this->fExpected[$j] != $this->fActual[$k]) {
             break;
         }
     }
     if ($j < $i && $k < $i) {
         $expected = $this->fExpected;
         $actual = $this->fActual;
     } else {
         $expected = substr($this->fExpected, $i, $j + 1 - $i);
         $actual = substr($this->fActual, $i, $k + 1 - $i);
         if ($i <= $end && $i > 0) {
             $expected = '...' . $expected;
             $actual = '...' . $actual;
         }
         if ($j < strlen($this->fExpected) - 1) {
             $expected .= '...';
         }
         if ($k < strlen($this->fActual) - 1) {
             $actual .= '...';
         }
         return PHPUnit_Framework_Assert::format($expected, $actual, parent::getMessage());
     }
 }
Пример #16
0
 /**
  * A failure occurred.
  *
  * @param  PHPUnit_Framework_Test                 $test
  * @param  PHPUnit_Framework_AssertionFailedError $e
  * @param  float                                  $time
  * @access public
  */
 public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
 {
     $this->storeResult(PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE, $time, $e->getMessage());
     $this->currentTestSuccess = FALSE;
 }
Пример #17
0
 /**
  * Print message on failure
  *
  * @param PHPUnit_Framework_Test $test
  * @param PHPUnit_Framework_AssertionFailedError $e
  * @param integer $time
  */
 public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
 {
     echo $e->getMessage();
     printf("##teamcity[testFailed name='%s' details='See full log for details']\n", $test->getName());
 }
Пример #18
0
 public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time)
 {
     $this->logger->write('Failed: ' . $e->getMessage());
     $this->tests_failed++;
 }
Пример #19
0
 /**
  * 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()));
 }
Пример #20
0
 /**
  * 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);
 }
Пример #21
0
 /**
  * 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
  *
  * @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);
 }
Пример #23
0
 /**
  * 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);
     }
 }
Пример #24
0
 /**
  * @param \PHPUnit_Framework_Test $test
  * @param \PHPUnit_Framework_AssertionFailedError $e
  * @param $time
  * @return void
  */
 public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time)
 {
     echo "\t[";
     echo Colorize::text($e->getMessage(), "white", "red", true);
     echo "] ";
 }