public function run_plan_features() { // Execute each feature file 1 by one to show the proper progress... $testplanconfig = util::get_feature_config(); if (empty($testplanconfig)) { util::performance_exception("Check generator config file testplan.json"); } $status = $this->execute_behat_generator(); // Don't proceed if it fails. if ($status) { echo "Error: Failed generating test plan" . PHP_EOL . PHP_EOL; $moodlepath = util::get_moodle_path(); echo "cd {$moodlepath}" . PHP_EOL; $cmd = "vendor/bin/behat --config " . util::get_tool_dir() . DIRECTORY_SEPARATOR . 'behat.yml '; echo "Run " . PHP_EOL . ' - ' . $cmd . PHP_EOL . PHP_EOL; die; } else { echo PHP_EOL . "Test plan has been generated under:" . PHP_EOL; echo " - " . util::get_final_testplan_path() . PHP_EOL; } }
/** * Return request index which is defined in config with updated query data, leaving global values untouched. * * @param $getrequests * @param $postrequests * @param $postdata * @param $requestsfromconfig * @return array requestindex, method and path. */ private function is_request_in_config($capturelabel, $requests) { $requestsfromconfig = $this->get_capture_request_from_config($capturelabel, \behat_hooks::$featurefile); $requestfromhar = null; // Check if request is already set by user in config. if (!empty($requestsfromconfig)) { // Loop though each request from har and find the appropriate one. // We need this to replace query values except the global set by user. foreach ($requests as $index => $request) { if ($requestsfromconfig['method'] == $request['method'] && $requestsfromconfig['path'] == $request['path']) { break; } } if (empty($request)) { util::performance_exception("Request from har is not found in config. Check: " . \behat_hooks::$featurefile . " : " . $capturelabel); } // Replace global values in query array with config values. foreach ($requestsfromconfig['query'] as $key => $value) { if (preg_match('/^\\$\\{.*\\}/', $value)) { $request['query'][$key] = $value; } } return $request; } return array(); }
/** * Updates the composer installer and the dependencies. * * @param string $dirroot root of directory where to check for composer install. * @return void exit() if something goes wrong */ public static function testing_update_composer_dependencies($dirroot) { // To restore the value after finishing. $cwd = getcwd(); $composerpath = $dirroot . DIRECTORY_SEPARATOR . 'composer.phar'; $composerurl = 'https://getcomposer.org/composer.phar'; // Switch to Moodle's dirroot for easier path handling. chdir($dirroot); // Download or update composer.phar. Unfortunately we can't use the curl // class in filelib.php as we're running within one of the test platforms. if (!file_exists($composerpath)) { $file = @fopen($composerpath, 'w'); if ($file === false) { $errordetails = error_get_last(); util::performance_exception(sprintf("Unable to create composer.phar\nPHP error: %s", $errordetails['message'])); } $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $composerurl); curl_setopt($curl, CURLOPT_FILE, $file); $result = curl_exec($curl); $curlerrno = curl_errno($curl); $curlerror = curl_error($curl); $curlinfo = curl_getinfo($curl); curl_close($curl); fclose($file); if (!$result) { $error = sprintf("Unable to download composer.phar\ncURL error (%d): %s", $curlerrno, $curlerror); util::performance_exception($error); } else { if ($curlinfo['http_code'] === 404) { if (file_exists($composerpath)) { // Deleting the resource as it would contain HTML. unlink($composerpath); } $error = sprintf("Unable to download composer.phar\n" . "404 http status code fetching {$composerurl}"); util::performance_exception($error); } } } else { passthru("php composer.phar self-update", $code); if ($code != 0) { exit($code); } } // Update composer dependencies. passthru("php composer.phar install", $code); if ($code != 0) { exit($code); } // Return to our original location. chdir($cwd); }
/** * Return proxy used by the test plan generator. * * @return array. */ public static function get_option($option) { $optionfile = self::get_tool_dir() . DIRECTORY_SEPARATOR . 'testplanoptions.json'; if (!file_exists($optionfile)) { util::performance_exception("Option " . $option . " is not set."); } else { $contents = json_decode(file_get_contents($optionfile), true); if (!empty($contents[$option])) { return $contents[$option]; } else { util::performance_exception("Option " . $option . " is not set."); } } }