Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/simpletestlib/autorun.php
Go to the documentation of this file.
00001 <?php
00008 require_once dirname(__FILE__) . '/unit_tester.php';
00009 require_once dirname(__FILE__) . '/mock_objects.php';
00010 require_once dirname(__FILE__) . '/collector.php';
00011 require_once dirname(__FILE__) . '/default_reporter.php';
00012 
00013 $GLOBALS['SIMPLETEST_AUTORUNNER_INITIAL_CLASSES'] = get_declared_classes();
00014 register_shutdown_function('simpletest_autorun');
00015 
00021 function simpletest_autorun() {
00022     if (tests_have_run()) {
00023         return;
00024     }
00025     $candidates = array_intersect(
00026             capture_new_classes(),
00027             classes_defined_in_initial_file());
00028     $loader = new SimpleFileLoader();
00029     $suite = $loader->createSuiteFromClasses(
00030             basename(initial_file()),
00031             $loader->selectRunnableTests($candidates));
00032     $result = $suite->run(new DefaultReporter());
00033     if (SimpleReporter::inCli()) {
00034         exit($result ? 0 : 1);
00035     }
00036 }
00037 
00043 function tests_have_run() {
00044     if ($context = SimpleTest::getContext()) {
00045         return (boolean)$context->getTest();
00046     }
00047     return false;
00048 }
00049 
00054 function initial_file() {
00055     static $file = false;
00056     if (! $file) {
00057         $file = reset(get_included_files());
00058     }
00059     return $file;
00060 }
00061 
00069 function classes_defined_in_initial_file() {
00070     if (preg_match_all('/\bclass\s+(\w+)/i', file_get_contents(initial_file()), $matches)) {
00071         return array_map('strtolower', $matches[1]);
00072     }
00073     return array();
00074 }
00075 
00081 function capture_new_classes() {
00082     global $SIMPLETEST_AUTORUNNER_INITIAL_CLASSES;
00083     return array_map('strtolower', array_diff(get_declared_classes(),
00084                             $SIMPLETEST_AUTORUNNER_INITIAL_CLASSES ?
00085                             $SIMPLETEST_AUTORUNNER_INITIAL_CLASSES : array()));
00086 }
00087 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations