1
0
Fork 0

Speed up installer tests by avoiding lots of bootstrapping and git processes

pull/8997/head
Jordi Boggiano 2020-06-19 17:56:13 +02:00
parent d19f5db568
commit 7a37e78a30
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
4 changed files with 39 additions and 5 deletions

View File

@ -356,7 +356,7 @@ class Factory
// load package // load package
$parser = new VersionParser; $parser = new VersionParser;
$guesser = new VersionGuesser($config, $process, $parser); $guesser = new VersionGuesser($config, $process, $parser);
$loader = new Package\Loader\RootPackageLoader($rm, $config, $parser, $guesser, $io); $loader = $this->loadRootPackage($rm, $config, $parser, $guesser, $io);
$package = $loader->load($localConfig, 'Composer\Package\RootPackage', $cwd); $package = $loader->load($localConfig, 'Composer\Package\RootPackage', $cwd);
$composer->setPackage($package); $composer->setPackage($package);
@ -567,6 +567,11 @@ class Factory
} }
} }
protected function loadRootPackage(RepositoryManager $rm, Config $config, VersionParser $parser, VersionGuesser $guesser, IOInterface $io)
{
return new Package\Loader\RootPackageLoader($rm, $config, $parser, $guesser, $io);
}
/** /**
* @param IOInterface $io IO instance * @param IOInterface $io IO instance
* @param mixed $config either a configuration array or a filename to read from, if null it will read from * @param mixed $config either a configuration array or a filename to read from, if null it will read from

View File

@ -26,7 +26,7 @@ Installs a dev package from lock using dist
"minimum-stability": "dev" "minimum-stability": "dev"
} }
--RUN-- --RUN--
install --prefer-dist install
--EXPECT-LOCK-- --EXPECT-LOCK--
{ {
"packages": [ "packages": [

View File

@ -14,7 +14,10 @@ namespace Composer\Test;
use Composer\DependencyResolver\Request; use Composer\DependencyResolver\Request;
use Composer\Installer; use Composer\Installer;
use Composer\Console\Application; use Symfony\Component\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Composer\IO\BufferIO; use Composer\IO\BufferIO;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Package\Dumper\ArrayDumper; use Composer\Package\Dumper\ArrayDumper;
@ -263,7 +266,12 @@ class InstallerTest extends TestCase
$installer = Installer::create($io, $composer); $installer = Installer::create($io, $composer);
$application = new Application; $application = new Application;
$application->get('install')->setCode(function ($input, $output) use ($installer) { $install = new Command('install');
$install->addOption('ignore-platform-reqs', null, InputOption::VALUE_NONE);
$install->addOption('ignore-platform-req', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY);
$install->addOption('no-dev', null, InputOption::VALUE_NONE);
$install->addOption('dry-run', null, InputOption::VALUE_NONE);
$install->setCode(function ($input, $output) use ($installer) {
$ignorePlatformReqs = $input->getOption('ignore-platform-reqs') ?: ($input->getOption('ignore-platform-req') ?: false); $ignorePlatformReqs = $input->getOption('ignore-platform-reqs') ?: ($input->getOption('ignore-platform-req') ?: false);
$installer $installer
@ -273,8 +281,21 @@ class InstallerTest extends TestCase
return $installer->run(); return $installer->run();
}); });
$application->add($install);
$application->get('update')->setCode(function ($input, $output) use ($installer) { $update = new Command('update');
$update->addOption('ignore-platform-reqs', null, InputOption::VALUE_NONE);
$update->addOption('ignore-platform-req', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY);
$update->addOption('no-dev', null, InputOption::VALUE_NONE);
$update->addOption('no-install', null, InputOption::VALUE_NONE);
$update->addOption('dry-run', null, InputOption::VALUE_NONE);
$update->addOption('lock', null, InputOption::VALUE_NONE);
$update->addOption('with-all-dependencies', null, InputOption::VALUE_NONE);
$update->addOption('with-dependencies', null, InputOption::VALUE_NONE);
$update->addOption('prefer-stable', null, InputOption::VALUE_NONE);
$update->addOption('prefer-lowest', null, InputOption::VALUE_NONE);
$update->addArgument('packages', InputArgument::IS_ARRAY | InputArgument::OPTIONAL);
$update->setCode(function ($input, $output) use ($installer) {
$packages = $input->getArgument('packages'); $packages = $input->getArgument('packages');
$filteredPackages = array_filter($packages, function ($package) { $filteredPackages = array_filter($packages, function ($package) {
return !in_array($package, array('lock', 'nothing', 'mirrors'), true); return !in_array($package, array('lock', 'nothing', 'mirrors'), true);
@ -305,6 +326,7 @@ class InstallerTest extends TestCase
return $installer->run(); return $installer->run();
}); });
$application->add($update);
if (!preg_match('{^(install|update)\b}', $run)) { if (!preg_match('{^(install|update)\b}', $run)) {
throw new \UnexpectedValueException('The run command only supports install and update'); throw new \UnexpectedValueException('The run command only supports install and update');

View File

@ -17,6 +17,8 @@ use Composer\Config;
use Composer\Factory; use Composer\Factory;
use Composer\Repository\RepositoryManager; use Composer\Repository\RepositoryManager;
use Composer\Repository\WritableRepositoryInterface; use Composer\Repository\WritableRepositoryInterface;
use Composer\Package\Version\VersionGuesser;
use Composer\Package\Version\VersionParser;
use Composer\Package\RootPackageInterface; use Composer\Package\RootPackageInterface;
use Composer\Installer; use Composer\Installer;
use Composer\EventDispatcher\EventDispatcher; use Composer\EventDispatcher\EventDispatcher;
@ -39,6 +41,11 @@ class FactoryMock extends Factory
return $config; return $config;
} }
protected function loadRootPackage(RepositoryManager $rm, Config $config, VersionParser $parser, VersionGuesser $guesser, IOInterface $io)
{
return new \Composer\Package\Loader\RootPackageLoader($rm, $config, $parser, new VersionGuesserMock(), $io);
}
protected function addLocalRepository(IOInterface $io, RepositoryManager $rm, $vendorDir, RootPackageInterface $rootPackage) protected function addLocalRepository(IOInterface $io, RepositoryManager $rm, $vendorDir, RootPackageInterface $rootPackage)
{ {
} }