From 035a5da679701e27c792888e7816c9abc614e74c Mon Sep 17 00:00:00 2001 From: tmont Date: Sat, 13 Jun 2009 22:41:24 +0000 Subject: [PATCH] result publishing: the beginnings --- src/TUnit/framework/TestRunner.php | 12 ++++++++- .../framework/constraints/Constraint.php | 8 +++--- .../framework/listeners/ConsoleListener.php | 2 +- .../framework/listeners/TestListener.php | 4 +++ .../framework/result/CombinedTestResult.php | 8 ++++++ .../framework/result/ErredTestResult.php | 14 +---------- .../framework/result/FailedTestResult.php | 14 +---------- .../framework/result/IgnoredTestResult.php | 14 +---------- .../framework/result/SingleTestResult.php | 25 +++++++++++++++++++ src/TUnit/framework/result/TestResult.php | 2 ++ src/TUnit/framework/test/TestMethod.php | 4 +-- src/TUnit/manifest.php | 3 ++- src/TUnit/util/entry_console.php | 2 +- 13 files changed, 63 insertions(+), 49 deletions(-) create mode 100644 src/TUnit/framework/result/SingleTestResult.php diff --git a/src/TUnit/framework/TestRunner.php b/src/TUnit/framework/TestRunner.php index 84b490a..874314f 100644 --- a/src/TUnit/framework/TestRunner.php +++ b/src/TUnit/framework/TestRunner.php @@ -27,7 +27,7 @@ $results[] = $test->run($this->listeners); } else { 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; } + public function publishResults(array $testResults) { + foreach ($testResults as $testResult) { + $testResult->publish($this->listeners); + } + } + + public function runAndPublish() { + $this->publishResults($this->runTests()); + } + } ?> \ No newline at end of file diff --git a/src/TUnit/framework/constraints/Constraint.php b/src/TUnit/framework/constraints/Constraint.php index c977d46..c36d185 100644 --- a/src/TUnit/framework/constraints/Constraint.php +++ b/src/TUnit/framework/constraints/Constraint.php @@ -10,10 +10,6 @@ $this->actual = $actual; } - public abstract function evaluate(); - - protected abstract function getFailureMessage(); - public function fail($message = '') { throw new FailedTest($this->toString($message)); } @@ -24,6 +20,10 @@ return $message; } + public abstract function evaluate(); + + protected abstract function getFailureMessage(); + } ?> \ No newline at end of file diff --git a/src/TUnit/framework/listeners/ConsoleListener.php b/src/TUnit/framework/listeners/ConsoleListener.php index 7812b13..2a1a19c 100644 --- a/src/TUnit/framework/listeners/ConsoleListener.php +++ b/src/TUnit/framework/listeners/ConsoleListener.php @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/src/TUnit/framework/result/CombinedTestResult.php b/src/TUnit/framework/result/CombinedTestResult.php index ea2d49d..84d1cd1 100644 --- a/src/TUnit/framework/result/CombinedTestResult.php +++ b/src/TUnit/framework/result/CombinedTestResult.php @@ -53,6 +53,14 @@ return $failedTests; } + public function publish(array $listeners) { + foreach ($this->getAllTestResults() as $result) { + foreach ($listeners as $listener) { + $listener->publishTestResult($result); + } + } + } + } ?> \ No newline at end of file diff --git a/src/TUnit/framework/result/ErredTestResult.php b/src/TUnit/framework/result/ErredTestResult.php index d1710e6..a051f95 100644 --- a/src/TUnit/framework/result/ErredTestResult.php +++ b/src/TUnit/framework/result/ErredTestResult.php @@ -1,14 +1,6 @@ test = $test; - $this->failure = $failure; - } + class ErredTestResult extends SingleTestResult { public function passed() { return false; @@ -18,10 +10,6 @@ return true; } - public function count() { - return 1; - } - } ?> \ No newline at end of file diff --git a/src/TUnit/framework/result/FailedTestResult.php b/src/TUnit/framework/result/FailedTestResult.php index e89e1c3..3d4a8e3 100644 --- a/src/TUnit/framework/result/FailedTestResult.php +++ b/src/TUnit/framework/result/FailedTestResult.php @@ -1,14 +1,6 @@ test = $test; - $this->failure = $failure; - } + class FailedTestResult extends SingleTestResult { public function passed() { return false; @@ -18,10 +10,6 @@ return true; } - public function count() { - return 1; - } - } ?> \ No newline at end of file diff --git a/src/TUnit/framework/result/IgnoredTestResult.php b/src/TUnit/framework/result/IgnoredTestResult.php index af035c2..a288dff 100644 --- a/src/TUnit/framework/result/IgnoredTestResult.php +++ b/src/TUnit/framework/result/IgnoredTestResult.php @@ -1,14 +1,6 @@ test = $test; - $this->failure = $failure; - } + class IgnoredTestResult extends SingleTestResult { public function passed() { return false; @@ -18,10 +10,6 @@ return false; } - public function count() { - return 1; - } - } ?> \ No newline at end of file diff --git a/src/TUnit/framework/result/SingleTestResult.php b/src/TUnit/framework/result/SingleTestResult.php new file mode 100644 index 0000000..af8efb7 --- /dev/null +++ b/src/TUnit/framework/result/SingleTestResult.php @@ -0,0 +1,25 @@ +test = $test; + $this->failure = $failure; + } + + public function count() { + return 1; + } + + public function publish(array $listeners) { + foreach ($listeners as $listener) { + $listener->publishTestResult($this); + } + } + + } + +?> \ No newline at end of file diff --git a/src/TUnit/framework/result/TestResult.php b/src/TUnit/framework/result/TestResult.php index 93fa0c6..8fecfb5 100644 --- a/src/TUnit/framework/result/TestResult.php +++ b/src/TUnit/framework/result/TestResult.php @@ -6,6 +6,8 @@ public function failed(); + public function publish(array $listeners); + } ?> \ No newline at end of file diff --git a/src/TUnit/framework/test/TestMethod.php b/src/TUnit/framework/test/TestMethod.php index 6f6afbb..a2b8d86 100644 --- a/src/TUnit/framework/test/TestMethod.php +++ b/src/TUnit/framework/test/TestMethod.php @@ -15,8 +15,8 @@ $listener->beforeTestMethod($this); } - $result = null; - $failure = null; + $result = null; + $failure = null; $this->testCase->setUp(); try { diff --git a/src/TUnit/manifest.php b/src/TUnit/manifest.php index f7ead97..b12b833 100644 --- a/src/TUnit/manifest.php +++ b/src/TUnit/manifest.php @@ -3,7 +3,7 @@ /** * 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 * @version 0.1.0 @@ -27,6 +27,7 @@ 'IgnoredTest' => 'TUnit/framework/result/FailedTest.php', 'IgnoredTestResult' => 'TUnit/framework/result/IgnoredTestResult.php', 'PassedTestResult' => 'TUnit/framework/result/PassedTestResult.php', + 'SingleTestResult' => 'TUnit/framework/result/SingleTestResult.php', 'TestCase' => 'TUnit/framework/test/TestCase.php', 'TestFailure' => 'TUnit/framework/result/FailedTest.php', 'TestListener' => 'TUnit/framework/listeners/TestListener.php', diff --git a/src/TUnit/util/entry_console.php b/src/TUnit/util/entry_console.php index 5609994..2dbfafa 100644 --- a/src/TUnit/util/entry_console.php +++ b/src/TUnit/util/entry_console.php @@ -45,7 +45,7 @@ $runner = new TestRunner(array(new TestSuite('Main Test Suite', $tests)), array(new ConsoleListener())); - $runner->runTests(); + $runner->runAndPublish(); exit(0); ?> \ No newline at end of file