Example #1
0
require_once $CFG->libdir . '/behat/classes/util.php';
require_once $CFG->libdir . '/behat/classes/behat_command.php';
// Run command (only one per time).
if ($options['install']) {
    behat_util::install_site();
    mtrace("Acceptance tests site installed");
} else {
    if ($options['drop']) {
        // Ensure no tests are running.
        test_lock::acquire('behat');
        behat_util::drop_site();
        mtrace("Acceptance tests site dropped");
    } else {
        if ($options['enable']) {
            behat_util::start_test_mode();
            $runtestscommand = behat_command::get_behat_command(true) . ' --config ' . behat_config_manager::get_behat_cli_config_filepath();
            mtrace("Acceptance tests environment enabled, to run the tests use:\n " . $runtestscommand);
        } else {
            if ($options['disable']) {
                behat_util::stop_test_mode();
                mtrace("Acceptance tests environment disabled");
            } else {
                if ($options['diag']) {
                    $code = behat_util::get_behat_status();
                    exit($code);
                } else {
                    echo $help;
                }
            }
        }
    }
Example #2
0
            $CFG->behat_dataroot = $behatdataroot . $i;
        }
        behat_config_manager::update_config_file('', true, $tags);
    }
    $CFG->behat_dataroot = $behatdataroot;
    $CFG->behat_wwwroot = $behatwwwroot;
    unset($CFG->behatrunprocess);
}
$cmds = array();
echo "Running " . ($options['torun'] - $options['fromrun'] + 1) . " parallel behat sites:" . PHP_EOL;
for ($i = $options['fromrun']; $i <= $options['torun']; $i++) {
    $CFG->behatrunprocess = $i;
    // Options parameters to be added to each run.
    $myopts = !empty($options['replace']) ? str_replace($options['replace'], $i, $extraopts) : $extraopts;
    $behatcommand = behat_command::get_behat_command(false, false, true);
    $behatconfigpath = behat_config_manager::get_behat_cli_config_filepath($i);
    // Command to execute behat run.
    $cmds[BEHAT_PARALLEL_SITE_NAME . $i] = $behatcommand . ' --config ' . $behatconfigpath . " " . $myopts;
    echo "[" . BEHAT_PARALLEL_SITE_NAME . $i . "] " . $cmds[BEHAT_PARALLEL_SITE_NAME . $i] . PHP_EOL;
}
if (empty($cmds)) {
    echo "No commands to execute " . PHP_EOL;
    exit(1);
}
// Create site symlink if necessary.
if (!behat_config_manager::create_parallel_site_links($options['fromrun'], $options['torun'])) {
    echo "Check permissions. If on windows, make sure you are running this command as admin" . PHP_EOL;
    exit(1);
}
// Execute all commands.
$processes = cli_execute_parallel($cmds, __DIR__);
                if ($options['diag']) {
                    $code = behat_util::get_behat_status();
                    exit($code);
                } else {
                    if ($options['updatesteps']) {
                        if (defined('BEHAT_FEATURE_STEP_FILE') && BEHAT_FEATURE_STEP_FILE) {
                            $behatstepfile = BEHAT_FEATURE_STEP_FILE;
                        } else {
                            echo "BEHAT_FEATURE_STEP_FILE is not set, please ensure you set this to writable file" . PHP_EOL;
                            exit(1);
                        }
                        // Rewrite config file to ensure we have all the features covered.
                        behat_config_manager::update_config_file();
                        // Run behat command to get steps in feature files.
                        $featurestepscmd = behat_command::get_behat_command(true);
                        $featurestepscmd .= ' --config ' . behat_config_manager::get_behat_cli_config_filepath();
                        $featurestepscmd .= ' --dry-run --format=moodle_step_count';
                        $processes = cli_execute_parallel(array($featurestepscmd), __DIR__ . "/../../../../");
                        $status = print_update_step_output(array_pop($processes), $behatstepfile);
                        exit($status);
                    } else {
                        echo $help;
                        exit(1);
                    }
                }
            }
        }
    }
}
exit(0);
/**