diff --git a/src/Composer/Factory.php b/src/Composer/Factory.php index 509fa62b0..8eb2d24cf 100644 --- a/src/Composer/Factory.php +++ b/src/Composer/Factory.php @@ -356,7 +356,7 @@ class Factory // load package $parser = new VersionParser; $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); $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 mixed $config either a configuration array or a filename to read from, if null it will read from diff --git a/tests/Composer/Test/Fixtures/installer/install-dev-using-dist.test b/tests/Composer/Test/Fixtures/installer/install-dev-using-dist.test index 4cb2dbbb5..3c171a4b0 100644 --- a/tests/Composer/Test/Fixtures/installer/install-dev-using-dist.test +++ b/tests/Composer/Test/Fixtures/installer/install-dev-using-dist.test @@ -26,7 +26,7 @@ Installs a dev package from lock using dist "minimum-stability": "dev" } --RUN-- -install --prefer-dist +install --EXPECT-LOCK-- { "packages": [ diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index 94a56147e..0be8af711 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -14,7 +14,10 @@ namespace Composer\Test; use Composer\DependencyResolver\Request; 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\Json\JsonFile; use Composer\Package\Dumper\ArrayDumper; @@ -263,7 +266,12 @@ class InstallerTest extends TestCase $installer = Installer::create($io, $composer); $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); $installer @@ -273,8 +281,21 @@ class InstallerTest extends TestCase 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'); $filteredPackages = array_filter($packages, function ($package) { return !in_array($package, array('lock', 'nothing', 'mirrors'), true); @@ -305,6 +326,7 @@ class InstallerTest extends TestCase return $installer->run(); }); + $application->add($update); if (!preg_match('{^(install|update)\b}', $run)) { throw new \UnexpectedValueException('The run command only supports install and update'); diff --git a/tests/Composer/Test/Mock/FactoryMock.php b/tests/Composer/Test/Mock/FactoryMock.php index a073f0ab7..d8b618647 100644 --- a/tests/Composer/Test/Mock/FactoryMock.php +++ b/tests/Composer/Test/Mock/FactoryMock.php @@ -17,6 +17,8 @@ use Composer\Config; use Composer\Factory; use Composer\Repository\RepositoryManager; use Composer\Repository\WritableRepositoryInterface; +use Composer\Package\Version\VersionGuesser; +use Composer\Package\Version\VersionParser; use Composer\Package\RootPackageInterface; use Composer\Installer; use Composer\EventDispatcher\EventDispatcher; @@ -39,6 +41,11 @@ class FactoryMock extends Factory 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) { }