MDL-38825 behat: fix composer install url
[moodle.git] / admin / tool / behat / cli / init.php
CommitLineData
ac41f878
DM
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.
13//
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/>.
16
17/**
18 * CLI script to set up all the behat test environment.
19 *
20 * @package tool_behat
21 * @copyright 2013 David MonllaĆ³
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25if (isset($_SERVER['REMOTE_ADDR'])) {
26 die(); // No access from web!
27}
28
29// Is not really necessary but adding it as is a CLI_SCRIPT.
30define('CLI_SCRIPT', true);
31
32// Basic functions.
33require_once(__DIR__ . '/../../../../lib/clilib.php');
34require_once(__DIR__ . '/../../../../lib/behat/lib.php');
35
36// Changing the cwd to admin/tool/behat/cli.
37chdir(__DIR__);
38$output = null;
39exec("php util.php --diag", $output, $code);
40if ($code == 0) {
41 echo "Behat test environment already installed\n";
42
43} else if ($code == BEHAT_EXITCODE_INSTALL) {
44 // Behat and dependencies are installed and we need to install the test site.
45 passthru("php util.php --install", $code);
46 if ($code != 0) {
47 exit($code);
48 }
49
50} else if ($code == BEHAT_EXITCODE_REINSTALL) {
51 // Test site data is outdated.
52 passthru("php util.php --drop", $code);
53 if ($code != 0) {
54 exit($code);
55 }
56
57 passthru("php util.php --install", $code);
58 if ($code != 0) {
59 exit($code);
60 }
61
62} else if ($code == BEHAT_EXITCODE_COMPOSER) {
63 // Missing Behat dependencies.
64
65 // Changing to moodle dirroot to run composer related commands at project level.
66 chdir(__DIR__ . '/../../../..');
67 if (!file_exists(__DIR__ . '/../../../../composer.phar')) {
c5f6371f 68 passthru("curl http://getcomposer.org/installer | php", $code);
ac41f878
DM
69 if ($code != 0) {
70 exit($code);
71 }
72 }
73
1e63755f 74 passthru("php composer.phar update --dev", $code);
ac41f878
DM
75 if ($code != 0) {
76 exit($code);
77 }
78
79 // Returning to admin/tool/behat/cli.
80 chdir(__DIR__);
81 passthru("php util.php --install", $code);
82 if ($code != 0) {
83 exit($code);
84 }
85
86} else {
87 // Generic error, we just output it.
88 echo implode("\n", $output)."\n";
89 exit($code);
90}
91
92// Enable editing mode according to config.php vars.
93passthru("php util.php --enable", $code);
94if ($code != 0) {
95 exit($code);
96}
97
98exit(0);