protected function assertTestsAreSuccessful(PHPUnit_Framework_TestResult $result) { if ($result->wasSuccessful()) { return; } $msg = "Test should pass, instead there are {$result->errorCount()} errors:\n"; /** @var $error PHPUnit_Framework_TestFailure */ foreach ($result->errors() as $error) { $msg .= $error->exceptionMessage(); } $this->fail($msg); }
/** * 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 */ protected function printErrors(PHPUnit_Framework_TestResult $result) { $this->printDefects($result->errors(), $result->errorCount(), 'error'); }
/** * @param PHPUnit_Framework_Test $test * @param PHPUnit_Framework_TestResult $result * @return mixed */ public static function lookupResult(PHPUnit_Framework_Test $test, PHPUnit_Framework_TestResult $result) { $testName = self::describe($test); foreach ($result->errors() as $error) { if ($testName == self::describe($error->failedTest())) { return $error; } } foreach ($result->failures() as $failure) { if ($testName == self::describe($failure->failedTest())) { return $failure; } } foreach ($result->notImplemented() as $notImplemented) { if ($testName == self::describe($notImplemented->failedTest())) { return $notImplemented; } } foreach ($result->skipped() as $skipped) { if ($testName == self::describe($skipped->failedTest())) { return $skipped; } } return PHPUnit_Runner_BaseTestRunner::STATUS_PASSED; }
/** * 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]; }
/** * Asserts that the given result belongs to a test that was * executed successfully. * * @param PHPUnit_Framework_TestResult $result */ protected function assertSuccessful(PHPUnit_Framework_TestResult $result) { $message = ''; foreach ($result->errors() as $error) { /* @var $error PHPUnit_Framework_TestFailure */ $message .= $error->getExceptionAsString() . PHP_EOL; } foreach ($result->failures() as $failure) { /* @var $failure PHPUnit_Framework_TestFailure */ $message .= $failure->getExceptionAsString() . PHP_EOL; } $this->assertTrue($result->wasSuccessful(), $message); }