本文整理汇总了PHP中PHPUnit_Framework_TestResult::passed方法的典型用法代码示例。如果您正苦于以下问题:PHP PHPUnit_Framework_TestResult::passed方法的具体用法?PHP PHPUnit_Framework_TestResult::passed怎么用?PHP PHPUnit_Framework_TestResult::passed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPUnit_Framework_TestResult
的用法示例。
在下文中一共展示了PHPUnit_Framework_TestResult::passed方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: paintFooter
/**
* 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();
}
示例2: paintFooter
/**
* 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();
}
示例3: parseTestSuite
/**
* 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];
}
示例4: fromPHPUnitTestResult
/**
* 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;
}
示例5: handleDependencies
/**
* @since Method available since Release 3.5.4
*/
protected function handleDependencies()
{
if (!empty($this->dependencies) && !$this->inIsolation) {
$className = get_class($this);
$passed = $this->result->passed();
$passedKeys = array_keys($passed);
$numKeys = count($passedKeys);
for ($i = 0; $i < $numKeys; $i++) {
$pos = strpos($passedKeys[$i], ' with data set');
if ($pos !== false) {
$passedKeys[$i] = substr($passedKeys[$i], 0, $pos);
}
}
$passedKeys = array_flip(array_unique($passedKeys));
foreach ($this->dependencies as $dependency) {
if (strpos($dependency, '::') === false) {
$dependency = $className . '::' . $dependency;
}
if (!isset($passedKeys[$dependency])) {
$this->result->addError($this, new PHPUnit_Framework_SkippedTestError(sprintf('This test depends on "%s" to pass.', $dependency)), 0);
return false;
}
if (isset($passed[$dependency])) {
if ($passed[$dependency]['size'] > $this->getSize()) {
$this->result->addError($this, new PHPUnit_Framework_SkippedTestError('This test depends on a test that is larger than itself.'), 0);
return false;
}
$this->dependencyInput[$dependency] = $passed[$dependency]['result'];
} else {
$this->dependencyInput[$dependency] = null;
}
}
}
return true;
}
示例6: run
/**
* Runs the test case and collects the results in a TestResult object.
* If no TestResult object is passed a new one will be created.
*
* @param PHPUnit_Framework_TestResult $result
* @return PHPUnit_Framework_TestResult
* @throws InvalidArgumentException
*/
public function run(PHPUnit_Framework_TestResult $result = NULL)
{
if ($result === NULL) {
$result = $this->createResult();
}
$this->setExpectedExceptionFromAnnotation();
$this->setUseErrorHandlerFromAnnotation();
$this->setUseOutputBufferingFromAnnotation();
if ($this->useErrorHandler !== NULL) {
$oldErrorHandlerSetting = $result->getConvertErrorsToExceptions();
$result->convertErrorsToExceptions($this->useErrorHandler);
}
$this->result = $result;
if (!empty($this->dependencies) && !$this->inIsolation) {
$className = get_class($this);
$passed = $this->result->passed();
$passedKeys = array_keys($passed);
$numKeys = count($passedKeys);
for ($i = 0; $i < $numKeys; $i++) {
$pos = strpos($passedKeys[$i], ' with data set');
if ($pos !== FALSE) {
$passedKeys[$i] = substr($passedKeys[$i], 0, $pos);
}
}
$passedKeys = array_flip(array_unique($passedKeys));
foreach ($this->dependencies as $dependency) {
if (strpos($dependency, '::') === FALSE) {
$dependency = $className . '::' . $dependency;
}
if (!isset($passedKeys[$dependency])) {
$result->addError($this, new PHPUnit_Framework_SkippedTestError(sprintf('This test depends on "%s" to pass.', $dependency)), 0);
return;
} else {
if (isset($passed[$dependency])) {
$this->dependencyInput[] = $passed[$dependency];
} else {
$this->dependencyInput[] = NULL;
}
}
}
}
if ($this->runTestInSeparateProcess === TRUE && $this->inIsolation !== TRUE && !$this instanceof PHPUnit_Extensions_SeleniumTestCase && !$this instanceof PHPUnit_Extensions_PhptTestCase) {
$class = new ReflectionClass($this);
$collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
$template = new PHPUnit_Util_Template(sprintf('%s%sProcess%sTestCaseMethod.tpl', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
$template->setVar(array('filename' => $class->getFileName(), 'className' => $class->getName(), 'methodName' => $this->name, 'data' => addcslashes(serialize($this->data), "'"), 'dependencyInput' => addcslashes(serialize($this->dependencyInput), "'"), 'dataName' => $this->dataName, 'collectCodeCoverageInformation' => $collectCodeCoverageInformation ? 'TRUE' : 'FALSE', 'included_files' => $this->preserveGlobalState ? PHPUnit_Util_GlobalState::getIncludedFilesAsString() : '', 'constants' => $this->preserveGlobalState ? PHPUnit_Util_GlobalState::getConstantsAsString() : '', 'globals' => $this->preserveGlobalState ? PHPUnit_Util_GlobalState::getGlobalsAsString() : '', 'include_path' => addslashes(get_include_path())));
$this->prepareTemplate($template);
$job = $template->render();
$result->startTest($this);
$jobResult = PHPUnit_Util_PHP::runJob($job);
if (!empty($jobResult['stderr'])) {
$time = 0;
$result->addError($this, new RuntimeException(trim($jobResult['stderr'])), $time);
} else {
$childResult = @unserialize($jobResult['stdout']);
if ($childResult !== FALSE) {
if (!empty($childResult['output'])) {
print $childResult['output'];
}
$this->testResult = $childResult['testResult'];
$this->numAssertions = $childResult['numAssertions'];
$childResult = $childResult['result'];
if ($collectCodeCoverageInformation) {
$codeCoverageInformation = $childResult->getRawCodeCoverageInformation();
$result->appendCodeCoverageInformation($this, $codeCoverageInformation[0]['data']);
}
$time = $childResult->time();
$notImplemented = $childResult->notImplemented();
$skipped = $childResult->skipped();
$errors = $childResult->errors();
$failures = $childResult->failures();
if (!empty($notImplemented)) {
$result->addError($this, $notImplemented[0]->thrownException(), $time);
} else {
if (!empty($skipped)) {
$result->addError($this, $skipped[0]->thrownException(), $time);
} else {
if (!empty($errors)) {
$result->addError($this, $errors[0]->thrownException(), $time);
} else {
if (!empty($failures)) {
$result->addFailure($this, $failures[0]->thrownException(), $time);
}
}
}
}
} else {
$time = 0;
$result->addError($this, new RuntimeException(trim($jobResult['stdout'])), $time);
}
}
$result->endTest($this, $time);
//.........这里部分代码省略.........
示例7: run
/**
* Runs the test case and collects the results in a TestResult object.
* If no TestResult object is passed a new one will be created.
*
* @param PHPUnit_Framework_TestResult $result
* @return PHPUnit_Framework_TestResult
* @throws InvalidArgumentException
*/
public function run(PHPUnit_Framework_TestResult $result = NULL)
{
if ($result === NULL) {
$result = $this->createResult();
}
$this->setExpectedExceptionFromAnnotation();
$this->setUseErrorHandlerFromAnnotation();
$this->setUseOutputBufferingFromAnnotation();
if ($this->useErrorHandler !== NULL) {
$oldErrorHandlerSetting = $result->getConvertErrorsToExceptions();
$result->convertErrorsToExceptions($this->useErrorHandler);
}
$this->result = $result;
if (!empty($this->dependencies) && !$this->inIsolation) {
$className = get_class($this);
$passed = $this->result->passed();
$passedKeys = array_keys($passed);
$numKeys = count($passedKeys);
for ($i = 0; $i < $numKeys; $i++) {
$pos = strpos($passedKeys[$i], ' with data set');
if ($pos !== FALSE) {
$passedKeys[$i] = substr($passedKeys[$i], 0, $pos);
}
}
$passedKeys = array_flip(array_unique($passedKeys));
foreach ($this->dependencies as $dependency) {
if (strpos($dependency, '::') === FALSE) {
$dependency = $className . '::' . $dependency;
}
if (!isset($passedKeys[$dependency])) {
$result->addError($this, new PHPUnit_Framework_SkippedTestError(sprintf('This test depends on "%s" to pass.', $dependency)), 0);
return;
} else {
if (isset($passed[$dependency])) {
$this->dependencyInput[] = $passed[$dependency];
} else {
$this->dependencyInput[] = NULL;
}
}
}
}
if ($this->runTestInSeparateProcess === TRUE && $this->inIsolation !== TRUE && !$this instanceof PHPUnit_Extensions_SeleniumTestCase && !$this instanceof PHPUnit_Extensions_PhptTestCase) {
$class = new ReflectionClass($this);
$template = new Text_Template(sprintf('%s%sProcess%sTestCaseMethod.tpl', dirname(__FILE__), DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
if ($this->preserveGlobalState) {
$constants = PHPUnit_Util_GlobalState::getConstantsAsString();
$globals = PHPUnit_Util_GlobalState::getGlobalsAsString();
$includedFiles = PHPUnit_Util_GlobalState::getIncludedFilesAsString();
} else {
$constants = '';
$globals = '';
$includedFiles = '';
}
if ($result->getCollectCodeCoverageInformation()) {
$coverage = 'TRUE';
} else {
$coverage = 'FALSE';
}
$data = addcslashes(serialize($this->data), "'");
$dependencyInput = addcslashes(serialize($this->dependencyInput), "'");
$includePath = addslashes(get_include_path());
$template->setVar(array('filename' => $class->getFileName(), 'className' => $class->getName(), 'methodName' => $this->name, 'collectCodeCoverageInformation' => $coverage, 'data' => $data, 'dataName' => $this->dataName, 'dependencyInput' => $dependencyInput, 'constants' => $constants, 'globals' => $globals, 'include_path' => $includePath, 'included_files' => $includedFiles));
$this->prepareTemplate($template);
PHPUnit_Util_PHP::runJob($template->render(), $this, $result);
} else {
$result->run($this);
}
if ($this->useErrorHandler !== NULL) {
$result->convertErrorsToExceptions($oldErrorHandlerSetting);
}
$this->result = NULL;
return $result;
}
示例8: handleDependencies
/**
* @since Method available since Release 3.5.4
*/
protected function handleDependencies()
{
if (!empty($this->dependencies) && !$this->inIsolation) {
$className = get_class($this);
$passed = $this->result->passed();
$passedKeys = array_keys($passed);
$numKeys = count($passedKeys);
for ($i = 0; $i < $numKeys; $i++) {
$pos = strpos($passedKeys[$i], ' with data set');
if ($pos !== FALSE) {
$passedKeys[$i] = substr($passedKeys[$i], 0, $pos);
}
}
$passedKeys = array_flip(array_unique($passedKeys));
foreach ($this->dependencies as $dependency) {
if (strpos($dependency, '::') === FALSE) {
$dependency = $className . '::' . $dependency;
}
if (!isset($passedKeys[$dependency])) {
$this->result->addError(
$this,
new PHPUnit_Framework_SkippedTestError(
sprintf(
'This test depends on "%s" to pass.', $dependency
)
),
0
);
return FALSE;
} else {
if (isset($passed[$dependency])) {
$this->dependencyInput[] = $passed[$dependency];
} else {
$this->dependencyInput[] = NULL;
}
}
}
}
return TRUE;
}
示例9: printResult
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);
}
示例10: run
public function run(PHPUnit_Framework_TestResult $result = NULL)
{
if (is_array($this->theDependencies) && count($this->theDependencies)) {
$className = get_class($this);
$passed = $result->passed();
$passedKeys = array_keys($passed);
foreach ($this->theDependencies as $dependency) {
$dependency = $className . '::' . $dependency;
if (in_array($dependency, $passedKeys)) {
$this->theDependencyInput[] = $passed[$dependency];
}
}
}
$ret = parent::run($result);
$testConfig = $this->config->get('config');
if ($testConfig->reportPath) {
$xml = new SimpleXMLElement('<test/>');
$xml->addAttribute('name', $this->getName());
$xml->addAttribute('status', $this->getStatus());
$xml->addAttribute('numAssertions', $this->getNumAssertions());
$xml->addAttribute('statusMessage', $this->getStatusMessage());
$resultElement = $xml->addChild('result');
$resultElement->addAttribute('returnedType', get_class($this->getResult()));
if ($result instanceof PHPUnit_Framework_TestResult) {
if ($result->errorCount()) {
$errorsElemnt = $resultElement->addChild('errors');
$errors = $result->errors();
foreach ($errors as $error) {
/* @var $error PHPUnit_Framework_TestFailure */
$errorElemnt = $errorsElemnt->addChild('error', $error->exceptionMessage());
}
}
if ($result->skippedCount()) {
$skippedsElemnt = $resultElement->addChild('skippeds');
$skippeds = $result->skipped();
foreach ($skippeds as $skipped) {
/* @var $skipped PHPUnit_Framework_TestFailure */
$skippedElemnt = $skippedsElemnt->addChild('skipped', $skipped->exceptionMessage());
}
}
if ($result->failureCount()) {
$failuresElemnt = $resultElement->addChild('failures');
$failures = $result->failures();
foreach ($failures as $failure) {
/* @var $failure PHPUnit_Framework_TestFailure */
$failureElemnt = $failuresElemnt->addChild('failure', $failure->exceptionMessage());
}
}
}
$fileName = $testConfig->reportPath . DIRECTORY_SEPARATOR . get_class($this) . '.' . $this->getName() . '.xml';
$xml->asXML($fileName);
}
return $ret;
}
示例11: print_passed_tests
/**
* @param PHPUnit_Framework_TestResult $result
*/
protected function print_passed_tests(PHPUnit_Framework_TestResult $result)
{
$passed = $result->passed();
foreach ($passed as $name => $unused) {
$this->print_passed_test($name);
}
}