fix minor db bugs, add preliminary unit testing
This commit is contained in:
60
simpletest/test.php
Executable file
60
simpletest/test.php
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/php
|
||||
<?
|
||||
class SimpleTest {
|
||||
protected function assert($boolean) {
|
||||
if (! $boolean) $this->fail();
|
||||
}
|
||||
|
||||
protected function fail($msg = '') {
|
||||
echo "FAILURE! $msg\n";
|
||||
debug_print_backtrace();
|
||||
die;
|
||||
}
|
||||
|
||||
public static function __listfiles($dir, $regex, $type='files', $rec = false) {
|
||||
$A = array();
|
||||
|
||||
if (! $dir_handler = @opendir($dir)) return $A;
|
||||
|
||||
while (false !== ($filename = @readdir($dir_handler))) {
|
||||
if ($filename == '.' || $filename == '..') continue;
|
||||
if ($rec && is_dir("$dir/$filename")) $A = array_merge($A, File::listfiles("$dir/$filename", $regex, $type, true));
|
||||
|
||||
if (! preg_match($regex, $filename)) continue;
|
||||
if ($type == 'files' && ! is_file("$dir/$filename")) continue;
|
||||
if ($type == 'dirs' && ! is_dir("$dir/$filename")) continue;
|
||||
if ($type == 'symlinks' && ! is_link("$dir/$filename")) continue;
|
||||
|
||||
$A[] = "$dir/$filename";
|
||||
}
|
||||
return $A;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
$files = SimpleTest::__listfiles(__DIR__, '/^.*php$/i');
|
||||
|
||||
$classes_to_test = array();
|
||||
foreach ($files as $fullpath) {
|
||||
$filename = basename($fullpath);
|
||||
if ($fullpath == __FILE__) continue;
|
||||
|
||||
require_once($fullpath);
|
||||
$classes_to_test[] = str_replace('.php', '', $filename);
|
||||
}
|
||||
|
||||
foreach ($classes_to_test as $class) {
|
||||
$object = new $class();
|
||||
|
||||
foreach (get_class_methods($object) as $method) {
|
||||
if (substr($method, 0, 2) == '__') continue;
|
||||
echo "Running $class::$method..\n";
|
||||
$object->$method();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user