Skip to content

Commit

Permalink
MDL-45287 fix behat database reset between scenarios
Browse files Browse the repository at this point in the history
We cannot find out if DB received any writes because behat
web access runs in different request.

This was affecting only scenarios without generators.
  • Loading branch information
skodak committed Apr 28, 2014
1 parent 254402d commit a9236a2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
26 changes: 26 additions & 0 deletions lib/phpunit/classes/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
* @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();

Expand Down Expand Up @@ -246,6 +251,27 @@ public static function reset_all_data($detectchanges = false) {
}
}

/**
* 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
Expand Down
11 changes: 0 additions & 11 deletions lib/testing/classes/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -549,10 +544,6 @@ public static function reset_all_database_sequences(array $empties = null) {
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
Expand Down Expand Up @@ -681,8 +672,6 @@ public static function reset_database() {
}
}

self::$lastdbwrites = $DB->perf_get_writes();

return true;
}

Expand Down

0 comments on commit a9236a2

Please sign in to comment.