Merge branch 'w18_MDL-45287_m27_dbreset' of git://github.com/skodak/moodle

This commit is contained in:
Marina Glancy
2014-04-28 20:17:57 +08:00
2 changed files with 26 additions and 11 deletions
+26
View File
@@ -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
-11
View File
@@ -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;
}