From 9f10626533b58e5baa42ef093bc9a2522c806790 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sat, 13 Jan 2024 18:46:45 +0100 Subject: [PATCH] MDL-80591 phpunit: Coding style cleanup both CLI scripts While the init.php was cleaned up not long ago, let's re-review it (small detail only) and proceed to, also, clean up the util.php one. Note that both will raise an error about missing MOODLE_INTERNAL check, but that's expected, they are CLI scripts, independent from Moodle's bootstrap, so they don't have config.php required either. --- admin/tool/phpunit/cli/init.php | 15 ++++++------- admin/tool/phpunit/cli/util.php | 37 ++++++++++++++++++--------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/admin/tool/phpunit/cli/init.php b/admin/tool/phpunit/cli/init.php index 9c173774b7f..9c4714c87db 100644 --- a/admin/tool/phpunit/cli/init.php +++ b/admin/tool/phpunit/cli/init.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** * 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 @@ -99,10 +99,7 @@ if ($code != 0) { 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); @@ -115,7 +112,7 @@ if ($code == 0) { exit($code); } -} else { +} else if ($code != 0) { echo implode("\n", $output)."\n"; exit($code); } diff --git a/admin/tool/phpunit/cli/util.php b/admin/tool/phpunit/cli/util.php index 8d60ff3c952..a806aaacfbb 100644 --- a/admin/tool/phpunit/cli/util.php +++ b/admin/tool/phpunit/cli/util.php @@ -1,5 +1,5 @@ . +// along with Moodle. If not, see . /** * PHPUnit related utilities. @@ -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); @@ -34,9 +34,9 @@ require_once(__DIR__.'/../../../../lib/clilib.php'); 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, @@ -44,10 +44,10 @@ list($options, $unrecognized) = cli_get_params( 'diag' => false, 'run' => false, 'help' => false, - ), - array( - 'h' => 'help' - ) + ], + [ + 'h' => 'help', + ] ); // Basic check to see if phpunit is installed. @@ -57,7 +57,7 @@ if (!file_exists(__DIR__.'/../../../../vendor/phpunit/phpunit/composer.json') || phpunit_bootstrap_error(PHPUNIT_EXITCODE_PHPUNITMISSING); } -if ($options['install'] or $options['drop']) { +if ($options['install'] || $options['drop']) { define('CACHE_DISABLE_ALL', true); } @@ -65,7 +65,7 @@ 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; @@ -81,7 +81,7 @@ 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'); @@ -99,7 +99,7 @@ $install = $options['install']; $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: @@ -131,7 +131,10 @@ if ($diag) { 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) { @@ -139,10 +142,10 @@ if ($diag) { 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) {