diff --git a/src/Composer/Command/BaseDependencyCommand.php b/src/Composer/Command/BaseDependencyCommand.php index ff7bae2fe..ca80fa246 100644 --- a/src/Composer/Command/BaseDependencyCommand.php +++ b/src/Composer/Command/BaseDependencyCommand.php @@ -12,7 +12,6 @@ namespace Composer\Command; -use Composer\DependencyResolver\Pool; use Composer\Package\Link; use Composer\Package\PackageInterface; use Composer\Repository\ArrayRepository; @@ -79,7 +78,7 @@ class BaseDependencyCommand extends BaseCommand $composer->getRepositoryManager()->getLocalRepository(), new PlatformRepository(array(), $platformOverrides), )); - $repositorySet = new RepositorySet(new Pool()); + $repositorySet = new RepositorySet(); $repositorySet->addRepository($repository); // Parse package name and constraint diff --git a/src/Composer/Command/CreateProjectCommand.php b/src/Composer/Command/CreateProjectCommand.php index 4c5a21794..1b58d59c5 100644 --- a/src/Composer/Command/CreateProjectCommand.php +++ b/src/Composer/Command/CreateProjectCommand.php @@ -20,7 +20,6 @@ use Composer\Installer\InstallationManager; use Composer\Installer\SuggestedPackagesReporter; use Composer\IO\IOInterface; use Composer\Package\BasePackage; -use Composer\DependencyResolver\Pool; use Composer\DependencyResolver\Operation\InstallOperation; use Composer\Package\Version\VersionSelector; use Composer\Package\AliasPackage; @@ -291,7 +290,7 @@ EOT throw new \InvalidArgumentException('Invalid stability provided ('.$stability.'), must be one of: '.implode(', ', array_keys(BasePackage::$stabilities))); } - $repositorySet = new RepositorySet(new Pool($stability)); + $repositorySet = new RepositorySet(array(), $stability); $repositorySet->addRepository($sourceRepo); $phpVersion = null; diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index 86c55b152..03504e29a 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -12,7 +12,6 @@ namespace Composer\Command; -use Composer\DependencyResolver\Pool; use Composer\Factory; use Composer\Json\JsonFile; use Composer\Package\BasePackage; @@ -643,7 +642,7 @@ EOT $key = $minimumStability ?: 'default'; if (!isset($this->repositorySets[$key])) { - $this->repositorySets[$key] = $repositorySet = new RepositorySet(new Pool($minimumStability ?: $this->getMinimumStability($input))); + $this->repositorySets[$key] = $repositorySet = new RepositorySet(array(), $minimumStability ?: $this->getMinimumStability($input)); $repositorySet->addRepository($this->getRepos()); } diff --git a/src/Composer/Command/ShowCommand.php b/src/Composer/Command/ShowCommand.php index edb7198c9..94ec78362 100644 --- a/src/Composer/Command/ShowCommand.php +++ b/src/Composer/Command/ShowCommand.php @@ -14,7 +14,6 @@ namespace Composer\Command; use Composer\Composer; use Composer\DependencyResolver\DefaultPolicy; -use Composer\DependencyResolver\Pool; use Composer\Json\JsonFile; use Composer\Package\BasePackage; use Composer\Package\CompletePackageInterface; @@ -524,7 +523,7 @@ EOT $constraint = is_string($version) ? $this->versionParser->parseConstraints($version) : $version; $policy = new DefaultPolicy(); - $repositorySet = new RepositorySet(new Pool('dev')); + $repositorySet = new RepositorySet(array(), 'dev'); $repositorySet->addRepository($repos); $matchedPackage = null; @@ -985,7 +984,7 @@ EOT private function getRepositorySet(Composer $composer) { if (!$this->repositorySet) { - $this->repositorySet = new RepositorySet(new Pool($composer->getPackage()->getMinimumStability(), $composer->getPackage()->getStabilityFlags())); + $this->repositorySet = new RepositorySet(array(), $composer->getPackage()->getMinimumStability(), $composer->getPackage()->getStabilityFlags()); $this->repositorySet->addRepository(new CompositeRepository($composer->getRepositoryManager()->getRepositories())); } diff --git a/src/Composer/DependencyResolver/Pool.php b/src/Composer/DependencyResolver/Pool.php index c63556974..ee4bace97 100644 --- a/src/Composer/DependencyResolver/Pool.php +++ b/src/Composer/DependencyResolver/Pool.php @@ -54,22 +54,12 @@ class Pool implements \Countable protected $whitelist = null; protected $id = 1; - public function __construct($minimumStability = 'stable', array $stabilityFlags = array(), array $filterRequires = array()) + public function __construct(array $acceptableStabilities, array $stabilityFlags = array(), array $filterRequires = array()) { - $this->versionParser = new VersionParser; - $this->acceptableStabilities = array(); - foreach (BasePackage::$stabilities as $stability => $value) { - if ($value <= BasePackage::$stabilities[$minimumStability]) { - $this->acceptableStabilities[$stability] = $value; - } - } + $this->acceptableStabilities = $acceptableStabilities; $this->stabilityFlags = $stabilityFlags; $this->filterRequires = $filterRequires; - foreach ($filterRequires as $name => $constraint) { - if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $name)) { - unset($this->filterRequires[$name]); - } - } + $this->versionParser = new VersionParser; } public function setWhitelist($whitelist) @@ -202,7 +192,7 @@ class Pool implements \Countable $candidates = array(); foreach ($this->providerRepos as $repo) { - foreach ($repo->whatProvides($this, $name, $bypassFilters) as $candidate) { + foreach ($repo->whatProvides($name, $bypassFilters, array($this, 'isPackageAcceptable')) as $candidate) { $candidates[] = $candidate; if ($candidate->id < 1) { $candidate->setId($this->id++); diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index 73120ea4b..bb27bda3c 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -20,7 +20,6 @@ use Composer\DependencyResolver\Operation\UninstallOperation; use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation; use Composer\DependencyResolver\Operation\OperationInterface; use Composer\DependencyResolver\PolicyInterface; -use Composer\DependencyResolver\Pool; use Composer\DependencyResolver\Request; use Composer\DependencyResolver\Rule; use Composer\DependencyResolver\Solver; @@ -371,19 +370,19 @@ class Installer // creating repository set $policy = $this->createPolicy(); - $repositorySet = $this->createRepositorySet($this->update ? null : $lockedRepository); - $repositorySet->addRepository($installedRepo, $aliases); + $repositorySet = $this->createRepositorySet($aliases, $this->update ? null : $lockedRepository); + $repositorySet->addRepository($installedRepo); if ($this->update) { $repositories = $this->repositoryManager->getRepositories(); foreach ($repositories as $repository) { - $repositorySet->addRepository($repository, $aliases); + $repositorySet->addRepository($repository); } } // Add the locked repository after the others in case we are doing a // partial update so missing packages can be found there still. // For installs from lock it's the only one added so it is first if ($lockedRepository) { - $repositorySet->addRepository($lockedRepository, $aliases); + $repositorySet->addRepository($lockedRepository); } // creating requirements request @@ -465,6 +464,8 @@ class Installer } } + $repositorySet->getPoolTemp(); // TODO remove this, but ensures ids are set before dev packages are processed in advance of solver + // force dev packages to have the latest links if we update or install from a (potentially new) lock $this->processDevPackages($localRepo, $repositorySet, $policy, $repositories, $installedRepo, $lockedRepository, 'force-links'); @@ -685,9 +686,9 @@ class Installer unset($tempLocalRepo, $loader, $dumper); $policy = $this->createPolicy(); - $repositorySet = $this->createRepositorySet(); + $repositorySet = $this->createRepositorySet($aliases); $installedRepo = $this->createInstalledRepo($localRepo, $platformRepo); - $repositorySet->addRepository($installedRepo, $aliases); + $repositorySet->addRepository($installedRepo); // creating requirements request without dev requirements $request = $this->createRequest($this->package, $platformRepo); @@ -844,17 +845,12 @@ class Installer return $installedRepo; } - private function createRepositorySet($lockedRepository = null) - { - $pool = $this->createPool($lockedRepository); - return new RepositorySet($pool); - } - /** - * @param RepositoryInterface|null $lockedRepository - * @return Pool + * @param array $rootAliases + * @param RepositoryInterface|null $lockedRepository + * @return RepositorySet */ - private function createPool(RepositoryInterface $lockedRepository = null) + private function createRepositorySet(array $rootAliases = array(), $lockedRepository = null) { if ($this->update) { $minimumStability = $this->package->getMinimumStability(); @@ -886,7 +882,7 @@ class Installer } } - return new Pool($minimumStability, $stabilityFlags, $rootConstraints); + return new RepositorySet($rootAliases, $minimumStability, $stabilityFlags, $rootConstraints); } /** @@ -1319,7 +1315,7 @@ class Installer } } - $repositorySet = new RepositorySet(new Pool('dev')); + $repositorySet = new RepositorySet(array(), 'dev'); $repositorySet->addRepository($localOrLockRepo); $seen = array(); @@ -1354,11 +1350,11 @@ class Installer while (!$packageQueue->isEmpty()) { $package = $packageQueue->dequeue(); - if (isset($seen[$package->getId()])) { + if (isset($seen[spl_object_hash($package)])) { continue; } - $seen[$package->getId()] = true; + $seen[spl_object_hash($package)] = true; $this->updateWhitelist[$package->getName()] = true; if (!$this->whitelistDependencies && !$this->whitelistAllDependencies) { diff --git a/src/Composer/Plugin/PluginManager.php b/src/Composer/Plugin/PluginManager.php index c6bdefc5a..d16c51db1 100644 --- a/src/Composer/Plugin/PluginManager.php +++ b/src/Composer/Plugin/PluginManager.php @@ -23,7 +23,6 @@ use Composer\Package\PackageInterface; use Composer\Package\Link; use Composer\Repository\RepositorySet; use Composer\Semver\Constraint\Constraint; -use Composer\DependencyResolver\Pool; use Composer\Plugin\Capability\Capability; /** @@ -158,7 +157,7 @@ class PluginManager $localRepo = $this->composer->getRepositoryManager()->getLocalRepository(); $globalRepo = $this->globalComposer ? $this->globalComposer->getRepositoryManager()->getLocalRepository() : null; - $repositorySet = new RepositorySet(new Pool('dev')); + $repositorySet = new RepositorySet(array(), 'dev'); $repositorySet->addRepository($localRepo); if ($globalRepo) { $repositorySet->addRepository($globalRepo); diff --git a/src/Composer/Repository/ComposerRepository.php b/src/Composer/Repository/ComposerRepository.php index 8a5da2b23..cec2ae948 100644 --- a/src/Composer/Repository/ComposerRepository.php +++ b/src/Composer/Repository/ComposerRepository.php @@ -16,7 +16,6 @@ use Composer\Package\Loader\ArrayLoader; use Composer\Package\PackageInterface; use Composer\Package\AliasPackage; use Composer\Package\Version\VersionParser; -use Composer\DependencyResolver\Pool; use Composer\Json\JsonFile; use Composer\Cache; use Composer\Config; @@ -136,7 +135,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito foreach ($this->getProviderNames() as $providerName) { if ($name === $providerName) { - $packages = $this->whatProvides(new Pool('dev'), $providerName); + $packages = $this->whatProvides($providerName); foreach ($packages as $package) { if ($name === $package->getName()) { $pkgConstraint = new Constraint('==', $package->getVersion()); @@ -170,7 +169,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito foreach ($this->getProviderNames() as $providerName) { if ($name === $providerName) { - $candidates = $this->whatProvides(new Pool('dev'), $providerName); + $candidates = $this->whatProvides($providerName); // TODO what is the point of this? foreach ($candidates as $package) { if ($name === $package->getName()) { $pkgConstraint = new Constraint('==', $package->getVersion()); @@ -289,12 +288,12 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito } /** - * @param Pool $pool - * @param string $name package name - * @param bool $bypassFilters If set to true, this bypasses the stability filtering, and forces a recompute without cache + * @param string $name package name + * @param bool $bypassFilters If set to true, this bypasses the stability filtering, and forces a recompute without cache + * @param callable $isPackageAcceptableCallable * @return array|mixed */ - public function whatProvides(Pool $pool, $name, $bypassFilters = false) + public function whatProvides($name, $bypassFilters = false, $isPackageAcceptableCallable = null) { if (isset($this->providers[$name]) && !$bypassFilters) { return $this->providers[$name]; @@ -395,7 +394,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito } } } else { - if (!$bypassFilters && !$pool->isPackageAcceptable(strtolower($version['name']), VersionParser::parseStability($version['version']))) { + if (!$bypassFilters && (!$isPackageAcceptableCallable || !call_user_func($isPackageAcceptableCallable, strtolower($version['name']), VersionParser::parseStability($version['version'])))) { continue; } diff --git a/src/Composer/Repository/RepositorySet.php b/src/Composer/Repository/RepositorySet.php index e6b6db26b..d3c652ccb 100644 --- a/src/Composer/Repository/RepositorySet.php +++ b/src/Composer/Repository/RepositorySet.php @@ -24,36 +24,132 @@ use Composer\Semver\Constraint\ConstraintInterface; */ class RepositorySet { - private $pool; + /** @var array */ + private $rootAliases; - public function __construct(Pool $pool) + /** @var RepositoryInterface[] */ + private $repositories; + + /** @var ComposerRepository[] */ + private $providerRepos; + + private $acceptableStabilities; + private $stabilityFlags; + protected $filterRequires; + + /** @var Pool */ + private $pool; // TODO remove this + + public function __construct(array $rootAliases = array(), $minimumStability = 'stable', array $stabilityFlags = array(), array $filterRequires = array()) { - $this->pool = $pool; + $this->rootAliases = $rootAliases; + + $this->acceptableStabilities = array(); + foreach (BasePackage::$stabilities as $stability => $value) { + if ($value <= BasePackage::$stabilities[$minimumStability]) { + $this->acceptableStabilities[$stability] = $value; + } + } + $this->stabilityFlags = $stabilityFlags; + $this->filterRequires = $filterRequires; + foreach ($filterRequires as $name => $constraint) { + if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $name)) { + unset($this->filterRequires[$name]); + } + } } - public function addRepository(RepositoryInterface $repo, $rootAliases = array()) + /** + * Adds a repository to this repository set + * + * @param RepositoryInterface $repo A package repository + */ + public function addRepository(RepositoryInterface $repo) { - return $this->pool->addRepository($repo, $rootAliases); + if ($repo instanceof CompositeRepository) { + $repos = $repo->getRepositories(); + } else { + $repos = array($repo); + } + + foreach ($repos as $repo) { + $this->repositories[] = $repo; + if ($repo instanceof ComposerRepository && $repo->hasProviders()) { + $this->providerRepos[] = $repo; + } + } } public function isPackageAcceptable($name, $stability) { - return $this->pool->isPackageAcceptable($name, $stability); + foreach ((array) $name as $n) { + // allow if package matches the global stability requirement and has no exception + if (!isset($this->stabilityFlags[$n]) && isset($this->acceptableStabilities[$stability])) { + return true; + } + + // allow if package matches the package-specific stability flag + if (isset($this->stabilityFlags[$n]) && BasePackage::$stabilities[$stability] <= $this->stabilityFlags[$n]) { + return true; + } + } + + return false; } + /** + * Find packages matching name and optionally a constraint in all repositories + * + * @param $name + * @param ConstraintInterface|null $constraint + * @return array + */ public function findPackages($name, ConstraintInterface $constraint = null) { - return $this->pool->whatProvides($name, $constraint, true); + $packages = array(); + foreach ($this->repositories as $repository) { + $packages[] = $repository->findPackages($name, $constraint) ?: array(); + } + + $candidates = $packages ? call_user_func_array('array_merge', $packages) : array(); + + $result = array(); + foreach ($candidates as $candidate) { + if ($this->isPackageAcceptable($candidate->getNames(), $candidate->getStability())) { + $result[] = $candidate; + } + } + + return $candidates; } + /** + * Create a pool for dependency resolution from the packages in this repository set. + * + * @return Pool + */ public function createPool() { + if ($this->pool) { + return $this->pool; + } + + $this->pool = new Pool($this->acceptableStabilities, $this->stabilityFlags, $this->filterRequires); + + foreach ($this->repositories as $repository) { + $this->pool->addRepository($repository, $this->rootAliases); + } + return $this->pool; } // TODO get rid of this function public function getPoolTemp() { - return $this->pool; + if (!$this->pool) { + return $this->createPool(); + } else { + return $this->pool; + } } } diff --git a/tests/Composer/Test/DependencyResolver/DefaultPolicyTest.php b/tests/Composer/Test/DependencyResolver/DefaultPolicyTest.php index a73139d54..34a1c092b 100644 --- a/tests/Composer/Test/DependencyResolver/DefaultPolicyTest.php +++ b/tests/Composer/Test/DependencyResolver/DefaultPolicyTest.php @@ -18,13 +18,14 @@ use Composer\DependencyResolver\DefaultPolicy; use Composer\DependencyResolver\Pool; use Composer\Package\Link; use Composer\Package\AliasPackage; +use Composer\Repository\RepositorySet; use Composer\Semver\Constraint\Constraint; use Composer\TestCase; class DefaultPolicyTest extends TestCase { - /** @var Pool */ - protected $pool; + /** @var RepositorySet */ + protected $repositorySet; /** @var ArrayRepository */ protected $repo; /** @var ArrayRepository */ @@ -34,7 +35,7 @@ class DefaultPolicyTest extends TestCase public function setUp() { - $this->pool = new Pool('dev'); + $this->repositorySet = new RepositorySet(array(), 'dev'); $this->repo = new ArrayRepository; $this->repoInstalled = new ArrayRepository; @@ -44,12 +45,14 @@ class DefaultPolicyTest extends TestCase public function testSelectSingle() { $this->repo->addPackage($packageA = $this->getPackage('A', '1.0')); - $this->pool->addRepository($this->repo); + $this->repositorySet->addRepository($this->repo); + + $pool = $this->repositorySet->getPoolTemp(); $literals = array($packageA->getId()); $expected = array($packageA->getId()); - $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); + $selected = $this->policy->selectPreferredPackages($pool, array(), $literals); $this->assertSame($expected, $selected); } @@ -58,12 +61,14 @@ class DefaultPolicyTest extends TestCase { $this->repo->addPackage($packageA1 = $this->getPackage('A', '1.0')); $this->repo->addPackage($packageA2 = $this->getPackage('A', '2.0')); - $this->pool->addRepository($this->repo); + $this->repositorySet->addRepository($this->repo); + + $pool = $this->repositorySet->getPoolTemp(); $literals = array($packageA1->getId(), $packageA2->getId()); $expected = array($packageA2->getId()); - $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); + $selected = $this->policy->selectPreferredPackages($pool, array(), $literals); $this->assertSame($expected, $selected); } @@ -72,12 +77,14 @@ class DefaultPolicyTest extends TestCase { $this->repo->addPackage($packageA1 = $this->getPackage('A', '1.0.0')); $this->repo->addPackage($packageA2 = $this->getPackage('A', '1.0.1-alpha')); - $this->pool->addRepository($this->repo); + $this->repositorySet->addRepository($this->repo); + + $pool = $this->repositorySet->getPoolTemp(); $literals = array($packageA1->getId(), $packageA2->getId()); $expected = array($packageA2->getId()); - $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); + $selected = $this->policy->selectPreferredPackages($pool, array(), $literals); $this->assertSame($expected, $selected); } @@ -86,13 +93,15 @@ class DefaultPolicyTest extends TestCase { $this->repo->addPackage($packageA1 = $this->getPackage('A', '1.0.0')); $this->repo->addPackage($packageA2 = $this->getPackage('A', '1.0.1-alpha')); - $this->pool->addRepository($this->repo); + $this->repositorySet->addRepository($this->repo); + + $pool = $this->repositorySet->getPoolTemp(); $literals = array($packageA1->getId(), $packageA2->getId()); $expected = array($packageA1->getId()); $policy = new DefaultPolicy(true); - $selected = $policy->selectPreferredPackages($this->pool, array(), $literals); + $selected = $policy->selectPreferredPackages($pool, array(), $literals); $this->assertSame($expected, $selected); } @@ -101,12 +110,14 @@ class DefaultPolicyTest extends TestCase { $this->repo->addPackage($packageA1 = $this->getPackage('A', 'dev-foo')); $this->repo->addPackage($packageA2 = $this->getPackage('A', '1.0.0')); - $this->pool->addRepository($this->repo); + $this->repositorySet->addRepository($this->repo); + + $pool = $this->repositorySet->getPoolTemp(); $literals = array($packageA1->getId(), $packageA2->getId()); $expected = array($packageA2->getId()); - $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); + $selected = $this->policy->selectPreferredPackages($pool, array(), $literals); $this->assertSame($expected, $selected); } @@ -115,13 +126,15 @@ class DefaultPolicyTest extends TestCase { $this->repo->addPackage($packageA = $this->getPackage('A', '2.0')); $this->repoInstalled->addPackage($packageAInstalled = $this->getPackage('A', '1.0')); - $this->pool->addRepository($this->repoInstalled); - $this->pool->addRepository($this->repo); + $this->repositorySet->addRepository($this->repoInstalled); + $this->repositorySet->addRepository($this->repo); + + $pool = $this->repositorySet->getPoolTemp(); $literals = array($packageA->getId(), $packageAInstalled->getId()); $expected = array($packageA->getId()); - $selected = $this->policy->selectPreferredPackages($this->pool, $this->mapFromRepo($this->repoInstalled), $literals); + $selected = $this->policy->selectPreferredPackages($pool, $this->mapFromRepo($this->repoInstalled), $literals); $this->assertSame($expected, $selected); } @@ -133,14 +146,16 @@ class DefaultPolicyTest extends TestCase $this->repo->addPackage($packageA = $this->getPackage('A', '1.0')); $otherRepository->addPackage($packageAImportant = $this->getPackage('A', '1.0')); - $this->pool->addRepository($this->repoInstalled); - $this->pool->addRepository($otherRepository); - $this->pool->addRepository($this->repo); + $this->repositorySet->addRepository($this->repoInstalled); + $this->repositorySet->addRepository($otherRepository); + $this->repositorySet->addRepository($this->repo); + + $pool = $this->repositorySet->getPoolTemp(); $literals = array($packageA->getId(), $packageAImportant->getId()); $expected = array($packageAImportant->getId()); - $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); + $selected = $this->policy->selectPreferredPackages($pool, array(), $literals); $this->assertSame($expected, $selected); } @@ -155,21 +170,25 @@ class DefaultPolicyTest extends TestCase $repo2->addPackage($package3 = $this->getPackage('A', '1.1')); $repo2->addPackage($package4 = $this->getPackage('A', '1.2')); - $this->pool->addRepository($repo1); - $this->pool->addRepository($repo2); + $this->repositorySet->addRepository($repo1); + $this->repositorySet->addRepository($repo2); + + $pool = $this->repositorySet->getPoolTemp(); $literals = array($package1->getId(), $package2->getId(), $package3->getId(), $package4->getId()); $expected = array($package2->getId()); - $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); + $selected = $this->policy->selectPreferredPackages($pool, array(), $literals); $this->assertSame($expected, $selected); - $this->pool = new Pool('dev'); - $this->pool->addRepository($repo2); - $this->pool->addRepository($repo1); + $this->repositorySet = new RepositorySet(array(), 'dev'); + $this->repositorySet->addRepository($repo2); + $this->repositorySet->addRepository($repo1); + + $pool = $this->repositorySet->getPoolTemp(); $expected = array($package4->getId()); - $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); + $selected = $this->policy->selectPreferredPackages($pool, array(), $literals); $this->assertSame($expected, $selected); } @@ -186,11 +205,13 @@ class DefaultPolicyTest extends TestCase $repoImportant->addPackage($packageA2AliasImportant = new AliasPackage($packageA2Important, '2.1.9999999.9999999-dev', '2.1.x-dev')); $packageAAliasImportant->setRootPackageAlias(true); - $this->pool->addRepository($this->repoInstalled); - $this->pool->addRepository($repoImportant); - $this->pool->addRepository($this->repo); + $this->repositorySet->addRepository($this->repoInstalled); + $this->repositorySet->addRepository($repoImportant); + $this->repositorySet->addRepository($this->repo); - $packages = $this->pool->whatProvides('a', new Constraint('=', '2.1.9999999.9999999-dev')); + $pool = $this->repositorySet->getPoolTemp(); + + $packages = $pool->whatProvides('a', new Constraint('=', '2.1.9999999.9999999-dev')); $literals = array(); foreach ($packages as $package) { $literals[] = $package->getId(); @@ -198,7 +219,7 @@ class DefaultPolicyTest extends TestCase $expected = array($packageAAliasImportant->getId()); - $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); + $selected = $this->policy->selectPreferredPackages($pool, array(), $literals); $this->assertSame($expected, $selected); } @@ -211,12 +232,14 @@ class DefaultPolicyTest extends TestCase $packageA->setProvides(array(new Link('A', 'X', new Constraint('==', '1.0'), 'provides'))); $packageB->setProvides(array(new Link('B', 'X', new Constraint('==', '1.0'), 'provides'))); - $this->pool->addRepository($this->repo); + $this->repositorySet->addRepository($this->repo); + + $pool = $this->repositorySet->getPoolTemp(); $literals = array($packageA->getId(), $packageB->getId()); $expected = $literals; - $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); + $selected = $this->policy->selectPreferredPackages($pool, array(), $literals); $this->assertSame($expected, $selected); } @@ -228,12 +251,14 @@ class DefaultPolicyTest extends TestCase $packageB->setReplaces(array(new Link('B', 'A', new Constraint('==', '1.0'), 'replaces'))); - $this->pool->addRepository($this->repo); + $this->repositorySet->addRepository($this->repo); + + $pool = $this->repositorySet->getPoolTemp(); $literals = array($packageA->getId(), $packageB->getId()); $expected = $literals; - $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); + $selected = $this->policy->selectPreferredPackages($pool, array(), $literals); $this->assertSame($expected, $selected); } @@ -247,12 +272,14 @@ class DefaultPolicyTest extends TestCase $packageA->setReplaces(array(new Link('vendor-a/replacer', 'vendor-a/package', new Constraint('==', '1.0'), 'replaces'))); $packageB->setReplaces(array(new Link('vendor-b/replacer', 'vendor-a/package', new Constraint('==', '1.0'), 'replaces'))); - $this->pool->addRepository($this->repo); + $this->repositorySet->addRepository($this->repo); + + $pool = $this->repositorySet->getPoolTemp(); $literals = array($packageA->getId(), $packageB->getId()); $expected = $literals; - $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals, 'vendor-a/package'); + $selected = $this->policy->selectPreferredPackages($pool, array(), $literals, 'vendor-a/package'); $this->assertEquals($expected, $selected); // test with reversed order in repo @@ -260,13 +287,15 @@ class DefaultPolicyTest extends TestCase $repo->addPackage($packageA = clone $packageA); $repo->addPackage($packageB = clone $packageB); - $pool = new Pool('dev'); - $pool->addRepository($this->repo); + $repositorySet = new RepositorySet(array(), 'dev'); + $repositorySet->addRepository($this->repo); + + $pool = $this->repositorySet->getPoolTemp(); $literals = array($packageA->getId(), $packageB->getId()); $expected = $literals; - $selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals, 'vendor-a/package'); + $selected = $this->policy->selectPreferredPackages($pool, array(), $literals, 'vendor-a/package'); $this->assertSame($expected, $selected); } @@ -286,12 +315,14 @@ class DefaultPolicyTest extends TestCase $this->repo->addPackage($packageA1 = $this->getPackage('A', '1.0')); $this->repo->addPackage($packageA2 = $this->getPackage('A', '2.0')); - $this->pool->addRepository($this->repo); + $this->repositorySet->addRepository($this->repo); + + $pool = $this->repositorySet->getPoolTemp(); $literals = array($packageA1->getId(), $packageA2->getId()); $expected = array($packageA1->getId()); - $selected = $policy->selectPreferredPackages($this->pool, array(), $literals); + $selected = $policy->selectPreferredPackages($pool, array(), $literals); $this->assertSame($expected, $selected); } diff --git a/tests/Composer/Test/DependencyResolver/PoolTest.php b/tests/Composer/Test/DependencyResolver/PoolTest.php index 14b24fc9f..5169586f6 100644 --- a/tests/Composer/Test/DependencyResolver/PoolTest.php +++ b/tests/Composer/Test/DependencyResolver/PoolTest.php @@ -21,7 +21,7 @@ class PoolTest extends TestCase { public function testPool() { - $pool = new Pool; + $pool = $this->createPool(); $repo = new ArrayRepository; $package = $this->getPackage('foo', '1'); @@ -34,7 +34,7 @@ class PoolTest extends TestCase public function testPoolIgnoresIrrelevantPackages() { - $pool = new Pool('stable', array('bar' => BasePackage::STABILITY_BETA)); + $pool = new Pool(array('stable' => BasePackage::STABILITY_STABLE), array('bar' => BasePackage::STABILITY_BETA)); $repo = new ArrayRepository; $repo->addPackage($package = $this->getPackage('bar', '1')); $repo->addPackage($betaPackage = $this->getPackage('bar', '1-beta')); @@ -53,7 +53,7 @@ class PoolTest extends TestCase */ public function testGetPriorityForNotRegisteredRepository() { - $pool = new Pool; + $pool = $this->createPool(); $repository = new ArrayRepository; $pool->getPriority($repository); @@ -61,7 +61,7 @@ class PoolTest extends TestCase public function testGetPriorityWhenRepositoryIsRegistered() { - $pool = new Pool; + $pool = $this->createPool(); $firstRepository = new ArrayRepository; $pool->addRepository($firstRepository); $secondRepository = new ArrayRepository; @@ -76,7 +76,7 @@ class PoolTest extends TestCase public function testWhatProvidesSamePackageForDifferentRepositories() { - $pool = new Pool; + $pool = $this->createPool(); $firstRepository = new ArrayRepository; $secondRepository = new ArrayRepository; @@ -96,7 +96,7 @@ class PoolTest extends TestCase public function testWhatProvidesPackageWithConstraint() { - $pool = new Pool; + $pool = $this->createPool(); $repository = new ArrayRepository; $firstPackage = $this->getPackage('foo', '1'); @@ -113,7 +113,7 @@ class PoolTest extends TestCase public function testPackageById() { - $pool = new Pool; + $pool = $this->createPool(); $repository = new ArrayRepository; $package = $this->getPackage('foo', '1'); @@ -125,8 +125,13 @@ class PoolTest extends TestCase public function testWhatProvidesWhenPackageCannotBeFound() { - $pool = new Pool; + $pool = $this->createPool(); $this->assertEquals(array(), $pool->whatProvides('foo')); } + + protected function createPool() + { + return new Pool(array('stable' => BasePackage::STABILITY_STABLE)); + } } diff --git a/tests/Composer/Test/DependencyResolver/RuleSetIteratorTest.php b/tests/Composer/Test/DependencyResolver/RuleSetIteratorTest.php index 7789881df..24a2e7c54 100644 --- a/tests/Composer/Test/DependencyResolver/RuleSetIteratorTest.php +++ b/tests/Composer/Test/DependencyResolver/RuleSetIteratorTest.php @@ -17,6 +17,7 @@ use Composer\DependencyResolver\Rule; use Composer\DependencyResolver\RuleSet; use Composer\DependencyResolver\RuleSetIterator; use Composer\DependencyResolver\Pool; +use Composer\Package\BasePackage; use PHPUnit\Framework\TestCase; class RuleSetIteratorTest extends TestCase @@ -26,7 +27,7 @@ class RuleSetIteratorTest extends TestCase protected function setUp() { - $this->pool = new Pool; + $this->pool = new Pool(array('stable' => BasePackage::STABILITY_STABLE)); $this->rules = array( RuleSet::TYPE_JOB => array( diff --git a/tests/Composer/Test/DependencyResolver/RuleSetTest.php b/tests/Composer/Test/DependencyResolver/RuleSetTest.php index cecae613d..e9753c848 100644 --- a/tests/Composer/Test/DependencyResolver/RuleSetTest.php +++ b/tests/Composer/Test/DependencyResolver/RuleSetTest.php @@ -16,6 +16,7 @@ use Composer\DependencyResolver\GenericRule; use Composer\DependencyResolver\Rule; use Composer\DependencyResolver\RuleSet; use Composer\DependencyResolver\Pool; +use Composer\Package\BasePackage; use Composer\Repository\ArrayRepository; use Composer\TestCase; @@ -25,7 +26,7 @@ class RuleSetTest extends TestCase public function setUp() { - $this->pool = new Pool; + $this->pool = new Pool(array('stable' => BasePackage::STABILITY_STABLE)); } public function testAdd() diff --git a/tests/Composer/Test/DependencyResolver/RuleTest.php b/tests/Composer/Test/DependencyResolver/RuleTest.php index a0339f27a..c9b3dbe1a 100644 --- a/tests/Composer/Test/DependencyResolver/RuleTest.php +++ b/tests/Composer/Test/DependencyResolver/RuleTest.php @@ -16,6 +16,7 @@ use Composer\DependencyResolver\GenericRule; use Composer\DependencyResolver\Rule; use Composer\DependencyResolver\RuleSet; use Composer\DependencyResolver\Pool; +use Composer\Package\BasePackage; use Composer\Repository\ArrayRepository; use Composer\TestCase; @@ -25,7 +26,7 @@ class RuleTest extends TestCase public function setUp() { - $this->pool = new Pool; + $this->pool = new Pool(array('stable' => BasePackage::STABILITY_STABLE)); } public function testGetHash() diff --git a/tests/Composer/Test/DependencyResolver/SolverTest.php b/tests/Composer/Test/DependencyResolver/SolverTest.php index 0142818fc..1a43c5b60 100644 --- a/tests/Composer/Test/DependencyResolver/SolverTest.php +++ b/tests/Composer/Test/DependencyResolver/SolverTest.php @@ -34,7 +34,7 @@ class SolverTest extends TestCase public function setUp() { - $this->repoSet = new RepositorySet(new Pool); + $this->repoSet = new RepositorySet(array()); $this->repo = new ArrayRepository; $this->repoInstalled = new ArrayRepository; diff --git a/tests/Composer/Test/Plugin/PluginInstallerTest.php b/tests/Composer/Test/Plugin/PluginInstallerTest.php index 26fc63efa..7981177eb 100644 --- a/tests/Composer/Test/Plugin/PluginInstallerTest.php +++ b/tests/Composer/Test/Plugin/PluginInstallerTest.php @@ -130,7 +130,7 @@ class PluginInstallerTest extends TestCase public function testInstallNewPlugin() { $this->repository - ->expects($this->exactly(2)) + ->expects($this->once()) ->method('getPackages') ->will($this->returnValue(array())); $installer = new PluginInstaller($this->io, $this->composer); @@ -145,7 +145,7 @@ class PluginInstallerTest extends TestCase public function testInstallMultiplePlugins() { $this->repository - ->expects($this->exactly(2)) + ->expects($this->once()) ->method('getPackages') ->will($this->returnValue(array($this->packages[3]))); $installer = new PluginInstaller($this->io, $this->composer); @@ -163,7 +163,7 @@ class PluginInstallerTest extends TestCase public function testUpgradeWithNewClassName() { $this->repository - ->expects($this->exactly(3)) + ->expects($this->once()) ->method('getPackages') ->will($this->returnValue(array($this->packages[0]))); $this->repository @@ -182,7 +182,7 @@ class PluginInstallerTest extends TestCase public function testUpgradeWithSameClassName() { $this->repository - ->expects($this->exactly(3)) + ->expects($this->once()) ->method('getPackages') ->will($this->returnValue(array($this->packages[1]))); $this->repository @@ -201,7 +201,7 @@ class PluginInstallerTest extends TestCase public function testRegisterPluginOnlyOneTime() { $this->repository - ->expects($this->exactly(2)) + ->expects($this->once()) ->method('getPackages') ->will($this->returnValue(array())); $installer = new PluginInstaller($this->io, $this->composer); @@ -240,11 +240,11 @@ class PluginInstallerTest extends TestCase // Add the plugins to the repo along with the internal Plugin package on which they all rely. $this->repository - ->expects($this->any()) - ->method('getPackages') - ->will($this->returnCallback(function () use ($plugApiInternalPackage, $plugins) { - return array_merge(array($plugApiInternalPackage), $plugins); - })); + ->expects($this->any()) + ->method('getPackages') + ->will($this->returnCallback(function () use ($plugApiInternalPackage, $plugins) { + return array_merge(array($plugApiInternalPackage), $plugins); + })); $this->pm->loadInstalledPlugins(); } @@ -300,7 +300,7 @@ class PluginInstallerTest extends TestCase public function testCommandProviderCapability() { $this->repository - ->expects($this->exactly(2)) + ->expects($this->once()) ->method('getPackages') ->will($this->returnValue(array($this->packages[7]))); $installer = new PluginInstaller($this->io, $this->composer); diff --git a/tests/Composer/Test/Repository/ComposerRepositoryTest.php b/tests/Composer/Test/Repository/ComposerRepositoryTest.php index 38b459730..fa6809cbb 100644 --- a/tests/Composer/Test/Repository/ComposerRepositoryTest.php +++ b/tests/Composer/Test/Repository/ComposerRepositoryTest.php @@ -142,11 +142,6 @@ class ComposerRepositoryTest extends TestCase ), ))); - $pool = $this->getMockBuilder('Composer\DependencyResolver\Pool')->getMock(); - $pool->expects($this->any()) - ->method('isPackageAcceptable') - ->will($this->returnValue(true)); - $versionParser = new VersionParser(); $repo->setRootAliases(array( 'a' => array( @@ -155,7 +150,7 @@ class ComposerRepositoryTest extends TestCase ), )); - $packages = $repo->whatProvides($pool, 'a'); + $packages = $repo->whatProvides('a', false, array($this, 'isPackageAcceptableReturnTrue')); $this->assertCount(7, $packages); $this->assertEquals(array('1', '1-alias', '2', '2-alias', '2-root', '3', '3-root'), array_keys($packages)); @@ -164,6 +159,11 @@ class ComposerRepositoryTest extends TestCase $this->assertSame($packages['2'], $packages['2-alias']->getAliasOf()); } + public function isPackageAcceptableReturnTrue() + { + return true; + } + public function testSearchWithType() { $repoConfig = array(