From 7d4eb8991f13d00557e14ce094bbeb1b3664ee67 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 633fadc187b..4ee93a63a71 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(); @@ -242,6 +247,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 065cfc559d2..75a92db517e 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; }