Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - https://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 <https://www.gnu.org/licenses/>.
16
 
17
/**
18
 * All in one init script - PHP version.
19
 *
20
 * @package    tool_phpunit
21
 * @copyright  2012 Petr Skoda {@link http://skodak.org}
22
 * @license    https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
if (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.
31
if (function_exists('opcache_reset')) {
32
    opcache_reset();
33
}
34
 
35
define('IGNORE_COMPONENT_CACHE', true);
36
 
1441 ariadna 37
// It makes no sense to use BEHAT_CLI for this script (you cannot initialise PHPunit starting from
38
// the Behat environment), so in case user has set tne environment variable, disable it.
39
putenv('BEHAT_CLI=0');
40
 
1 efrain 41
require_once(__DIR__.'/../../../../lib/clilib.php');
42
require_once(__DIR__.'/../../../../lib/phpunit/bootstraplib.php');
43
require_once(__DIR__.'/../../../../lib/testing/lib.php');
44
 
45
list($options, $unrecognized) = cli_get_params(
46
    [
47
        'help'                 => false,
48
        'disable-composer'     => false,
49
        'composer-upgrade'     => true,
50
        'composer-self-update' => true,
51
    ],
52
    [
53
        'h' => 'help',
54
    ]
55
);
56
 
57
$help = "
58
Utilities to initialise the PHPUnit test site.
59
 
60
Usage:
61
  php init.php [--no-composer-self-update] [--no-composer-upgrade]
62
               [--help]
63
 
64
--no-composer-self-update
65
                    Prevent upgrade of the composer utility using its self-update command
66
 
67
--no-composer-upgrade
68
                    Prevent update development dependencies using composer
69
 
70
--disable-composer
71
                    A shortcut to disable composer self-update and dependency update
72
                    Note: Installation of composer and/or dependencies will still happen as required
73
 
74
-h, --help          Print out this help
75
 
76
Example from Moodle root directory:
77
\$ php admin/tool/phpunit/cli/init.php
78
";
79
 
80
if (!empty($options['help'])) {
81
    echo $help;
82
    exit(0);
83
}
84
 
85
echo "Initialising Moodle PHPUnit test environment...\n";
86
 
87
if ($options['disable-composer']) {
88
    // Disable self-update and upgrade easily.
89
    // Note: Installation will still occur regardless of this setting.
90
    $options['composer-self-update'] = false;
91
    $options['composer-upgrade'] = false;
92
}
93
 
94
// Install and update composer and dependencies as required.
95
testing_update_composer_dependencies($options['composer-self-update'], $options['composer-upgrade']);
96
 
97
$output = null;
98
exec('php --version', $output, $code);
99
if ($code != 0) {
100
    phpunit_bootstrap_error(1, 'Can not execute \'php\' binary.');
101
}
102
 
103
chdir(__DIR__);
104
$output = null;
105
exec("php util.php --diag", $output, $code);
106
if ($code == PHPUNIT_EXITCODE_INSTALL) {
107
    passthru("php util.php --install", $code);
108
    if ($code != 0) {
109
        exit($code);
110
    }
111
 
112
} else if ($code == PHPUNIT_EXITCODE_REINSTALL) {
113
    passthru("php util.php --drop", $code);
114
    passthru("php util.php --install", $code);
115
    if ($code != 0) {
116
        exit($code);
117
    }
118
 
119
} else if ($code != 0) {
120
    echo implode("\n", $output)."\n";
121
    exit($code);
122
}
123
 
124
passthru("php util.php --buildconfig", $code);
125
 
126
echo "\n";
127
echo "PHPUnit test environment setup complete.\n";
128
exit(0);