Skip to content

Commit

Permalink
Merge pull request #5902 from kenjis/fix-autoloader-psr4
Browse files Browse the repository at this point in the history
fix: Composer PSR-4 overwrites Config\Autoload::$psr4
  • Loading branch information
kenjis authored Apr 16, 2022
2 parents dd48692 + 0208c72 commit fc6bb8e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion system/Autoloader/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions tests/system/Autoloader/AutoloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit fc6bb8e

Please sign in to comment.