2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * CLI script to set up all the behat test environment.
21 * @copyright 2013 David Monllaó
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 if (isset($_SERVER['REMOTE_ADDR'])) {
26 die(); // No access from web!
29 // Force OPcache reset if used, we do not want any stale caches
30 // when preparing test environment.
31 if (function_exists('opcache_reset')) {
35 // Is not really necessary but adding it as is a CLI_SCRIPT.
36 define('CLI_SCRIPT', true);
37 define('CACHE_DISABLE_ALL', true);
40 require_once(__DIR__ . '/../../../../lib/clilib.php');
41 require_once(__DIR__ . '/../../../../lib/behat/lib.php');
43 list($options, $unrecognized) = cli_get_params(
58 // Checking run.php CLI script usage.
60 Behat utilities to initialise behat tests
63 php init.php [--parallel=value [--maxruns=value] [--fromrun=value --torun=value]] [--help]
66 -j, --parallel Number of parallel behat run to initialise
67 -m, --maxruns Max parallel processes to be executed at one time.
68 --fromrun Execute run starting from (Used for parallel runs on different vms)
69 --torun Execute run till (Used for parallel runs on different vms)
71 -h, --help Print out this help
73 Example from Moodle root directory:
74 \$ php admin/tool/behat/cli/init.php --parallel=2
76 More info in http://docs.moodle.org/dev/Acceptance_testing#Running_tests
79 if (!empty($options['help'])) {
84 // Check which util file to call.
85 $utilfile = 'util_single_run.php';
87 // If parallel run then use utilparallel.
88 if ($options['parallel'] && $options['parallel'] > 1) {
89 $utilfile = 'util.php';
91 foreach ($options as $option => $value) {
93 $paralleloption .= " --$option=\"$value\"";
98 // Changing the cwd to admin/tool/behat/cli.
102 // If behat dependencies not downloaded then do it first, else symfony/process can't be used.
103 testing_update_composer_dependencies();
105 // Check whether the behat test environment needs to be updated.
107 exec("php $utilfile --diag $paralleloption", $output, $code);
110 echo "Behat test environment already installed\n";
112 } else if ($code == BEHAT_EXITCODE_INSTALL) {
113 // Behat and dependencies are installed and we need to install the test site.
115 passthru("php $utilfile --install $paralleloption", $code);
121 } else if ($code == BEHAT_EXITCODE_REINSTALL) {
122 // Test site data is outdated.
124 passthru("php $utilfile --drop $paralleloption", $code);
131 passthru("php $utilfile --install $paralleloption", $code);
138 // Generic error, we just output it.
139 echo implode("\n", $output)."\n";
144 // Enable editing mode according to config.php vars.
146 passthru("php $utilfile --enable $paralleloption", $code);
148 echo "Error enabling site" . PHP_EOL;