MDL-38878 behat: Also update composer dependencies after site install/reinstall
[moodle.git] / admin / tool / behat / cli / init.php
blobfd11b088bca8eb050af1e0747a6b72b83c192f90
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
18 * CLI script to set up all the behat test environment.
20 * @package tool_behat
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 // Is not really necessary but adding it as is a CLI_SCRIPT.
30 define('CLI_SCRIPT', true);
32 // Basic functions.
33 require_once(__DIR__ . '/../../../../lib/clilib.php');
34 require_once(__DIR__ . '/../../../../lib/behat/lib.php');
36 // Changing the cwd to admin/tool/behat/cli.
37 chdir(__DIR__);
38 $output = null;
39 exec("php util.php --diag", $output, $code);
40 if ($code == 0) {
41 echo "Behat test environment already installed\n";
43 } else if ($code == BEHAT_EXITCODE_INSTALL) {
45 testing_update_composer_dependencies();
47 // Behat and dependencies are installed and we need to install the test site.
48 chdir(__DIR__);
49 passthru("php util.php --install", $code);
50 if ($code != 0) {
51 exit($code);
54 } else if ($code == BEHAT_EXITCODE_REINSTALL) {
56 testing_update_composer_dependencies();
58 // Test site data is outdated.
59 chdir(__DIR__);
60 passthru("php util.php --drop", $code);
61 if ($code != 0) {
62 exit($code);
65 passthru("php util.php --install", $code);
66 if ($code != 0) {
67 exit($code);
70 } else if ($code == BEHAT_EXITCODE_COMPOSER) {
71 // Missing Behat dependencies.
73 testing_update_composer_dependencies();
75 // Returning to admin/tool/behat/cli.
76 chdir(__DIR__);
77 passthru("php util.php --install", $code);
78 if ($code != 0) {
79 exit($code);
82 } else {
83 // Generic error, we just output it.
84 echo implode("\n", $output)."\n";
85 exit($code);
88 // Enable editing mode according to config.php vars.
89 passthru("php util.php --enable", $code);
90 if ($code != 0) {
91 exit($code);
94 exit(0);