/** * 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; // Check if site is initialised for performance testing. //TODO: // 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 '; echo "Run " . PHP_EOL . ' - ' . $cmd . PHP_EOL . PHP_EOL; } else { $this->run_plan_features(); } // Close BrowserMobProxy connection. $browsermobproxy->close_connection(); }
/** * Create new connection to the proxy * * @param string $port speficy port if you want to open proxy at specific port. * @return string the url for proxy. */ public function create_connection($port = '') { $parts = parse_url($this->proxyurl); $hostname = $parts["host"]; // Create request to open proxy connection. $options = array(); $headers = array(); if (!empty($port)) { $options = array('port' => $port); } $response = self::curl_post($this->proxyurl . "/proxy/", $options); // Get port on which new proxy connection is created. $decoded = json_decode($response, true); if ($decoded) { $this->port = $decoded["port"]; util::set_option('proxyport', $this->port); } self::new_har(); // Return url on which the request will be handled. return $hostname . ":" . $this->port; }