/** * Lists the available steps definitions * * @param string $type * @param string $component * @param string $filter * @return string */ public static function stepsdefinitions($type, $component, $filter) { // We don't require the test environment to be enabled to list the steps definitions // so test writers can more easily set up the environment. behat_command::check_behat_setup(); // The loaded steps depends on the component specified. behat_config_manager::update_config_file($component, false); // The Moodle\BehatExtension\HelpPrinter\MoodleDefinitionsPrinter will parse this search format. if ($type) { $filter .= '&&' . $type; } if ($filter) { $filteroption = ' -d "' . $filter . '"'; } else { $filteroption = ' -di'; } // Get steps definitions from Behat. $options = ' --config="' . behat_config_manager::get_steps_list_config_filepath() . '" ' . $filteroption; list($steps, $code) = behat_command::run($options); if ($steps) { $stepshtml = implode('', $steps); } if (empty($stepshtml)) { $stepshtml = get_string('nostepsdefinitions', 'tool_behat'); } return $stepshtml; }
/** * Enables test mode * * It uses CFG->behat_dataroot * * Starts the test mode checking the composer installation and * the test environment and updating the available * features and steps definitions. * * Stores a file in dataroot/behat to allow Moodle to switch * to the test environment when using cli-server (or $CFG->behat_switchcompletely) * @throws coding_exception * @return void */ public static function start_test_mode() { global $CFG; if (!defined('BEHAT_UTIL')) { throw new coding_exception('This method can be only used by Behat CLI tool'); } // Checks the behat set up and the PHP version. behat_command::check_behat_setup(true); // Check that test environment is correctly set up. self::test_environment_problem(); // Updates all the Moodle features and steps definitions. behat_config_manager::update_config_file(); if (self::is_test_mode_enabled()) { return; } $contents = '$CFG->behat_wwwroot, $CFG->behat_prefix and $CFG->behat_dataroot' . ' are currently used as $CFG->wwwroot, $CFG->prefix and $CFG->dataroot'; $filepath = self::get_test_file_path(); if (!file_put_contents($filepath, $contents)) { behat_error(BEHAT_EXITCODE_PERMISSIONS, 'File ' . $filepath . ' can not be created'); } }