MDL-68705 testing: New CLI args to disable composer features

This commit introduces the following new flags:

  --no-composer-self-update   Disable composer self-update of the
                              composer.phar utility

  --no-composer-upgrade       Disable upgrade of development
                              dependencies using Composer.

  --disable-composer          Disable both composer self-update and
                              composer upgrade
This commit is contained in:
Andrew Nicols 2020-08-04 11:21:03 +08:00 committed by Eloy Lafuente (stronk7)
parent b430493ca8
commit 5e60d77da1
2 changed files with 88 additions and 12 deletions

View file

@ -38,8 +38,57 @@ require_once(__DIR__.'/../../../../lib/clilib.php');
require_once(__DIR__.'/../../../../lib/phpunit/bootstraplib.php');
require_once(__DIR__.'/../../../../lib/testing/lib.php');
list($options, $unrecognized) = cli_get_params(
[
'help' => false,
'disable-composer' => false,
'composer-upgrade' => true,
'composer-self-update' => true,
],
[
'h' => 'help',
]
);
$help = "
Utilities to initialise the PHPUnit test site.
Usage:
php init.php [--no-composer-self-update] [--no-composer-upgrade]
[--help]
--no-composer-self-update
Prevent upgrade of the composer utility using its self-update command
--no-composer-upgrade
Prevent update development dependencies using composer
--disable-composer
A shortcut to disable composer self-update and dependency update
Note: Installation of composer and/or dependencies will still happen as required
-h, --help Print out this help
Example from Moodle root directory:
\$ php admin/tool/phpunit/cli/init.php
";
if (!empty($options['help'])) {
echo $help;
exit(0);
}
echo "Initialising Moodle PHPUnit test environment...\n";
testing_update_composer_dependencies();
if ($options['disable-composer']) {
// Disable self-update and upgrade easily.
// Note: Installation will still occur regardless of this setting.
$options['composer-self-update'] = false;
$options['composer-upgrade'] = false;
}
// Install and update composer and dependencies as required.
testing_update_composer_dependencies($options['composer-self-update'], $options['composer-upgrade']);
$output = null;
exec('php --version', $output, $code);