* renamed TestCaseResult to CombinedTestResult since TestSuite needs to use it as well
* other changes
This commit is contained in:
parent
801403b3f1
commit
b9dae617f6
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class TestCaseResult implements TestResult {
|
||||
class CombinedCaseResult implements TestResult {
|
||||
|
||||
protected $testResults;
|
||||
|
||||
@ -17,18 +17,20 @@
|
||||
}
|
||||
|
||||
public function count() {
|
||||
return count($this->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)) {
|
@ -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));
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user