function scan_directory() { global $suite, $total_tests, $total_failures, $testRunner; $d = opendir("."); while ($entry = readdir($d)) { if ($entry == "." || $entry == "..") { /** ignore these directories **/ } else { if (is_dir($entry)) { chdir($entry); scan_directory(); chdir(".."); } else { if (preg_match("/^[T|t]est/", $entry) && (preg_match("/[.]php3?\$/", $entry) || preg_match("/[.]inc\$/", $entry))) { if (!defined("OPT_BE_BRIEF")) { print "Requiring file ... {$entry}<br>\n"; } require_once $entry; // because we run into memory problems if we include // all files and then run the tests, we run the test suite // after each include. $result = $testRunner->run($suite); mkdb_check_did_db_fail_calls(); $total_tests += $result->countTests(); $total_failures += $result->countFailures(); unset_global('queries'); $result = ''; $suite = new TestSuite(); } } } } closedir($d); }
function define_test_suite($filename) { // using the naming convention that the file name is "TestXXXX.php" // and the class that is the unit test class is "UnitTestXXXX" if (defined("BEING_INCLUDED")) { // we're being included, that implies that a $suite global exists global $suite; $suite->addTest(new TestSuite(_filename_to_classname($filename))); } else { // doing a single test, no global suite global $old_error_handler; $suite = new TestSuite(_filename_to_classname($filename)); $testRunner = new TestRunner(); $testRunner->run($suite); mkdb_check_did_db_fail_calls(); global $start_time; $time = getmicrotime() - $start_time; print "Completed test in {$time} seconds\n"; } }