diff --git a/lib/phpunit/classes/util.php b/lib/phpunit/classes/util.php index c1c3b049ccc..c12d18123ec 100644 --- a/lib/phpunit/classes/util.php +++ b/lib/phpunit/classes/util.php @@ -34,6 +34,11 @@ require_once(__DIR__.'/../../testing/classes/util.php'); * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class phpunit_util extends testing_util { + /** + * @var int last value of db writes counter, used for db resetting + */ + public static $lastdbwrites = null; + /** @var array An array of original globals, restored after each test */ protected static $globals = array(); @@ -246,6 +251,27 @@ class phpunit_util extends testing_util { } } + /** + * Reset all database tables to default values. + * @static + * @return bool true if reset done, false if skipped + */ + public static function reset_database() { + global $DB; + + if (!is_null(self::$lastdbwrites) and self::$lastdbwrites == $DB->perf_get_writes()) { + return false; + } + + if (!parent::reset_database()) { + return false; + } + + self::$lastdbwrites = $DB->perf_get_writes(); + + return true; + } + /** * Called during bootstrap only! * @internal diff --git a/lib/testing/classes/util.php b/lib/testing/classes/util.php index 097bbd1076f..ed0ab994bb2 100644 --- a/lib/testing/classes/util.php +++ b/lib/testing/classes/util.php @@ -39,11 +39,6 @@ abstract class testing_util { */ private static $dataroot = null; - /** - * @var int last value of db writes counter, used for db resetting - */ - public static $lastdbwrites = null; - /** * @var testing_data_generator */ @@ -549,10 +544,6 @@ abstract class testing_util { public static function reset_database() { global $DB; - if (!is_null(self::$lastdbwrites) and self::$lastdbwrites == $DB->perf_get_writes()) { - return false; - } - $tables = $DB->get_tables(false); if (!$tables or empty($tables['config'])) { // not installed yet @@ -681,8 +672,6 @@ abstract class testing_util { } } - self::$lastdbwrites = $DB->perf_get_writes(); - return true; }