MDL-45287 fix behat database reset between scenarios

We cannot find out if DB received any writes because behat
web access runs in different request.

This was affecting only scenarios without generators.
This commit is contained in:
Petr Skoda
2014-04-28 17:13:29 +08:00
parent 14df84f65e
commit 2e123e7120
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