From 5f31b37e1dc0a06562e65c113eede1eeb4d25199 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" Date: Sat, 13 Jan 2024 18:13:52 +0100 Subject: [PATCH] MDL-80591 phpunit: delegate run to phpunit binary Instead of manually including composer's auto-loading stuff and then run PHPUnit\TextUI\Command::main(), now we are using the PHPUnit "binary". That way behaviour should be 100% the same than running vendor/bin/phpunit (recommended instead of util.php --run). Also, note that, for other util.php commands, we still need composer's auto-loading to happen, so we have moved it immediately after the --run command. Finally, a few more file_exists() conditions have been added to ensure that PHPUnit is properly installed. Redundant but... --- admin/tool/phpunit/cli/util.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/admin/tool/phpunit/cli/util.php b/admin/tool/phpunit/cli/util.php index 6bda8483c5e..8d60ff3c952 100644 --- a/admin/tool/phpunit/cli/util.php +++ b/admin/tool/phpunit/cli/util.php @@ -50,12 +50,10 @@ list($options, $unrecognized) = cli_get_params( ) ); -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); } @@ -74,12 +72,13 @@ if ($options['run']) { } } $_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