/** * Get user input, about what request is of interest, if set in testplan.json then ignore. * * @param string $capturelabel capture label. * @return array request which is saved. */ private function confirm_requests_to_capture($capturelabel) { // Save har data in the temp file. $useridentifiedrequestsdatafile = util::get_har_file_path($capturelabel); $hardata = browsermobproxyclient::get_har($capturelabel); file_put_contents($useridentifiedrequestsdatafile, $hardata); $requests = util::get_info_from_har($capturelabel); // Get which request is being used. $request = $this->is_request_in_config($capturelabel, $requests); // Get query params to be used. if (!empty($request)) { // Update config and return. util::save_final_har_data($capturelabel, $request); return $request; } // This is only possible with interactive terminal, so ensure we have one before proceeding. $posixexists = function_exists('posix_isatty'); // Make sure this step is only used with interactive terminal (if detected). if ($posixexists && !@posix_isatty(STDOUT)) { $msg = "You have some unfilled requests in testplan.json\n" . "Please run following command for interactive terminal to enter value\n" . " vendor/bin/behat --config " . util::get_tool_dir() . DIRECTORY_SEPARATOR . 'behat.yml '; util::performance_exception($msg); } // Else ask user for the actual request to use. fwrite(STDOUT, "\n"); if (count($requests) > 1) { foreach ($requests as $index => $request) { fwrite(STDOUT, $index . ". - " . $request['method'] . " - " . $request['path'] . PHP_EOL); } fwrite(STDOUT, "Which http request should associate with \"{$capturelabel}\": "); $requestindex = trim(fread(STDIN, 1024)); // Ensure correct selection is done. while (!is_number($requestindex) || $requestindex <= 0 || $requestindex > count($requests)) { fwrite(STDOUT, "Wrong request number for step {$capturelabel}, try again: "); $requestindex = trim(fread(STDIN, 1024)); } } else { $requestindex = 0; } fwrite(STDOUT, "\\Enter query values to substitute for \"" . $requests[$requestindex]['path'] . "\"\n "); $requests[$requestindex]['query'] = $this->get_substitute_value_from_user($requests[$requestindex]['query']); // Save final request. util::save_final_har_data($capturelabel, $requests[$requestindex]); return $requests[$requestindex]; }
/** * 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); $process->setWorkingDirectory(__DIR__ . "/../../../../../"); $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(); }