forked from moodlehq/moodle-local_ci
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_phpunit_xml.php
More file actions
112 lines (95 loc) · 3.76 KB
/
create_phpunit_xml.php
File metadata and controls
112 lines (95 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
// This file is part of Moodle - https://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
/**
* CLI utility in charge of creating the main phpunit.xml file for further inspections.
*
* For a given, valid, Moodle's root directory (dirroot), this will generate
* the phpunit.xml, normally used by phpunit runs. The main difference is that it's
* done in a way a real site and database are not needed, so it's quicker and easier
* to run in any environment (very similar to list_valid_components job).
*
* @category test
* @package local_ci
* @subpackage remote_branch_checker
* @copyright 2022 onwards Eloy Lafuente (stronk7) {@link https://stronk7.com}
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__.'/../phplib/clilib.php');
// now get cli options
list($options, $unrecognized) = cli_get_params(
[
'help' => false,
'basedir' => '',
],
[
'h' => 'help',
'b' => 'basedir',
]
);
if ($unrecognized) {
$unrecognized = implode("\n ", $unrecognized);
cli_error("Unrecognised options:\n{$unrecognized}\n Please use --help option.");
}
if ($options['help']) {
$help =
"Generate the phpunit.xml file for a given Moodle's root directory.
Options:
-h, --help Print out this help.
--basedir Full path to the moodle base dir to look for components.
Example:
php local/ci/verify_phpunit_xml/create_phpunit_xml.php --basedir=/home/moodle/git
";
echo $help;
exit(0);
}
if (empty($options['basedir'])) {
cli_error('Missing basedir param. Please use --help option.');
}
if (!file_exists($options['basedir'])) {
cli_error('Incorrect directory: ' . $options['basedir']);
}
if (!is_writable($options['basedir'])) {
cli_error('Non-writable directory: ' . $options['basedir']);
}
// We need all the components loaded first.
if (!load_core_component_from_moodle($options['basedir'])) {
cli_error('Something went wrong. Components not loaded from ' . $options['basedir']);
}
if (file_exists("{$options['basedir']}/public/version.php")) {
$dirroot = "{$options['basedir']}/public";
} else {
$dirroot = $options['basedir'];
}
// We need to register the Moodle autoloader.
require_once("{$dirroot}/lib/classes/component.php");
spl_autoload_register([\core_component::class, 'classloader']);
// Now, let's invoke phpunit utils to generate the phpunit.xml file
// We need to load a few things manually.
if (!class_exists(\phpunit_util::class)) {
// From Moodle 5.2 we can autoload the phpunit_util class.
// Including the old location will throw debugging notices. In this case, because we do not load the full Moodle
// stack, this excepts.
require_once("{$dirroot}/lib/phpunit/classes/util.php");
}
if (!class_exists(\core\output\core_renderer::class)) {
// From Moodle 4.5 we start to autoload the output components and including outputcomponents.php will throw an exception.
// If the core_renderer class can be autoloaded then we do not need to include outputcomponents.php.
require_once("{$dirroot}/lib/outputcomponents.php");
}
require_once("{$dirroot}/lib/testing/lib.php");
phpunit_util::build_config_file();
// We are done, end here.
exit(0);