Proyectos de Subversion Moodle

Rev

| 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
 
37
require_once(__DIR__.'/../../../../lib/clilib.php');
38
require_once(__DIR__.'/../../../../lib/phpunit/bootstraplib.php');
39
require_once(__DIR__.'/../../../../lib/testing/lib.php');
40
 
41
list($options, $unrecognized) = cli_get_params(
42
    [
43
        'help'                 => false,
44
        'disable-composer'     => false,
45
        'composer-upgrade'     => true,
46
        'composer-self-update' => true,
47
    ],
48
    [
49
        'h' => 'help',
50
    ]
51
);
52
 
53
$help = "
54
Utilities to initialise the PHPUnit test site.
55
 
56
Usage:
57
  php init.php [--no-composer-self-update] [--no-composer-upgrade]
58
               [--help]
59
 
60
--no-composer-self-update
61
                    Prevent upgrade of the composer utility using its self-update command
62
 
63
--no-composer-upgrade
64
                    Prevent update development dependencies using composer
65
 
66
--disable-composer
67
                    A shortcut to disable composer self-update and dependency update
68
                    Note: Installation of composer and/or dependencies will still happen as required
69
 
70
-h, --help          Print out this help
71
 
72
Example from Moodle root directory:
73
\$ php admin/tool/phpunit/cli/init.php
74
";
75
 
76
if (!empty($options['help'])) {
77
    echo $help;
78
    exit(0);
79
}
80
 
81
echo "Initialising Moodle PHPUnit test environment...\n";
82
 
83
if ($options['disable-composer']) {
84
    // Disable self-update and upgrade easily.
85
    // Note: Installation will still occur regardless of this setting.
86
    $options['composer-self-update'] = false;
87
    $options['composer-upgrade'] = false;
88
}
89
 
90
// Install and update composer and dependencies as required.
91
testing_update_composer_dependencies($options['composer-self-update'], $options['composer-upgrade']);
92
 
93
$output = null;
94
exec('php --version', $output, $code);
95
if ($code != 0) {
96
    phpunit_bootstrap_error(1, 'Can not execute \'php\' binary.');
97
}
98
 
99
chdir(__DIR__);
100
$output = null;
101
exec("php util.php --diag", $output, $code);
102
if ($code == PHPUNIT_EXITCODE_INSTALL) {
103
    passthru("php util.php --install", $code);
104
    if ($code != 0) {
105
        exit($code);
106
    }
107
 
108
} else if ($code == PHPUNIT_EXITCODE_REINSTALL) {
109
    passthru("php util.php --drop", $code);
110
    passthru("php util.php --install", $code);
111
    if ($code != 0) {
112
        exit($code);
113
    }
114
 
115
} else if ($code != 0) {
116
    echo implode("\n", $output)."\n";
117
    exit($code);
118
}
119
 
120
passthru("php util.php --buildconfig", $code);
121
 
122
echo "\n";
123
echo "PHPUnit test environment setup complete.\n";
124
exit(0);