/** * 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 SuiteEvent $event event before suite. * @static * @throws Exception * @BeforeSuite */ public static function before_suite(SuiteEvent $event) { global $CFG; define('CLI_SCRIPT', 1); $moodlepath = util::get_moodle_path(); require_once $moodlepath . '/config.php'; require_once __DIR__ . '/inc.php'; // Now that we are MOODLE_INTERNAL. require_once $CFG->libdir . '/behat/classes/behat_command.php'; require_once $CFG->libdir . '/behat/classes/behat_selectors.php'; require_once $CFG->libdir . '/behat/classes/behat_context_helper.php'; require_once $CFG->libdir . '/behat/classes/util.php'; require_once $CFG->libdir . '/testing/classes/test_lock.php'; require_once $CFG->libdir . '/testing/classes/nasty_strings.php'; // Initialise BrowserMobProxy. $browsermobproxy = new browsermobproxyclient(util::get_option('proxyurl')); // Use the proxy server url now. $browsermobproxy->create_connection(util::get_option('proxyport')); util::drop_dir(util::get_final_testplan_path()); // Update global properties in test plan. testplan_writer::start_testplan(util::get_option('size')); }
/** * Execute the command. * * @param InputInterface $input * @param OutputInterface $output */ protected function execute(InputInterface $input, OutputInterface $output) { // We don't need moodle for getting value. if ($value = $input->getOption('value')) { switch ($value) { case 'version': $output->writeln(\moodlehq\behat_2jmx\util::get_tool_version()); break; case 'moodlepath': $output->writeln(util::get_moodle_path()); break; case 'datapath': $output->writeln(util::get_data_path()); break; default: $output->writeln('<error>Not a valid option.</error><info> Should be wither version|moodlepath|datapath</info>'); return 1; break; } return 0; } // Describe this script. define('PERFORMANCE_SITE_GENERATOR', true); define('CLI_SCRIPT', true); define('NO_OUTPUT_BUFFERING', true); define('IGNORE_COMPONENT_CACHE', true); // Load moodle config and all classes. $moodlepath = util::get_moodle_path(); // Autoload files and ensure we load moodle config, as we will be using moodle code for behat context. require_once $moodlepath . '/config.php'; require_once __DIR__ . '/inc.php'; raise_memory_limit(MEMORY_HUGE); $status = false; // Do action. $behat2jmx = new \moodlehq\behat_2jmx\generator(); $testplan = $input->getOption('testplan'); $proxyurl = $input->getOption('proxyurl'); // make sure proxyport and proxy url is provided. if (empty($proxyurl) || empty($testplan)) { $output->write($this->getHelp(), true); return 1; } $status = $behat2jmx->create_test_plan(strtolower($testplan), $proxyurl, $input->getOption('proxyport'), $input->getOption('force')); return $status; }
/** * Execute behat command for featurename and return exit status. * * @return int status code. */ protected function execute_behat_generator() { $cmd = "vendor/bin/behat --config " . util::get_tool_dir() . DIRECTORY_SEPARATOR . 'behat.yml '; $process = new Process($cmd); $moodlepath = util::get_moodle_path(); $process->setWorkingDirectory($moodlepath); $process->setTimeout(null); $process->start(); if ($process->getStatus() !== 'started') { echo "Error starting process"; $process->signal(SIGKILL); exit(1); } while ($process->isRunning()) { $output = $process->getIncrementalOutput(); $op = trim($output); if (!empty($op)) { echo $output; } } if ($process->getExitCode() !== 0) { echo $process->getErrorOutput(); } return $process->getExitCode(); }