/** * Create test plan. * * @param string $size size of the test plan. * @param string $proxy proxy url * @param string $port (optional) port to be used for proxy server. * @param bool $enable only enable it. */ public function create_test_plan($size, $proxy = "localhost:9090", $port = '', $enable = false) { global $CFG, $DB; // Drop old testplan data dir, ensuring we have fresh data everytime we run the tool. util::drop_dir(util::get_tool_dir(), true); // Initialise BrowserMobProxy. $browsermobproxy = new browsermobproxyclient($proxy); // Use the proxy server url now. $proxyurl = $browsermobproxy->create_connection($port); echo "Proxy server running at: " . $proxyurl . PHP_EOL; // Create behat.yml. util::create_test_feature($size, array(), $proxyurl); util::set_option('size', $size); // Run test plan. if (!$enable) { $cmd = "vendor/bin/behat --config " . util::get_tool_dir() . DIRECTORY_SEPARATOR . 'behat.yml '; $moodlepath = util::get_moodle_path(); echo "cd {$moodlepath}" . PHP_EOL; echo "Run " . PHP_EOL . ' - ' . $cmd . PHP_EOL . PHP_EOL; } else { $this->run_plan_features(); } // Close BrowserMobProxy connection. $browsermobproxy->close_connection(); return 0; }
/** * 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')); }