/** * Gives access to moodle codebase, ensures all is ready and sets up the test lock. * * Includes config.php to use moodle codebase with $CFG->behat_* * instead of $CFG->prefix and $CFG->dataroot, called once per suite. * * @param BeforeSuiteScope $scope scope passed by event fired before suite. * @static * @throws behat_stop_exception */ public static function before_suite(BeforeSuiteScope $scope) { global $CFG; // Defined only when the behat CLI command is running, the moodle init setup process will // read this value and switch to $CFG->behat_dataroot and $CFG->behat_prefix instead of // the normal site. if (!defined('BEHAT_TEST')) { define('BEHAT_TEST', 1); } if (!defined('CLI_SCRIPT')) { define('CLI_SCRIPT', 1); } // With BEHAT_TEST we will be using $CFG->behat_* instead of $CFG->dataroot, $CFG->prefix and $CFG->wwwroot. require_once __DIR__ . '/../../../config.php'; // Now that we are MOODLE_INTERNAL. require_once __DIR__ . '/../../behat/classes/behat_command.php'; require_once __DIR__ . '/../../behat/classes/behat_selectors.php'; require_once __DIR__ . '/../../behat/classes/behat_context_helper.php'; require_once __DIR__ . '/../../behat/classes/util.php'; require_once __DIR__ . '/../../testing/classes/test_lock.php'; require_once __DIR__ . '/../../testing/classes/nasty_strings.php'; // Avoids vendor/bin/behat to be executed directly without test environment enabled // to prevent undesired db & dataroot modifications, this is also checked // before each scenario (accidental user deletes) in the BeforeScenario hook. if (!behat_util::is_test_mode_enabled()) { throw new behat_stop_exception('Behat only can run if test mode is enabled. More info in ' . behat_command::DOCS_URL . '#Running_tests'); } // Reset all data, before checking for check_server_status. // If not done, then it can return apache error, while running tests. behat_util::clean_tables_updated_by_scenario_list(); behat_util::reset_all_data(); // Check if server is running and using same version for cli and apache. behat_util::check_server_status(); // Prevents using outdated data, upgrade script would start and tests would fail. if (!behat_util::is_test_data_updated()) { $commandpath = 'php admin/tool/behat/cli/init.php'; throw new behat_stop_exception("Your behat test site is outdated, please run\n\n " . $commandpath . "\n\nfrom your moodle dirroot to drop and install the behat test site again."); } // Avoid parallel tests execution, it continues when the previous lock is released. test_lock::acquire('behat'); // Store the browser reset time if reset after N seconds is specified in config.php. if (!empty($CFG->behat_restart_browser_after)) { // Store the initial browser session opening. self::$lastbrowsersessionstart = time(); } if (!empty($CFG->behat_faildump_path) && !is_writable($CFG->behat_faildump_path)) { throw new behat_stop_exception('You set $CFG->behat_faildump_path to a non-writable directory'); } // Handle interrupts on PHP7. if (extension_loaded('pcntl')) { $disabled = explode(',', ini_get('disable_functions')); if (!in_array('pcntl_signal', $disabled)) { declare (ticks=1); } } }