source: moodle/trunk/fuentes/admin/tool/behat/cli/init.php @ 136

Last change on this file since 136 was 136, checked in by mabarracus, 4 years ago

Ported code to xenial

File size: 2.7 KB
Line 
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// Force OPcache reset if used, we do not want any stale caches
30// when preparing test environment.
31if (function_exists('opcache_reset')) {
32    opcache_reset();
33}
34
35// Is not really necessary but adding it as is a CLI_SCRIPT.
36define('CLI_SCRIPT', true);
37define('CACHE_DISABLE_ALL', true);
38
39// Basic functions.
40require_once(__DIR__ . '/../../../../lib/clilib.php');
41require_once(__DIR__ . '/../../../../lib/behat/lib.php');
42
43// Changing the cwd to admin/tool/behat/cli.
44chdir(__DIR__);
45$output = null;
46exec("php util.php --diag", $output, $code);
47if ($code == 0) {
48    echo "Behat test environment already installed\n";
49
50} else if ($code == BEHAT_EXITCODE_INSTALL) {
51
52    testing_update_composer_dependencies();
53
54    // Behat and dependencies are installed and we need to install the test site.
55    chdir(__DIR__);
56    passthru("php util.php --install", $code);
57    if ($code != 0) {
58        exit($code);
59    }
60
61} else if ($code == BEHAT_EXITCODE_REINSTALL) {
62
63    testing_update_composer_dependencies();
64
65    // Test site data is outdated.
66    chdir(__DIR__);
67    passthru("php util.php --drop", $code);
68    if ($code != 0) {
69        exit($code);
70    }
71
72    passthru("php util.php --install", $code);
73    if ($code != 0) {
74        exit($code);
75    }
76
77} else if ($code == BEHAT_EXITCODE_COMPOSER) {
78    // Missing Behat dependencies.
79
80    testing_update_composer_dependencies();
81
82    // Returning to admin/tool/behat/cli.
83    chdir(__DIR__);
84    passthru("php util.php --install", $code);
85    if ($code != 0) {
86        exit($code);
87    }
88
89} else {
90    // Generic error, we just output it.
91    echo implode("\n", $output)."\n";
92    exit($code);
93}
94
95// Enable editing mode according to config.php vars.
96passthru("php util.php --enable", $code);
97if ($code != 0) {
98    exit($code);
99}
100
101exit(0);
Note: See TracBrowser for help on using the repository browser.