diff --git a/system/Autoloader/Autoloader.php b/system/Autoloader/Autoloader.php index 520e669be685..311428fe4165 100644 --- a/system/Autoloader/Autoloader.php +++ b/system/Autoloader/Autoloader.php @@ -328,7 +328,7 @@ private function loadComposerNamespaces(ClassLoader $composer): void $newPaths[rtrim($key, '\\ ')] = $value; } - $this->prefixes = array_merge($this->prefixes, $newPaths); + $this->addNamespace($newPaths); } private function loadComposerClassmap(ClassLoader $composer): void diff --git a/tests/system/Autoloader/AutoloaderTest.php b/tests/system/Autoloader/AutoloaderTest.php index 82e0307affad..1279910d2289 100644 --- a/tests/system/Autoloader/AutoloaderTest.php +++ b/tests/system/Autoloader/AutoloaderTest.php @@ -233,6 +233,23 @@ public function testFindsComposerRoutes() $this->assertArrayHasKey('Laminas\\Escaper', $namespaces); } + public function testComposerNamespaceDoesNotOverwriteConfigAutoloadPsr4() + { + $config = new Autoload(); + $config->psr4 = [ + 'Psr\Log' => '/Config/Autoload/Psr/Log/', + ]; + $modules = new Modules(); + $modules->discoverInComposer = true; + + $this->loader = new Autoloader(); + $this->loader->initialize($config, $modules); + + $namespaces = $this->loader->getNamespace(); + $this->assertSame('/Config/Autoload/Psr/Log/', $namespaces['Psr\Log'][0]); + $this->assertStringContainsString(VENDORPATH, $namespaces['Psr\Log'][1]); + } + public function testFindsComposerRoutesWithComposerPathNotFound() { $composerPath = COMPOSER_PATH;