revamped results publishing
This commit is contained in:
parent
a2d6335740
commit
664b77c361
@ -10,12 +10,12 @@
|
||||
$this->listeners = $listeners;
|
||||
}
|
||||
|
||||
public function addTest(Testable $test) {
|
||||
public final function addTest(Testable $test) {
|
||||
$this->tests[] = $test;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function addListener(TestListener $listener) {
|
||||
public final function addListener(TestListener $listener) {
|
||||
$this->listeners[] = $listener;
|
||||
return $this;
|
||||
}
|
||||
@ -36,16 +36,17 @@
|
||||
}
|
||||
|
||||
public function publishResults(array $testResults) {
|
||||
foreach ($testResults as $testResult) {
|
||||
$testResult->publish($this->listeners);
|
||||
foreach ($this->listeners as $listener) {
|
||||
$listener->publishTestResults($testResults);
|
||||
}
|
||||
}
|
||||
|
||||
public function runAndPublish() {
|
||||
public function run() {
|
||||
self::printMeta();
|
||||
$this->publishResults($this->runTests());
|
||||
}
|
||||
|
||||
public function printMeta() {
|
||||
public static function printMeta() {
|
||||
fwrite(STDOUT, Product::NAME . ' ' . Product::VERSION . ' (build date: ' . Product::DATE . ')' . "\n");
|
||||
fwrite(STDOUT, ' by ' . Product::AUTHOR . "\n\n");
|
||||
}
|
||||
|
@ -195,6 +195,43 @@
|
||||
}
|
||||
}
|
||||
|
||||
public function publishTestResults($result) {
|
||||
if (is_array($result)) {
|
||||
$result = new CombinedTestResult($result);
|
||||
} else if ($result instanceof TestResult) {
|
||||
$result = new CombinedTestResult(array($result));
|
||||
}
|
||||
|
||||
if (!($result instanceof CombinedTestResult)) {
|
||||
throw new InvalidArgumentException('Could not convert $result to a CombinedTestResult');
|
||||
}
|
||||
|
||||
$passed = $result->getPassedTestResults();
|
||||
$failed = $result->getFailedTestResults();
|
||||
$erred = $result->getErredTestResults();
|
||||
$ignored = $result->getIgnoredTestResults();
|
||||
$total = count($passed) + count($failed) + count($erred) + count($ignored);
|
||||
|
||||
$countPad = strlen($total);
|
||||
|
||||
$width = 12 + $countPad + 3 + 6 + 3;
|
||||
|
||||
$this->out("\n");
|
||||
$this->out('+' . str_repeat('-', $width - 2) . '+' . "\n");
|
||||
$this->out('| Passed | ' . str_pad(count($passed), $countPad, ' ', STR_PAD_LEFT) . ' | ' . str_pad(number_format(round(count($passed) / $total * 100, 2), 2), 6, ' ', STR_PAD_LEFT) . '% |' . "\n");
|
||||
$this->out('+' . str_repeat('-', $width - 2) . '+' . "\n");
|
||||
$this->out('| Failed | ' . str_pad(count($failed), $countPad, ' ', STR_PAD_LEFT) . ' | ' . str_pad(number_format(round(count($failed) / $total * 100, 2), 2), 6, ' ', STR_PAD_LEFT) . '% |' . "\n");
|
||||
$this->out('+' . str_repeat('-', $width - 2) . '+' . "\n");
|
||||
$this->out('| Erred | ' . str_pad(count($erred), $countPad, ' ', STR_PAD_LEFT) . ' | ' . str_pad(number_format(round(count($erred) / $total * 100, 2), 2), 6, ' ', STR_PAD_LEFT) . '% |' . "\n");
|
||||
$this->out('+' . str_repeat('-', $width - 2) . '+' . "\n");
|
||||
$this->out('| Ignored | ' . str_pad(count($ignored), $countPad, ' ', STR_PAD_LEFT) . ' | ' . str_pad(number_format(round(count($ignored) / $total * 100, 2), 2), 6, ' ', STR_PAD_LEFT) . '% |' . "\n");
|
||||
$this->out('+' . str_repeat('-', $width - 2) . '+' . "\n");
|
||||
$this->out('+' . str_repeat('-', $width - 2) . '+' . "\n");
|
||||
$this->out('| Total | ' . $total . ' | ' . '100.00% |' . "\n");
|
||||
$this->out('+' . str_repeat('-', $width - 2) . '+' . "\n");
|
||||
$this->out("\n");
|
||||
}
|
||||
|
||||
public function publishTestResult(TestResult $result) {
|
||||
$failure = $result->getFailure();
|
||||
if ($failure instanceof TestFailure) {
|
||||
@ -203,7 +240,7 @@
|
||||
$this->out('Test name: ' . $result->getTest()->getName() . "\n");
|
||||
$this->out('Message: ' . $failure->getMessage() . "\n\n");
|
||||
$this->out($failure->getStackTrace());
|
||||
$this->out("\n");
|
||||
$this->out("-------------------------------\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,6 +62,10 @@
|
||||
|
||||
}
|
||||
|
||||
public function publishTestResults($result) {
|
||||
|
||||
}
|
||||
|
||||
public function publishTestResult(TestResult $result) {
|
||||
|
||||
}
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
protected $testResults;
|
||||
|
||||
public function __construct() {
|
||||
$this->testResults = array();
|
||||
public function __construct(array $results = array()) {
|
||||
$this->testResults = $results;
|
||||
}
|
||||
|
||||
public function passed() {
|
||||
@ -37,9 +37,8 @@
|
||||
}
|
||||
|
||||
public function getPassedTestResults() {
|
||||
//use a recursive iterator here...
|
||||
$passedTests = array();
|
||||
foreach ($this->testResults as $testResult) {
|
||||
foreach ($this->getAllTestResults() as $testResult) {
|
||||
if ($testResult instanceof PassedTestResult) {
|
||||
$passedTests[] = $testResult;
|
||||
}
|
||||
@ -49,10 +48,9 @@
|
||||
}
|
||||
|
||||
public function getFailedTestResults() {
|
||||
//use a recursive iterator here...
|
||||
$failedTests = array();
|
||||
foreach ($this->testResults as $testResult) {
|
||||
if (!($testResult instanceof PassedTestResult)) {
|
||||
foreach ($this->getAllTestResults() as $testResult) {
|
||||
if ($testResult instanceof FailedTestResult) {
|
||||
$failedTests[] = $testResult;
|
||||
}
|
||||
}
|
||||
@ -60,12 +58,26 @@
|
||||
return $failedTests;
|
||||
}
|
||||
|
||||
public function publish(array $listeners) {
|
||||
foreach ($this->getAllTestResults() as $result) {
|
||||
foreach ($listeners as $listener) {
|
||||
$listener->publishTestResult($result);
|
||||
public function getIgnoredTestResults() {
|
||||
$failedTests = array();
|
||||
foreach ($this->getAllTestResults() as $testResult) {
|
||||
if ($testResult instanceof IgnoredTestResult) {
|
||||
$failedTests[] = $testResult;
|
||||
}
|
||||
}
|
||||
|
||||
return $failedTests;
|
||||
}
|
||||
|
||||
public function getErredTestResults() {
|
||||
$failedTests = array();
|
||||
foreach ($this->getAllTestResults() as $testResult) {
|
||||
if ($testResult instanceof ErredTestResult) {
|
||||
$failedTests[] = $testResult;
|
||||
}
|
||||
}
|
||||
|
||||
return $failedTests;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -22,12 +22,6 @@
|
||||
return 1;
|
||||
}
|
||||
|
||||
public function publish(array $listeners) {
|
||||
foreach ($listeners as $listener) {
|
||||
$listener->publishTestResult($this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -6,8 +6,6 @@
|
||||
|
||||
public function failed();
|
||||
|
||||
public function publish(array $listeners);
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -47,7 +47,7 @@
|
||||
$refClass = new ReflectionClass($this);
|
||||
$methods = array();
|
||||
foreach ($refClass->getMethods() as $method) {
|
||||
if (preg_match('/^[\*\s]*@test\s*$/m', $method->getDocComment())) {
|
||||
if (preg_match('/^[\/\*\s]*@test\s*(?:\*\/)?$/m', $method->getDocComment())) {
|
||||
$methods[] = $method;
|
||||
}
|
||||
}
|
||||
|
@ -43,9 +43,8 @@
|
||||
}
|
||||
|
||||
|
||||
$runner = new TestRunner(array(new TestSuite('Main Test Suite', $tests)), array(new ConsoleListener()));
|
||||
$runner->printMeta();
|
||||
$runner->runAndPublish();
|
||||
$runner = new TestRunner(array(new TestSuite('Main Test Suite', $tests)), array(new ConsoleListener(/*ConsoleListener::VERBOSITY_HIGH*/)));
|
||||
$runner->run();
|
||||
exit(0);
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user