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

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

Ported code to xenial

File size: 4.2 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 tool with utilities to manage Behat integration in Moodle
19 *
20 * All CLI utilities uses $CFG->behat_dataroot and $CFG->prefix_dataroot as
21 * $CFG->dataroot and $CFG->prefix
22 *
23 * @package    tool_behat
24 * @copyright  2012 David Monllaó
25 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 */
27
28
29if (isset($_SERVER['REMOTE_ADDR'])) {
30    die(); // No access from web!.
31}
32
33// Basic functions.
34require_once(__DIR__ . '/../../../../lib/clilib.php');
35require_once(__DIR__ . '/../../../../lib/behat/lib.php');
36
37
38// CLI options.
39list($options, $unrecognized) = cli_get_params(
40    array(
41        'help'    => false,
42        'install' => false,
43        'drop'    => false,
44        'enable'  => false,
45        'disable' => false,
46        'diag'    => false
47    ),
48    array(
49        'h' => 'help'
50    )
51);
52
53if ($options['install'] or $options['drop']) {
54    define('CACHE_DISABLE_ALL', true);
55}
56
57// Checking util.php CLI script usage.
58$help = "
59Behat utilities to manage the test environment
60
61Options:
62--install  Installs the test environment for acceptance tests
63--drop     Drops the database tables and the dataroot contents
64--enable   Enables test environment and updates tests list
65--disable  Disables test environment
66--diag     Get behat test environment status code
67
68-h, --help     Print out this help
69
70Example from Moodle root directory:
71\$ php admin/tool/behat/cli/util.php --enable
72
73More info in http://docs.moodle.org/dev/Acceptance_testing#Running_tests
74";
75
76if (!empty($options['help'])) {
77    echo $help;
78    exit(0);
79}
80
81// Describe this script.
82define('BEHAT_UTIL', true);
83define('CLI_SCRIPT', true);
84define('NO_OUTPUT_BUFFERING', true);
85define('IGNORE_COMPONENT_CACHE', true);
86
87// Only load CFG from config.php, stop ASAP in lib/setup.php.
88define('ABORT_AFTER_CONFIG', true);
89require_once(__DIR__ . '/../../../../config.php');
90
91// Remove error handling overrides done in config.php.
92$CFG->debug = (E_ALL | E_STRICT);
93$CFG->debugdisplay = 1;
94error_reporting($CFG->debug);
95ini_set('display_errors', '1');
96ini_set('log_errors', '1');
97
98// Finish moodle init.
99define('ABORT_AFTER_CONFIG_CANCEL', true);
100require("$CFG->dirroot/lib/setup.php");
101
102raise_memory_limit(MEMORY_HUGE);
103
104require_once($CFG->libdir.'/adminlib.php');
105require_once($CFG->libdir.'/upgradelib.php');
106require_once($CFG->libdir.'/clilib.php');
107require_once($CFG->libdir.'/installlib.php');
108require_once($CFG->libdir.'/testing/classes/test_lock.php');
109
110if ($unrecognized) {
111    $unrecognized = implode("\n  ", $unrecognized);
112    cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
113}
114
115// Behat utilities.
116require_once($CFG->libdir . '/behat/classes/util.php');
117require_once($CFG->libdir . '/behat/classes/behat_command.php');
118
119// Run command (only one per time).
120if ($options['install']) {
121    behat_util::install_site();
122    mtrace("Acceptance tests site installed");
123} else if ($options['drop']) {
124    // Ensure no tests are running.
125    test_lock::acquire('behat');
126    behat_util::drop_site();
127    mtrace("Acceptance tests site dropped");
128} else if ($options['enable']) {
129    behat_util::start_test_mode();
130    $runtestscommand = behat_command::get_behat_command(true) .
131        ' --config ' . behat_config_manager::get_behat_cli_config_filepath();
132    mtrace("Acceptance tests environment enabled on $CFG->behat_wwwroot, to run the tests use:\n " . $runtestscommand);
133} else if ($options['disable']) {
134    behat_util::stop_test_mode();
135    mtrace("Acceptance tests environment disabled");
136} else if ($options['diag']) {
137    $code = behat_util::get_behat_status();
138    exit($code);
139} else {
140    echo $help;
141}
142
143exit(0);
Note: See TracBrowser for help on using the repository browser.