/** * Start test plan. * * @param string $size size of the site. */ public static function start_testplan($size) { global $CFG; $urlcomponents = parse_url($CFG->wwwroot); if (empty($urlcomponents['path'])) { $urlcomponents['path'] = ''; } // Update fixed attributes. $propertiestoupdate = array('moodleversion' => $CFG->version, 'dataplansize' => get_config('core', 'performancesitedata'), 'host' => $urlcomponents['host'], 'sitepath' => $urlcomponents['path'], 'dataplanversion' => dataplanutil::get_tool_version(), 'testplansize' => $size, 'testplanversion' => util::get_tool_version()); foreach ($propertiestoupdate as $prop => $value) { $list['//elementProp[@name=\'' . $prop . '\']//stringProp[@name=\'Argument.value\']'] = $value; } // Update throughput and any other global value found. $globalconfig = util::get_config(); $globalconfig = $globalconfig['global']; foreach ($globalconfig as $key => $value) { if (is_array($value)) { $value = $value[$size]; } $list['//stringProp[@name=\'' . $key . '\']'] = '${__property(throughput,throughput,' . $value . ')}'; } self::replace_append_xml_in_testplan($list); }
/** * Save state of current site. Dataroot and database. * * @param string $statename * @return int 0 on success else error code. */ public static function store_site_state($statename = "default") { echo "Saving database state" . PHP_EOL; // Save database and dataroot state, before proceeding. self::store_database_state($statename); echo "Saving dataroot state" . PHP_EOL; self::store_data_root_state($statename); echo "Site state is stored at " . util::get_tool_dir() . DIRECTORY_SEPARATOR . $statename . ".*" . PHP_EOL; return 0; }
/** * Execute behat command for featurename and return exit status. * * @param string $featurename name of the feature * @param string $featurepath path of feature file * @return int status code. */ protected function execute_behat_generator($featurename, $featurepath) { $cmd = "vendor/bin/behat --config " . util::get_tool_dir() . DIRECTORY_SEPARATOR . 'behat.yml ' . $featurepath; $process = new symfonyprocess($cmd); $process->setWorkingDirectory(__DIR__ . "/../../moodle"); $process->setTimeout(null); $process->start(); if ($process->getStatus() !== 'started') { echo "Error starting process: {$featurename}"; $process->signal(SIGKILL); exit(1); } while ($process->isRunning()) { $output = $process->getIncrementalOutput(); // Don't show start data everytime. $output = preg_replace('/[a-z0-9.\\(\\)].*/im', '', $output); $op = trim($output); if (!empty($op)) { echo $output; } } return $process->getExitCode(); }
/** * Restore state of current site. Dataroot and database. * * @param string $statename * @return int 0 on success else error code. */ public static function restore_site_state($statename = "default") { // Clean up the dataroot folder. util::drop_dir(self::get_dataroot() . '/'); // Restore database and dataroot state, before proceeding. echo "Restoring database state" . PHP_EOL; if (!self::restore_database_state($statename)) { util::performance_exception("Error restoring state db: " . $statename); } echo "Restoring dataroot state" . PHP_EOL; if (!self::restore_dataroot($statename)) { util::performance_exception("Error restoring state data: " . $statename); } echo "Site restored to {$statename} state" . PHP_EOL; return 0; }