2009-06-13 06:00:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class TestSuite implements Testable {
|
|
|
|
|
|
|
|
protected $name;
|
|
|
|
protected $tests;
|
|
|
|
|
|
|
|
public function __construct($name, array $tests) {
|
2009-06-13 06:41:48 +00:00
|
|
|
$this->name = $name;
|
2009-06-13 06:00:17 +00:00
|
|
|
$this->tests = $tests;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function setUp() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function tearDown() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-06-13 06:41:48 +00:00
|
|
|
public function addTest(Testable $test) {
|
|
|
|
$this->tests[] = $test;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2009-06-13 06:00:17 +00:00
|
|
|
public function run(array $listeners) {
|
2009-06-13 06:41:48 +00:00
|
|
|
foreach ($listeners as $listener) {
|
|
|
|
$listener->beforeTestSuite($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = new CombinedTestResult();
|
|
|
|
|
2009-06-13 06:00:17 +00:00
|
|
|
$this->setUp();
|
|
|
|
foreach ($this->tests as $test) {
|
2009-06-13 06:41:48 +00:00
|
|
|
if ($test instanceof Testable) {
|
|
|
|
$result->addTestResult($test->run($listeners));
|
2009-06-13 06:00:17 +00:00
|
|
|
} else {
|
|
|
|
foreach ($this->listeners as $listener) {
|
2009-06-13 06:41:48 +00:00
|
|
|
$listener->onFrameworkWarning('Unable to run test because it is not an instance of Testable (' . gettype($test) . ')');
|
2009-06-13 06:00:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->tearDown();
|
2009-06-13 06:41:48 +00:00
|
|
|
|
|
|
|
foreach ($listeners as $listener) {
|
|
|
|
$listener->afterTestSuite($this);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
2009-06-13 06:00:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|