public static function setUpBeforeClass() { global $CFG; parent::setUpBeforeClass(); if (!defined('PHPUNIT_TEST_DRIVER')) { // use normal $DB return; } if (!isset($CFG->phpunit_extra_drivers[PHPUNIT_TEST_DRIVER])) { throw new exception('Can not find driver configuration options with index: ' . PHPUNIT_TEST_DRIVER); } $dblibrary = empty($CFG->phpunit_extra_drivers[PHPUNIT_TEST_DRIVER]['dblibrary']) ? 'native' : $CFG->phpunit_extra_drivers[PHPUNIT_TEST_DRIVER]['dblibrary']; $dbtype = $CFG->phpunit_extra_drivers[PHPUNIT_TEST_DRIVER]['dbtype']; $dbhost = $CFG->phpunit_extra_drivers[PHPUNIT_TEST_DRIVER]['dbhost']; $dbname = $CFG->phpunit_extra_drivers[PHPUNIT_TEST_DRIVER]['dbname']; $dbuser = $CFG->phpunit_extra_drivers[PHPUNIT_TEST_DRIVER]['dbuser']; $dbpass = $CFG->phpunit_extra_drivers[PHPUNIT_TEST_DRIVER]['dbpass']; $prefix = $CFG->phpunit_extra_drivers[PHPUNIT_TEST_DRIVER]['prefix']; $dboptions = empty($CFG->phpunit_extra_drivers[PHPUNIT_TEST_DRIVER]['dboptions']) ? array() : $CFG->phpunit_extra_drivers[PHPUNIT_TEST_DRIVER]['dboptions']; $classname = "{$dbtype}_{$dblibrary}_moodle_database"; require_once "{$CFG->libdir}/dml/{$classname}.php"; $d = new $classname(); if (!$d->driver_installed()) { throw new exception('Database driver for ' . $classname . ' is not installed'); } $d->connect($dbhost, $dbuser, $dbpass, $dbname, $prefix, $dboptions); self::$extradb = $d; }