From dd556f989b8a6d6605454c2862d6c8856d18bcbf Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 15 Jan 2020 14:56:58 +0100 Subject: [PATCH] Use LockArrayRepository instead of RepositoryInterface to clearly indicate which type of repo it is in some places --- src/Composer/DependencyResolver/Request.php | 4 +-- src/Composer/Package/Locker.php | 4 +-- src/Composer/Repository/RepositorySet.php | 10 ++++--- .../DependencyResolver/DefaultPolicyTest.php | 26 +++++++++---------- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/Composer/DependencyResolver/Request.php b/src/Composer/DependencyResolver/Request.php index 0656cbbae..d0502c1c5 100644 --- a/src/Composer/DependencyResolver/Request.php +++ b/src/Composer/DependencyResolver/Request.php @@ -15,7 +15,7 @@ namespace Composer\DependencyResolver; use Composer\Package\Package; use Composer\Package\PackageInterface; use Composer\Package\RootAliasPackage; -use Composer\Repository\RepositoryInterface; +use Composer\Repository\LockArrayRepository; use Composer\Semver\Constraint\ConstraintInterface; /** @@ -28,7 +28,7 @@ class Request protected $fixedPackages = array(); protected $unlockables = array(); - public function __construct(RepositoryInterface $lockedRepository = null) + public function __construct(LockArrayRepository $lockedRepository = null) { $this->lockedRepository = $lockedRepository; } diff --git a/src/Composer/Package/Locker.php b/src/Composer/Package/Locker.php index 8069ba50c..1e5ea8531 100644 --- a/src/Composer/Package/Locker.php +++ b/src/Composer/Package/Locker.php @@ -150,7 +150,7 @@ class Locker * * @param bool $withDevReqs true to retrieve the locked dev packages * @throws \RuntimeException - * @return \Composer\Repository\RepositoryInterface + * @return \Composer\Repository\LockArrayRepository */ public function getLockedRepository($withDevReqs = false) { @@ -194,7 +194,7 @@ class Locker return $packages; } - throw new \RuntimeException('Your composer.lock was created before 2012-09-15, and is not supported anymore. Run "composer update" to generate a new one.'); + throw new \RuntimeException('Your composer.lock is invalid. Run "composer update" to generate a new one.'); } /** diff --git a/src/Composer/Repository/RepositorySet.php b/src/Composer/Repository/RepositorySet.php index 6ed647297..9b15a0115 100644 --- a/src/Composer/Repository/RepositorySet.php +++ b/src/Composer/Repository/RepositorySet.php @@ -19,6 +19,7 @@ use Composer\Package\BasePackage; use Composer\Package\Version\VersionParser; use Composer\Repository\CompositeRepository; use Composer\Repository\PlatformRepository; +use Composer\Repository\LockArrayRepository; use Composer\Semver\Constraint\ConstraintInterface; use Composer\Test\DependencyResolver\PoolTest; @@ -150,14 +151,15 @@ class RepositorySet } // TODO unify this with above in some simpler version without "request"? - public function createPoolForPackage($packageName) + public function createPoolForPackage($packageName, LockArrayRepository $lockedRepo = null) { - return $this->createPoolForPackages(array($packageName)); + return $this->createPoolForPackages(array($packageName), $lockedRepo); } - public function createPoolForPackages($packageNames) + public function createPoolForPackages($packageNames, LockArrayRepository $lockedRepo = null) { - $request = new Request(); + $request = new Request($lockedRepo); + foreach ($packageNames as $packageName) { $request->install($packageName); } diff --git a/tests/Composer/Test/DependencyResolver/DefaultPolicyTest.php b/tests/Composer/Test/DependencyResolver/DefaultPolicyTest.php index 827a9181d..a2869290e 100644 --- a/tests/Composer/Test/DependencyResolver/DefaultPolicyTest.php +++ b/tests/Composer/Test/DependencyResolver/DefaultPolicyTest.php @@ -48,7 +48,7 @@ class DefaultPolicyTest extends TestCase $this->repo->addPackage($packageA = $this->getPackage('A', '1.0')); $this->repositorySet->addRepository($this->repo); - $pool = $this->repositorySet->createPoolForPackage('A'); + $pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked); $literals = array($packageA->getId()); $expected = array($packageA->getId()); @@ -64,7 +64,7 @@ class DefaultPolicyTest extends TestCase $this->repo->addPackage($packageA2 = $this->getPackage('A', '2.0')); $this->repositorySet->addRepository($this->repo); - $pool = $this->repositorySet->createPoolForPackage('A'); + $pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked); $literals = array($packageA1->getId(), $packageA2->getId()); $expected = array($packageA2->getId()); @@ -80,7 +80,7 @@ class DefaultPolicyTest extends TestCase $this->repo->addPackage($packageA2 = $this->getPackage('A', '1.0.1-alpha')); $this->repositorySet->addRepository($this->repo); - $pool = $this->repositorySet->createPoolForPackage('A'); + $pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked); $literals = array($packageA1->getId(), $packageA2->getId()); $expected = array($packageA2->getId()); @@ -96,7 +96,7 @@ class DefaultPolicyTest extends TestCase $this->repo->addPackage($packageA2 = $this->getPackage('A', '1.0.1-alpha')); $this->repositorySet->addRepository($this->repo); - $pool = $this->repositorySet->createPoolForPackage('A'); + $pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked); $literals = array($packageA1->getId(), $packageA2->getId()); $expected = array($packageA1->getId()); @@ -113,7 +113,7 @@ class DefaultPolicyTest extends TestCase $this->repo->addPackage($packageA2 = $this->getPackage('A', '1.0.0')); $this->repositorySet->addRepository($this->repo); - $pool = $this->repositorySet->createPoolForPackage('A'); + $pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked); $literals = array($packageA1->getId(), $packageA2->getId()); $expected = array($packageA2->getId()); @@ -136,7 +136,7 @@ class DefaultPolicyTest extends TestCase $this->repositorySet->addRepository($repo1); $this->repositorySet->addRepository($repo2); - $pool = $this->repositorySet->createPoolForPackage('A'); + $pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked); $literals = array($package1->getId(), $package2->getId(), $package3->getId(), $package4->getId()); $expected = array($package2->getId()); @@ -148,7 +148,7 @@ class DefaultPolicyTest extends TestCase $this->repositorySet->addRepository($repo2); $this->repositorySet->addRepository($repo1); - $pool = $this->repositorySet->createPoolForPackage('A'); + $pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked); $expected = array($package4->getId()); $selected = $this->policy->selectPreferredPackages($pool, $literals); @@ -172,7 +172,7 @@ class DefaultPolicyTest extends TestCase $this->repositorySet->addRepository($this->repo); $this->repositorySet->addRepository($this->repoLocked); - $pool = $this->repositorySet->createPoolForPackage('A'); + $pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked); $packages = $pool->whatProvides('a', new Constraint('=', '2.1.9999999.9999999-dev')); $literals = array(); @@ -197,7 +197,7 @@ class DefaultPolicyTest extends TestCase $this->repositorySet->addRepository($this->repo); - $pool = $this->repositorySet->createPoolForPackages(array('A', 'B')); + $pool = $this->repositorySet->createPoolForPackages(array('A', 'B'), $this->repoLocked); $literals = array($packageA->getId(), $packageB->getId()); $expected = $literals; @@ -216,7 +216,7 @@ class DefaultPolicyTest extends TestCase $this->repositorySet->addRepository($this->repo); - $pool = $this->repositorySet->createPoolForPackages(array('A', 'B')); + $pool = $this->repositorySet->createPoolForPackages(array('A', 'B'), $this->repoLocked); $literals = array($packageA->getId(), $packageB->getId()); $expected = $literals; @@ -237,7 +237,7 @@ class DefaultPolicyTest extends TestCase $this->repositorySet->addRepository($this->repo); - $pool = $this->repositorySet->createPoolForPackages(array('vendor-a/replacer', 'vendor-b/replacer')); + $pool = $this->repositorySet->createPoolForPackages(array('vendor-a/replacer', 'vendor-b/replacer'), $this->repoLocked); $literals = array($packageA->getId(), $packageB->getId()); $expected = $literals; @@ -253,7 +253,7 @@ class DefaultPolicyTest extends TestCase $repositorySet = new RepositorySet(array(), array(), 'dev'); $repositorySet->addRepository($this->repo); - $pool = $this->repositorySet->createPoolForPackages(array('vendor-a/replacer', 'vendor-b/replacer')); + $pool = $this->repositorySet->createPoolForPackages(array('vendor-a/replacer', 'vendor-b/replacer'), $this->repoLocked); $literals = array($packageA->getId(), $packageB->getId()); $expected = $literals; @@ -270,7 +270,7 @@ class DefaultPolicyTest extends TestCase $this->repo->addPackage($packageA2 = $this->getPackage('A', '2.0')); $this->repositorySet->addRepository($this->repo); - $pool = $this->repositorySet->createPoolForPackage('A'); + $pool = $this->repositorySet->createPoolForPackage('A', $this->repoLocked); $literals = array($packageA1->getId(), $packageA2->getId()); $expected = array($packageA1->getId());