Skip to content

Commit

Permalink
Merge branch 'MDL-80591' of https://github.com/stronk7/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Jan 18, 2024
2 parents f81adf9 + 9f10626 commit d8775cf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
15 changes: 6 additions & 9 deletions admin/tool/phpunit/cli/init.php
@@ -1,5 +1,5 @@
<?php
// This file is part of Moodle - http://moodle.org/
// 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
Expand All @@ -12,18 +12,18 @@
// 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 <http://www.gnu.org/licenses/>.
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

/**
* All in one init script - PHP version.
*
* @package tool_phpunit
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

if (isset($_SERVER['REMOTE_ADDR'])) {
die; // no access from web!
die; // No access from web!
}

// Force OPcache reset if used, we do not want any stale caches
Expand Down Expand Up @@ -99,10 +99,7 @@
chdir(__DIR__);
$output = null;
exec("php util.php --diag", $output, $code);
if ($code == 0) {
// everything is ready

} else if ($code == PHPUNIT_EXITCODE_INSTALL) {
if ($code == PHPUNIT_EXITCODE_INSTALL) {
passthru("php util.php --install", $code);
if ($code != 0) {
exit($code);
Expand All @@ -115,7 +112,7 @@
exit($code);
}

} else {
} else if ($code != 0) {
echo implode("\n", $output)."\n";
exit($code);
}
Expand Down
50 changes: 26 additions & 24 deletions admin/tool/phpunit/cli/util.php
@@ -1,5 +1,5 @@
<?php
// This file is part of Moodle - http://moodle.org/
// 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
Expand All @@ -12,7 +12,7 @@
// 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 <http://www.gnu.org/licenses/>.
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.

/**
* PHPUnit related utilities.
Expand All @@ -21,11 +21,11 @@
*
* @package tool_phpunit
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

if (isset($_SERVER['REMOTE_ADDR'])) {
die; // no access from web!
die; // No access from web!
}

define('IGNORE_COMPONENT_CACHE', true);
Expand All @@ -34,55 +34,54 @@
require_once(__DIR__.'/../../../../lib/phpunit/bootstraplib.php');
require_once(__DIR__.'/../../../../lib/testing/lib.php');

// now get cli options
// Now get cli options.
list($options, $unrecognized) = cli_get_params(
array(
[
'drop' => false,
'install' => false,
'buildconfig' => false,
'buildcomponentconfigs' => false,
'diag' => false,
'run' => false,
'help' => false,
),
array(
'h' => 'help'
)
],
[
'h' => 'help',
]
);

if (file_exists(__DIR__.'/../../../../vendor/phpunit/phpunit/composer.json')) {
// Composer packages present.
require_once(__DIR__.'/../../../../vendor/autoload.php');

} else {
// Note: installation via PEAR is not supported any more.
// Basic check to see if phpunit is installed.
if (!file_exists(__DIR__.'/../../../../vendor/phpunit/phpunit/composer.json') ||
!file_exists(__DIR__.'/../../../../vendor/bin/phpunit') ||
!file_exists(__DIR__.'/../../../../vendor/autoload.php')) {
phpunit_bootstrap_error(PHPUNIT_EXITCODE_PHPUNITMISSING);
}

if ($options['install'] or $options['drop']) {
if ($options['install'] || $options['drop']) {
define('CACHE_DISABLE_ALL', true);
}

if ($options['run']) {
unset($options);
unset($unrecognized);

foreach ($_SERVER['argv'] as $k=>$v) {
foreach ($_SERVER['argv'] as $k => $v) {
if (strpos($v, '--run') === 0) {
unset($_SERVER['argv'][$k]);
$_SERVER['argc'] = $_SERVER['argc'] - 1;
}
}
$_SERVER['argv'] = array_values($_SERVER['argv']);
PHPUnit\TextUI\Command::main();
require(__DIR__ . '/../../../../vendor/bin/phpunit');
exit(0);
}

define('PHPUNIT_UTIL', true);

require(__DIR__.'/../../../../vendor/autoload.php');
require(__DIR__ . '/../../../../lib/phpunit/bootstrap.php');

// from now on this is a regular moodle CLI_SCRIPT
// From now on this is a regular moodle CLI_SCRIPT.

require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/upgradelib.php');
Expand All @@ -100,7 +99,7 @@
$buildconfig = $options['buildconfig'];
$buildcomponentconfigs = $options['buildcomponentconfigs'];

if ($options['help'] or (!$drop and !$install and !$buildconfig and !$buildcomponentconfigs and !$diag)) {
if ($options['help'] || (!$drop && !$install && !$buildconfig && !$buildcomponentconfigs && !$diag)) {
$help = "Various PHPUnit utility functions
Options:
Expand Down Expand Up @@ -132,18 +131,21 @@
if (phpunit_util::build_config_file()) {
exit(0);
} else {
phpunit_bootstrap_error(PHPUNIT_EXITCODE_CONFIGWARNING, 'Can not create main /phpunit.xml configuration file, verify dirroot permissions');
phpunit_bootstrap_error(
PHPUNIT_EXITCODE_CONFIGWARNING,
'Can not create main /phpunit.xml configuration file, verify dirroot permissions'
);
}

} else if ($buildcomponentconfigs) {
phpunit_util::build_component_config_files();
exit(0);

} else if ($drop) {
// make sure tests do not run in parallel
// Make sure tests do not run in parallel.
test_lock::acquire('phpunit');
phpunit_util::drop_site(true);
// note: we must stop here because $CFG is messed up and we can not reinstall, sorry
// Note: we must stop here because $CFG is messed up and we can not reinstall, sorry.
exit(0);

} else if ($install) {
Expand Down

0 comments on commit d8775cf

Please sign in to comment.