diff --git a/.github/scripts/run-random-tests.sh b/.github/scripts/run-random-tests.sh index 45376fb58fb2..23a90f955e2f 100755 --- a/.github/scripts/run-random-tests.sh +++ b/.github/scripts/run-random-tests.sh @@ -23,6 +23,7 @@ ################################################################################ set -u +export LC_NUMERIC=C trap 'kill "${bg_pids[@]:-}" 2>/dev/null; wait 2>/dev/null' EXIT INT TERM ################################################################################ diff --git a/system/Autoloader/Autoloader.php b/system/Autoloader/Autoloader.php index 65c535e8611e..69906d4e162a 100644 --- a/system/Autoloader/Autoloader.php +++ b/system/Autoloader/Autoloader.php @@ -93,6 +93,10 @@ class Autoloader */ protected $helpers = ['url']; + public function __construct(private readonly string $composerPath = COMPOSER_PATH) + { + } + /** * Reads in the configuration array (described above) and stores * the valid parts that we'll need. @@ -127,7 +131,7 @@ public function initialize(Autoload $config, Modules $modules) $this->helpers = [...$this->helpers, ...$config->helpers]; } - if (is_file(COMPOSER_PATH)) { + if (is_file($this->composerPath)) { $this->loadComposerAutoloader($modules); } @@ -139,11 +143,11 @@ private function loadComposerAutoloader(Modules $modules): void // The path to the vendor directory. // We do not want to enforce this, so set the constant if Composer was used. if (! defined('VENDORPATH')) { - define('VENDORPATH', dirname(COMPOSER_PATH) . DIRECTORY_SEPARATOR); + define('VENDORPATH', dirname($this->composerPath) . DIRECTORY_SEPARATOR); } /** @var ClassLoader $composer */ - $composer = include COMPOSER_PATH; + $composer = include $this->composerPath; // Should we load through Composer's namespaces, also? if ($modules->discoverInComposer) { @@ -451,14 +455,14 @@ private function loadComposerNamespaces(ClassLoader $composer, array $composerPa */ protected function discoverComposerNamespaces() { - if (! is_file(COMPOSER_PATH)) { + if (! is_file($this->composerPath)) { return; } /** * @var ClassLoader $composer */ - $composer = include COMPOSER_PATH; + $composer = include $this->composerPath; $paths = $composer->getPrefixesPsr4(); $classes = $composer->getClassMap(); diff --git a/tests/system/Autoloader/AutoloaderTest.php b/tests/system/Autoloader/AutoloaderTest.php index cd73356958fe..ef76091baa39 100644 --- a/tests/system/Autoloader/AutoloaderTest.php +++ b/tests/system/Autoloader/AutoloaderTest.php @@ -367,17 +367,12 @@ public function testComposerPackagesOnlyAndExclude(): void public function testFindsComposerRoutesWithComposerPathNotFound(): void { - $composerPath = COMPOSER_PATH; - $config = new Autoload(); $modules = new Modules(); $modules->discoverInComposer = true; - $loader = new Autoloader(); - - rename(COMPOSER_PATH, COMPOSER_PATH . '.backup'); + $loader = new Autoloader('/nonexistent/path/autoload.php'); $loader->initialize($config, $modules); - rename(COMPOSER_PATH . '.backup', $composerPath); $namespaces = $loader->getNamespace(); $this->assertArrayNotHasKey('Laminas\\Escaper', $namespaces);