/**
  * After suite event.
  *
  * @param SuiteEvent $event
  * @AfterSuite
  */
 public static function after_suite(SuiteEvent $event)
 {
     $browsermobproxy = new browsermobproxyclient(util::get_option('proxyurl'));
     $browsermobproxy->close_connection();
     echo PHP_EOL . "Test plan has been generated under:" . PHP_EOL;
     echo " - " . util::get_final_testplan_path() . PHP_EOL;
 }
 /**
  * Creates csv file and add it to the threadgroup for use case.
  *
  * @Given /^I login as any "([^"]*)" enrolled in course "([^"]*)"$/
  */
 public function i_login_as_any_enrolled_in_course($rolearchtype, $courseshortname)
 {
     global $DB, $CFG;
     if (!($id = $DB->get_field('course', 'id', array('shortname' => $courseshortname)))) {
         util::performance_exception('The specified course with shortname "' . $courseshortname . '" does not exist');
     }
     $coursecontext = \context_course::instance($id);
     if ($roles = get_archetype_roles($rolearchtype)) {
         $roles = array_keys($roles);
     }
     $roleid = $roles[0];
     $users = get_role_users($roleid, $coursecontext, false, 'u.id,u.username', 'u.id ASC');
     if (!$users) {
         util::performance_exception("Course without users with role: " . $rolearchtype);
     }
     $data = "";
     foreach ($users as $user) {
         $data .= $user->username . "," . $user->username . "," . $user->id . PHP_EOL;
     }
     $testplanfilename = $rolearchtype . '_' . behat_hooks::$featurefile . '.csv';
     $csvfile = util::get_final_testplan_path() . DIRECTORY_SEPARATOR . $testplanfilename;
     $testplanfilepath = "";
     if (isset($CFG->testplanfiles_dataroot)) {
         $testplanfilepath = $CFG->testplanfiles_dataroot . DIRECTORY_SEPARATOR;
     }
     file_put_contents($csvfile, $data);
     testplan_writer::create_csv_data($testplanfilepath, $testplanfilename, $rolearchtype);
     $firstuser = array_shift($users);
     return new Given('I log in as "' . $firstuser->username . '"');
 }
 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;
     }
 }