'; $output .= '

Test run: '.date('d.m.Y H:i').'

'; foreach(get_class_methods(get_class($this)) as $method) { if (preg_match('#^test.*#', $method)) { $ok = true; try { $result = $this->$method(); } catch (TestFailedException $tfex) { $result = $tfex->getMessage(); $ok = false; } if ($ok) $output .= $method.': OK ('.$result.')
'; else $output .= $method.': FAILED ('.$result.')
'; } } $output .= ''; file_put_contents('result/test.'.get_class($this).'.'.$this->getTestName().'.html', $output); } public final function assert($condition, $comment = '') { if ($condition) return; $pos = debug_backtrace(); $fail = new stdClass(); $fail->test = $pos[1]['function']; $fail->comment = $comment; $this->fails[] = $fail; $this->checkcount++; } public function getFails() { return $this->fails; } public function cleanup() { } public final function doTests() { $this->init(); try { $this->run(); } catch (Exception $ex) { echo get_class($ex).':'.$ex->getMessage(); echo '
';
				echo $ex->getTraceAsString();
				echo '
'; } $this->cleanup(); } } final class TestSuite { private $tests = array(); private $name; public function __construct($name) { $this->name = $name; } public function addTest(Test $test) { $this->tests[] = $test; } public function run() { $s = ''; foreach ($this->tests as $test) { $s .= '
'; $s .= '

'.$test->getTestName().'

'; try { $test->doTests(); $s .= '

Test completed. Results

'; } catch (TestFailedException $tfex) { $s .= '

Test failed: '.$tfex->getMessage().'

'; } foreach($test->getFails() as $fail) { $s .= "Test: {$fail->test}
\n"; $s .= "Comment: {$fail->comment}
\n"; } } $s .= ''; file_put_contents('result/tests.'.$this->name.'.html', $s); } }