diff --git a/TestCaseResult.php b/CombinedTestResult.php similarity index 79% rename from TestCaseResult.php rename to CombinedTestResult.php index 1487478..8918a0e 100644 --- a/TestCaseResult.php +++ b/CombinedTestResult.php @@ -1,6 +1,6 @@ testResults); + return count($this->getAllTestResults()); } public function addTestResult(TestResult $result) { $this->testResults[] = $result; } - public function getTestResults() { + public function getAllTestResults() { + //use a recursive iterator here... return $this->testResults; } public function getPassedTestResults() { + //use a recursive iterator here... $passedTests = array(); foreach ($this->testResults as $testResult) { if ($testResult instanceof PassedTestResult) { @@ -40,6 +42,7 @@ } public function getFailedTestResults() { + //use a recursive iterator here... $failedTests = array(); foreach ($this->testResults as $testResult) { if (!($testResult instanceof PassedTestResult)) { diff --git a/TestCase.php b/TestCase.php index a403c68..e04f371 100644 --- a/TestCase.php +++ b/TestCase.php @@ -21,7 +21,7 @@ $listener->onBeforeTestCase($this); } - $result = new TestCaseResult(); + $result = new CombinedTestResult(); foreach ($this->getTestableMethods() as $method) { $testMethod = new TestMethod($this, $method); $result->addTestResult($testMethod->run($listeners)); diff --git a/TestRunner.php b/TestRunner.php index 941bb52..b5b401c 100644 --- a/TestRunner.php +++ b/TestRunner.php @@ -3,11 +3,9 @@ class TestRunner { protected $tests; - protected $name; protected $listeners; - public function __construct($name, array $tests, array $listeners = array()) { - $this->name = $name; + public function __construct(array $tests, array $listeners = array()) { $this->tests = $tests; $this->listeners = $listeners; } @@ -22,16 +20,19 @@ return $this; } - public function run() { + public function runTests() { + $results = array(); foreach ($this->tests as $test) { if ($test instanceof Testable) { - $test->run($this->listeners); + $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) . ')'); } } } + + return $results; } } diff --git a/TestSuite.php b/TestSuite.php index 4f74c41..65ab81b 100644 --- a/TestSuite.php +++ b/TestSuite.php @@ -6,7 +6,7 @@ protected $tests; public function __construct($name, array $tests) { - $this->name = $name; + $this->name = $name; $this->tests = $tests; } @@ -18,28 +18,35 @@ } + public function addTest(Testable $test) { + $this->tests[] = $test; + return $this; + } + public function run(array $listeners) { + foreach ($listeners as $listener) { + $listener->beforeTestSuite($this); + } + + $result = new CombinedTestResult(); + $this->setUp(); foreach ($this->tests as $test) { - if ($test instanceof self) { - foreach ($this->listeners as $listener) { - $listener->beforeTestSuite($test); - } - - $result = $test->run($listeners); - - foreach ($this->listeners as $listener) { - $listener->afterTestSuite($test); - } - } else if ($test instanceof TestCase) { - $test->run($listeners); + if ($test instanceof Testable) { + $result->addTestResult($test->run($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) . ')'); } } } $this->tearDown(); + + foreach ($listeners as $listener) { + $listener->afterTestSuite($this); + } + + return $result; } }