result publishing: the beginnings

This commit is contained in:
tmont 2009-06-13 22:41:24 +00:00
parent b519542d76
commit 035a5da679
13 changed files with 63 additions and 49 deletions

View File

@ -27,7 +27,7 @@
$results[] = $test->run($this->listeners); $results[] = $test->run($this->listeners);
} else { } else {
foreach ($this->listeners as $listener) { foreach ($this->listeners as $listener) {
$listener->onFrameworkWarning('Unable to run test because it is not an instanceof Testable (' . gettype($test) . ')'); $listener->onFrameworkWarning('Unable to run test because it is not an instance of Testable (' . gettype($test) . ')');
} }
} }
} }
@ -35,6 +35,16 @@
return $results; return $results;
} }
public function publishResults(array $testResults) {
foreach ($testResults as $testResult) {
$testResult->publish($this->listeners);
}
}
public function runAndPublish() {
$this->publishResults($this->runTests());
}
} }
?> ?>

View File

@ -10,10 +10,6 @@
$this->actual = $actual; $this->actual = $actual;
} }
public abstract function evaluate();
protected abstract function getFailureMessage();
public function fail($message = '') { public function fail($message = '') {
throw new FailedTest($this->toString($message)); throw new FailedTest($this->toString($message));
} }
@ -24,6 +20,10 @@
return $message; return $message;
} }
public abstract function evaluate();
protected abstract function getFailureMessage();
} }
?> ?>

View File

@ -1,6 +1,6 @@
<?php <?php
class ConsoleListener { class ConsoleListener extends TestListener {
private $verbosity; private $verbosity;
private $currentLineLength; private $currentLineLength;

View File

@ -62,6 +62,10 @@
} }
public function publishTestResult(TestResult $result) {
}
} }
?> ?>

View File

@ -53,6 +53,14 @@
return $failedTests; return $failedTests;
} }
public function publish(array $listeners) {
foreach ($this->getAllTestResults() as $result) {
foreach ($listeners as $listener) {
$listener->publishTestResult($result);
}
}
}
} }
?> ?>

View File

@ -1,14 +1,6 @@
<?php <?php
class ErredTestResult implements TestResult { class ErredTestResult extends SingleTestResult {
protected $test;
protected $failure;
public function __construct(Testable $test, TestFailure $failure) {
$this->test = $test;
$this->failure = $failure;
}
public function passed() { public function passed() {
return false; return false;
@ -18,10 +10,6 @@
return true; return true;
} }
public function count() {
return 1;
}
} }
?> ?>

View File

@ -1,14 +1,6 @@
<?php <?php
class FailedTestResult implements TestResult { class FailedTestResult extends SingleTestResult {
protected $test;
protected $failure;
public function __construct(Testable $test, TestFailure $failure) {
$this->test = $test;
$this->failure = $failure;
}
public function passed() { public function passed() {
return false; return false;
@ -18,10 +10,6 @@
return true; return true;
} }
public function count() {
return 1;
}
} }
?> ?>

View File

@ -1,14 +1,6 @@
<?php <?php
class IgnoredTestResult implements TestResult { class IgnoredTestResult extends SingleTestResult {
protected $test;
protected $failure;
public function __construct(Testable $test, TestFailure $failure) {
$this->test = $test;
$this->failure = $failure;
}
public function passed() { public function passed() {
return false; return false;
@ -18,10 +10,6 @@
return false; return false;
} }
public function count() {
return 1;
}
} }
?> ?>

View File

@ -0,0 +1,25 @@
<?php
abstract class SingleTestResult implements TestResult {
protected $test;
protected $failure;
public function __construct(Testable $test, TestFailure $failure) {
$this->test = $test;
$this->failure = $failure;
}
public function count() {
return 1;
}
public function publish(array $listeners) {
foreach ($listeners as $listener) {
$listener->publishTestResult($this);
}
}
}
?>

View File

@ -6,6 +6,8 @@
public function failed(); public function failed();
public function publish(array $listeners);
} }
?> ?>

View File

@ -3,7 +3,7 @@
/** /**
* Autoload manifest * Autoload manifest
* *
* Autogenerated by manifester.php on 2009-06-13 15:28:20 * Autogenerated by manifester.php on 2009-06-13 15:40:20
* *
* @package TUnit * @package TUnit
* @version 0.1.0 * @version 0.1.0
@ -27,6 +27,7 @@
'IgnoredTest' => 'TUnit/framework/result/FailedTest.php', 'IgnoredTest' => 'TUnit/framework/result/FailedTest.php',
'IgnoredTestResult' => 'TUnit/framework/result/IgnoredTestResult.php', 'IgnoredTestResult' => 'TUnit/framework/result/IgnoredTestResult.php',
'PassedTestResult' => 'TUnit/framework/result/PassedTestResult.php', 'PassedTestResult' => 'TUnit/framework/result/PassedTestResult.php',
'SingleTestResult' => 'TUnit/framework/result/SingleTestResult.php',
'TestCase' => 'TUnit/framework/test/TestCase.php', 'TestCase' => 'TUnit/framework/test/TestCase.php',
'TestFailure' => 'TUnit/framework/result/FailedTest.php', 'TestFailure' => 'TUnit/framework/result/FailedTest.php',
'TestListener' => 'TUnit/framework/listeners/TestListener.php', 'TestListener' => 'TUnit/framework/listeners/TestListener.php',

View File

@ -45,7 +45,7 @@
$runner = new TestRunner(array(new TestSuite('Main Test Suite', $tests)), array(new ConsoleListener())); $runner = new TestRunner(array(new TestSuite('Main Test Suite', $tests)), array(new ConsoleListener()));
$runner->runTests(); $runner->runAndPublish();
exit(0); exit(0);
?> ?>