From c3b7f2f9744061dc016b974029a82d09ceede1d6 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 8 Jul 2020 15:34:10 +0800 Subject: [PATCH] MDL-69232 behat: Move suite tests to BeforeSuite hook --- lib/tests/behat/behat_hooks.php | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/lib/tests/behat/behat_hooks.php b/lib/tests/behat/behat_hooks.php index 2ba7b37fda3..11f4e71974f 100644 --- a/lib/tests/behat/behat_hooks.php +++ b/lib/tests/behat/behat_hooks.php @@ -204,6 +204,25 @@ class behat_hooks extends behat_base { } } + /** + * Run final tests before running the suite. + * + * @BeforeSuite + * @param BeforeSuiteScope $scope scope passed by event fired before suite. + */ + public static function before_suite_final_checks(BeforeSuiteScope $scope) { + $happy = defined('BEHAT_TEST'); + $happy = $happy && defined('BEHAT_SITE_RUNNING'); + $happy = $happy && php_sapi_name() == 'cli'; + $happy = $happy && behat_util::is_test_mode_enabled(); + $happy = $happy && behat_util::is_test_site(); + + if (!$happy) { + error_log('Behat only can modify the test database and the test dataroot!'); + exit(1); + } + } + /** * Gives access to moodle codebase, to keep track of feature start time. * @@ -283,15 +302,6 @@ class behat_hooks extends behat_base { public function before_scenario(BeforeScenarioScope $scope) { global $DB, $CFG; - // As many checks as we can. - if (!defined('BEHAT_TEST') || - !defined('BEHAT_SITE_RUNNING') || - php_sapi_name() != 'cli' || - !behat_util::is_test_mode_enabled() || - !behat_util::is_test_site()) { - throw new behat_stop_exception('Behat only can modify the test database and the test dataroot!'); - } - $moreinfo = 'More info in ' . behat_command::DOCS_URL; $driverexceptionmsg = 'Selenium server is not running, you need to start it to run tests that involve Javascript. ' . $moreinfo; try {