From a9236a2c3f6320bac1b6e740f17984f653c12f91 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Mon, 28 Apr 2014 17:02:58 +0800 Subject: [PATCH] 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. --- lib/phpunit/classes/util.php | 26 ++++++++++++++++++++++++++ lib/testing/classes/util.php | 11 ----------- 2 files changed, 26 insertions(+), 11 deletions(-) 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; }