Fix plugin autoloading including files autoload rules from the root package, fixes #10382 (#10386)

main
Jordi Boggiano 2 years ago committed by GitHub
parent 25835bb5cd
commit 226689b90c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -216,6 +216,17 @@ class PluginManager
$globalRepo = $this->globalComposer !== null ? $this->globalComposer->getRepositoryManager()->getLocalRepository() : null;
$rootPackage = clone $this->composer->getPackage();
// clear files autoload rules from the root package as the root dependencies are not
// necessarily all present yet when booting this runtime autoloader
$rootPackageAutoloads = $rootPackage->getAutoload();
$rootPackageAutoloads['files'] = array();
$rootPackage->setAutoload($rootPackageAutoloads);
$rootPackageAutoloads = $rootPackage->getDevAutoload();
$rootPackageAutoloads['files'] = array();
$rootPackage->setDevAutoload($rootPackageAutoloads);
unset($rootPackageAutoloads);
$rootPackageRepo = new RootPackageRepository($rootPackage);
$installedRepo = new InstalledRepository(array($localRepo, $rootPackageRepo));
if ($globalRepo) {

@ -0,0 +1,3 @@
<?php
throw new \LogicException('This file should not be autoloaded');

@ -152,6 +152,28 @@ class PluginInstallerTest extends TestCase
);
}
public function testInstallPluginWithRootPackageHavingFilesAutoload()
{
$this->repository
->expects($this->any())
->method('getPackages')
->will($this->returnValue(array()));
$installer = new PluginInstaller($this->io, $this->composer);
$this->pm->loadInstalledPlugins();
$this->autoloadGenerator->setDevMode(true);
$this->composer->getPackage()->setAutoload(array('files' => array(__DIR__ . '/Fixtures/files_autoload_which_should_not_run.php')));
$this->composer->getPackage()->setDevAutoload(array('files' => array(__DIR__ . '/Fixtures/files_autoload_which_should_not_run.php')));
$installer->install($this->repository, $this->packages[0]);
$plugins = $this->pm->getPlugins();
$this->assertEquals(
'activate v1'.PHP_EOL,
$this->io->getOutput()
);
$this->assertEquals('installer-v1', $plugins[0]->version); // @phpstan-ignore-line
}
public function testInstallMultiplePlugins()
{
$this->repository

Loading…
Cancel
Save