1
0
Fork 0

Merge pull request #7625 from naderman/repository-set

Separate RepositorySet from Package Pool, load only metadata of packages directly required
pull/7629/head
Nils Adermann 2018-09-12 14:22:01 +02:00 committed by GitHub
commit 5c491ecc9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 826 additions and 507 deletions

View File

@ -12,7 +12,6 @@
namespace Composer\Command; namespace Composer\Command;
use Composer\DependencyResolver\Pool;
use Composer\Package\Link; use Composer\Package\Link;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Repository\ArrayRepository; use Composer\Repository\ArrayRepository;
@ -21,6 +20,7 @@ use Composer\Repository\PlatformRepository;
use Composer\Repository\RepositoryFactory; use Composer\Repository\RepositoryFactory;
use Composer\Plugin\CommandEvent; use Composer\Plugin\CommandEvent;
use Composer\Plugin\PluginEvents; use Composer\Plugin\PluginEvents;
use Composer\Repository\RepositorySet;
use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Formatter\OutputFormatterStyle;
use Composer\Package\Version\VersionParser; use Composer\Package\Version\VersionParser;
use Symfony\Component\Console\Helper\Table; use Symfony\Component\Console\Helper\Table;
@ -71,15 +71,15 @@ class BaseDependencyCommand extends BaseCommand
$commandEvent = new CommandEvent(PluginEvents::COMMAND, $this->getName(), $input, $output); $commandEvent = new CommandEvent(PluginEvents::COMMAND, $this->getName(), $input, $output);
$composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent); $composer->getEventDispatcher()->dispatch($commandEvent->getName(), $commandEvent);
// Prepare repositories and set up a pool // Prepare repositories and set up a repo set
$platformOverrides = $composer->getConfig()->get('platform') ?: array(); $platformOverrides = $composer->getConfig()->get('platform') ?: array();
$repository = new CompositeRepository(array( $repository = new CompositeRepository(array(
new ArrayRepository(array($composer->getPackage())), new ArrayRepository(array($composer->getPackage())),
$composer->getRepositoryManager()->getLocalRepository(), $composer->getRepositoryManager()->getLocalRepository(),
new PlatformRepository(array(), $platformOverrides), new PlatformRepository(array(), $platformOverrides),
)); ));
$pool = new Pool(); $repositorySet = new RepositorySet();
$pool->addRepository($repository); $repositorySet->addRepository($repository);
// Parse package name and constraint // Parse package name and constraint
list($needle, $textConstraint) = array_pad( list($needle, $textConstraint) = array_pad(
@ -89,7 +89,7 @@ class BaseDependencyCommand extends BaseCommand
); );
// Find packages that are or provide the requested package first // Find packages that are or provide the requested package first
$packages = $pool->whatProvides(strtolower($needle)); $packages = $repositorySet->findPackages(strtolower($needle), null, false);
if (empty($packages)) { if (empty($packages)) {
throw new \InvalidArgumentException(sprintf('Could not find package "%s" in your project', $needle)); throw new \InvalidArgumentException(sprintf('Could not find package "%s" in your project', $needle));
} }

View File

@ -20,7 +20,6 @@ use Composer\Installer\InstallationManager;
use Composer\Installer\SuggestedPackagesReporter; use Composer\Installer\SuggestedPackagesReporter;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Package\BasePackage; use Composer\Package\BasePackage;
use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\Operation\InstallOperation; use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\Package\Version\VersionSelector; use Composer\Package\Version\VersionSelector;
use Composer\Package\AliasPackage; use Composer\Package\AliasPackage;
@ -28,6 +27,7 @@ use Composer\Repository\RepositoryFactory;
use Composer\Repository\CompositeRepository; use Composer\Repository\CompositeRepository;
use Composer\Repository\PlatformRepository; use Composer\Repository\PlatformRepository;
use Composer\Repository\InstalledFilesystemRepository; use Composer\Repository\InstalledFilesystemRepository;
use Composer\Repository\RepositorySet;
use Composer\Script\ScriptEvents; use Composer\Script\ScriptEvents;
use Composer\Util\Silencer; use Composer\Util\Silencer;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
@ -290,8 +290,8 @@ EOT
throw new \InvalidArgumentException('Invalid stability provided ('.$stability.'), must be one of: '.implode(', ', array_keys(BasePackage::$stabilities))); throw new \InvalidArgumentException('Invalid stability provided ('.$stability.'), must be one of: '.implode(', ', array_keys(BasePackage::$stabilities)));
} }
$pool = new Pool($stability); $repositorySet = new RepositorySet(array(), $stability);
$pool->addRepository($sourceRepo); $repositorySet->addRepository($sourceRepo);
$phpVersion = null; $phpVersion = null;
$prettyPhpVersion = null; $prettyPhpVersion = null;
@ -305,7 +305,7 @@ EOT
} }
// find the latest version if there are multiple // find the latest version if there are multiple
$versionSelector = new VersionSelector($pool); $versionSelector = new VersionSelector($repositorySet);
$package = $versionSelector->findBestCandidate($name, $packageVersion, $phpVersion, $stability); $package = $versionSelector->findBestCandidate($name, $packageVersion, $phpVersion, $stability);
if (!$package) { if (!$package) {

View File

@ -12,7 +12,6 @@
namespace Composer\Command; namespace Composer\Command;
use Composer\DependencyResolver\Pool;
use Composer\Factory; use Composer\Factory;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Package\BasePackage; use Composer\Package\BasePackage;
@ -21,6 +20,7 @@ use Composer\Package\Version\VersionSelector;
use Composer\Repository\CompositeRepository; use Composer\Repository\CompositeRepository;
use Composer\Repository\PlatformRepository; use Composer\Repository\PlatformRepository;
use Composer\Repository\RepositoryFactory; use Composer\Repository\RepositoryFactory;
use Composer\Repository\RepositorySet;
use Composer\Util\ProcessExecutor; use Composer\Util\ProcessExecutor;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
@ -40,8 +40,8 @@ class InitCommand extends BaseCommand
/** @var array */ /** @var array */
private $gitConfig; private $gitConfig;
/** @var Pool[] */ /** @var RepositorySet[] */
private $pools; private $repositorySets;
/** /**
* {@inheritdoc} * {@inheritdoc}
@ -637,16 +637,16 @@ EOT
return false !== filter_var($email, FILTER_VALIDATE_EMAIL); return false !== filter_var($email, FILTER_VALIDATE_EMAIL);
} }
private function getPool(InputInterface $input, $minimumStability = null) private function getRepositorySet(InputInterface $input, $minimumStability = null)
{ {
$key = $minimumStability ?: 'default'; $key = $minimumStability ?: 'default';
if (!isset($this->pools[$key])) { if (!isset($this->repositorySets[$key])) {
$this->pools[$key] = $pool = new Pool($minimumStability ?: $this->getMinimumStability($input)); $this->repositorySets[$key] = $repositorySet = new RepositorySet(array(), $minimumStability ?: $this->getMinimumStability($input));
$pool->addRepository($this->getRepos()); $repositorySet->addRepository($this->getRepos());
} }
return $this->pools[$key]; return $this->repositorySets[$key];
} }
private function getMinimumStability(InputInterface $input) private function getMinimumStability(InputInterface $input)
@ -681,8 +681,8 @@ EOT
*/ */
private function findBestVersionAndNameForPackage(InputInterface $input, $name, $phpVersion, $preferredStability = 'stable', $requiredVersion = null, $minimumStability = null) private function findBestVersionAndNameForPackage(InputInterface $input, $name, $phpVersion, $preferredStability = 'stable', $requiredVersion = null, $minimumStability = null)
{ {
// find the latest version allowed in this pool // find the latest version allowed in this repo set
$versionSelector = new VersionSelector($this->getPool($input, $minimumStability)); $versionSelector = new VersionSelector($this->getRepositorySet($input, $minimumStability));
$package = $versionSelector->findBestCandidate($name, $requiredVersion, $phpVersion, $preferredStability); $package = $versionSelector->findBestCandidate($name, $requiredVersion, $phpVersion, $preferredStability);
// retry without phpVersion if platform requirements are ignored in case nothing was found // retry without phpVersion if platform requirements are ignored in case nothing was found

View File

@ -14,7 +14,6 @@ namespace Composer\Command;
use Composer\Composer; use Composer\Composer;
use Composer\DependencyResolver\DefaultPolicy; use Composer\DependencyResolver\DefaultPolicy;
use Composer\DependencyResolver\Pool;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Package\BasePackage; use Composer\Package\BasePackage;
use Composer\Package\CompletePackageInterface; use Composer\Package\CompletePackageInterface;
@ -29,6 +28,7 @@ use Composer\Repository\CompositeRepository;
use Composer\Repository\PlatformRepository; use Composer\Repository\PlatformRepository;
use Composer\Repository\RepositoryFactory; use Composer\Repository\RepositoryFactory;
use Composer\Repository\RepositoryInterface; use Composer\Repository\RepositoryInterface;
use Composer\Repository\RepositorySet;
use Composer\Semver\Constraint\ConstraintInterface; use Composer\Semver\Constraint\ConstraintInterface;
use Composer\Semver\Semver; use Composer\Semver\Semver;
use Composer\Spdx\SpdxLicenses; use Composer\Spdx\SpdxLicenses;
@ -52,8 +52,8 @@ class ShowCommand extends BaseCommand
protected $versionParser; protected $versionParser;
protected $colors; protected $colors;
/** @var Pool */ /** @var RepositorySet */
private $pool; private $repositorySet;
protected function configure() protected function configure()
{ {
@ -523,19 +523,13 @@ EOT
$constraint = is_string($version) ? $this->versionParser->parseConstraints($version) : $version; $constraint = is_string($version) ? $this->versionParser->parseConstraints($version) : $version;
$policy = new DefaultPolicy(); $policy = new DefaultPolicy();
$pool = new Pool('dev'); $repositorySet = new RepositorySet(array(), 'dev');
$pool->addRepository($repos); $repositorySet->addRepository($repos);
$matchedPackage = null; $matchedPackage = null;
$versions = array(); $versions = array();
$matches = $pool->whatProvides($name, $constraint); $matches = $repositorySet->findPackages($name, $constraint);
foreach ($matches as $index => $package) { foreach ($matches as $index => $package) {
// skip providers/replacers
if ($package->getName() !== $name) {
unset($matches[$index]);
continue;
}
// select an exact match if it is in the installed repo and no specific version was required // select an exact match if it is in the installed repo and no specific version was required
if (null === $version && $installedRepo->hasPackage($package)) { if (null === $version && $installedRepo->hasPackage($package)) {
$matchedPackage = $package; $matchedPackage = $package;
@ -545,6 +539,8 @@ EOT
$matches[$index] = $package->getId(); $matches[$index] = $package->getId();
} }
$pool = $repositorySet->createPool();
// select preferred package according to policy rules // select preferred package according to policy rules
if (!$matchedPackage && $matches && $preferred = $policy->selectPreferredPackages($pool, array(), $matches)) { if (!$matchedPackage && $matches && $preferred = $policy->selectPreferredPackages($pool, array(), $matches)) {
$matchedPackage = $pool->literalToPackage($preferred[0]); $matchedPackage = $pool->literalToPackage($preferred[0]);
@ -961,9 +957,9 @@ EOT
*/ */
private function findLatestPackage(PackageInterface $package, Composer $composer, $phpVersion, $minorOnly = false) private function findLatestPackage(PackageInterface $package, Composer $composer, $phpVersion, $minorOnly = false)
{ {
// find the latest version allowed in this pool // find the latest version allowed in this repo set
$name = $package->getName(); $name = $package->getName();
$versionSelector = new VersionSelector($this->getPool($composer)); $versionSelector = new VersionSelector($this->getRepositorySet($composer));
$stability = $composer->getPackage()->getMinimumStability(); $stability = $composer->getPackage()->getMinimumStability();
$flags = $composer->getPackage()->getStabilityFlags(); $flags = $composer->getPackage()->getStabilityFlags();
if (isset($flags[$name])) { if (isset($flags[$name])) {
@ -987,13 +983,13 @@ EOT
return $versionSelector->findBestCandidate($name, $targetVersion, $phpVersion, $bestStability); return $versionSelector->findBestCandidate($name, $targetVersion, $phpVersion, $bestStability);
} }
private function getPool(Composer $composer) private function getRepositorySet(Composer $composer)
{ {
if (!$this->pool) { if (!$this->repositorySet) {
$this->pool = new Pool($composer->getPackage()->getMinimumStability(), $composer->getPackage()->getStabilityFlags()); $this->repositorySet = new RepositorySet(array(), $composer->getPackage()->getMinimumStability(), $composer->getPackage()->getStabilityFlags());
$this->pool->addRepository(new CompositeRepository($composer->getRepositoryManager()->getRepositories())); $this->repositorySet->addRepository(new CompositeRepository($composer->getRepositoryManager()->getRepositories()));
} }
return $this->pool; return $this->repositorySet;
} }
} }

View File

@ -57,11 +57,6 @@ class DefaultPolicy implements PolicyInterface
return $packages; return $packages;
} }
public function getPriority(Pool $pool, PackageInterface $package)
{
return $pool->getPriority($package->getRepository());
}
public function selectPreferredPackages(Pool $pool, array $installedMap, array $literals, $requiredPackage = null) public function selectPreferredPackages(Pool $pool, array $installedMap, array $literals, $requiredPackage = null)
{ {
$packages = $this->groupLiteralsByNamePreferInstalled($pool, $installedMap, $literals); $packages = $this->groupLiteralsByNamePreferInstalled($pool, $installedMap, $literals);
@ -168,7 +163,7 @@ class DefaultPolicy implements PolicyInterface
return 1; return 1;
} }
return ($this->getPriority($pool, $a) > $this->getPriority($pool, $b)) ? -1 : 1; return ($pool->getPriority($a->id) > $pool->getPriority($b->id)) ? -1 : 1;
} }
/** /**
@ -236,10 +231,10 @@ class DefaultPolicy implements PolicyInterface
} }
if (null === $priority) { if (null === $priority) {
$priority = $this->getPriority($pool, $package); $priority = $pool->getPriority($package->id);
} }
if ($this->getPriority($pool, $package) != $priority) { if ($pool->getPriority($package->id) != $priority) {
break; break;
} }

View File

@ -15,6 +15,7 @@ namespace Composer\DependencyResolver;
use Composer\Package\BasePackage; use Composer\Package\BasePackage;
use Composer\Package\AliasPackage; use Composer\Package\AliasPackage;
use Composer\Package\Version\VersionParser; use Composer\Package\Version\VersionParser;
use Composer\Repository\RepositorySet;
use Composer\Semver\Constraint\ConstraintInterface; use Composer\Semver\Constraint\ConstraintInterface;
use Composer\Semver\Constraint\Constraint; use Composer\Semver\Constraint\Constraint;
use Composer\Semver\Constraint\EmptyConstraint; use Composer\Semver\Constraint\EmptyConstraint;
@ -26,7 +27,7 @@ use Composer\Repository\PlatformRepository;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
/** /**
* A package pool contains repositories that provide packages. * A package pool contains all packages for dependency resolution
* *
* @author Nils Adermann <naderman@naderman.de> * @author Nils Adermann <naderman@naderman.de>
* @author Jordi Boggiano <j.boggiano@seld.be> * @author Jordi Boggiano <j.boggiano@seld.be>
@ -40,35 +41,20 @@ class Pool implements \Countable
const MATCH_REPLACE = 3; const MATCH_REPLACE = 3;
const MATCH_FILTERED = 4; const MATCH_FILTERED = 4;
protected $repositories = array();
protected $providerRepos = array(); protected $providerRepos = array();
protected $packages = array(); protected $packages = array();
protected $packageByName = array(); protected $packageByName = array();
protected $packageByExactName = array(); protected $packageByExactName = array();
protected $acceptableStabilities; protected $priorities = array();
protected $stabilityFlags;
protected $versionParser; protected $versionParser;
protected $providerCache = array(); protected $providerCache = array();
protected $filterRequires; protected $filterRequires;
protected $whitelist = null; protected $whitelist = null;
protected $id = 1;
public function __construct($minimumStability = 'stable', array $stabilityFlags = array(), array $filterRequires = array()) public function __construct(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->stabilityFlags = $stabilityFlags;
$this->filterRequires = $filterRequires; $this->filterRequires = $filterRequires;
foreach ($filterRequires as $name => $constraint) { $this->versionParser = new VersionParser;
if (preg_match(PlatformRepository::PLATFORM_PACKAGE_REGEX, $name)) {
unset($this->filterRequires[$name]);
}
}
} }
public function setWhitelist($whitelist) public function setWhitelist($whitelist)
@ -77,76 +63,24 @@ class Pool implements \Countable
$this->providerCache = array(); $this->providerCache = array();
} }
/** public function setPackages(array $packages, array $priorities = array())
* Adds a repository and its packages to this package pool
*
* @param RepositoryInterface $repo A package repository
* @param array $rootAliases
*/
public function addRepository(RepositoryInterface $repo, $rootAliases = array())
{ {
if ($repo instanceof CompositeRepository) { $this->priorities = $priorities;
$repos = $repo->getRepositories(); $this->packages = $packages;
} else {
$repos = array($repo);
}
foreach ($repos as $repo) { foreach ($this->packages as $package) {
$this->repositories[] = $repo; $names = $package->getNames();
$this->packageByExactName[$package->getName()][$package->id] = $package;
$exempt = $repo instanceof PlatformRepository || $repo instanceof InstalledRepositoryInterface; foreach ($names as $provided) {
$this->packageByName[$provided][] = $package;
if ($repo instanceof ComposerRepository && $repo->hasProviders()) {
$this->providerRepos[] = $repo;
$repo->setRootAliases($rootAliases);
$repo->resetPackageIds();
} else {
foreach ($repo->getPackages() as $package) {
$names = $package->getNames();
$stability = $package->getStability();
if ($exempt || $this->isPackageAcceptable($names, $stability)) {
$package->setId($this->id++);
$this->packages[] = $package;
$this->packageByExactName[$package->getName()][$package->id] = $package;
foreach ($names as $provided) {
$this->packageByName[$provided][] = $package;
}
// handle root package aliases
$name = $package->getName();
if (isset($rootAliases[$name][$package->getVersion()])) {
$alias = $rootAliases[$name][$package->getVersion()];
if ($package instanceof AliasPackage) {
$package = $package->getAliasOf();
}
$aliasPackage = new AliasPackage($package, $alias['alias_normalized'], $alias['alias']);
$aliasPackage->setRootPackageAlias(true);
$aliasPackage->setId($this->id++);
$package->getRepository()->addPackage($aliasPackage);
$this->packages[] = $aliasPackage;
$this->packageByExactName[$aliasPackage->getName()][$aliasPackage->id] = $aliasPackage;
foreach ($aliasPackage->getNames() as $name) {
$this->packageByName[$name][] = $aliasPackage;
}
}
}
}
} }
} }
} }
public function getPriority(RepositoryInterface $repo) public function getPriority($id)
{ {
$priority = array_search($repo, $this->repositories, true); return $this->priorities[$id - 1];
if (false === $priority) {
throw new \RuntimeException("Could not determine repository priority. The repository was not registered in the pool.");
}
return -$priority;
} }
/** /**
@ -200,25 +134,12 @@ class Pool implements \Countable
{ {
$candidates = array(); $candidates = array();
foreach ($this->providerRepos as $repo) {
foreach ($repo->whatProvides($this, $name, $bypassFilters) as $candidate) {
$candidates[] = $candidate;
if ($candidate->id < 1) {
$candidate->setId($this->id++);
$this->packages[$this->id - 2] = $candidate;
}
}
}
if ($mustMatchName) { if ($mustMatchName) {
$candidates = array_filter($candidates, function ($candidate) use ($name) {
return $candidate->getName() == $name;
});
if (isset($this->packageByExactName[$name])) { if (isset($this->packageByExactName[$name])) {
$candidates = array_merge($candidates, $this->packageByExactName[$name]); $candidates = $this->packageByExactName[$name];
} }
} elseif (isset($this->packageByName[$name])) { } elseif (isset($this->packageByName[$name])) {
$candidates = array_merge($candidates, $this->packageByName[$name]); $candidates = $this->packageByName[$name];
} }
$matches = $provideMatches = array(); $matches = $provideMatches = array();
@ -296,23 +217,6 @@ class Pool implements \Countable
return $prefix.' '.$package->getPrettyString(); return $prefix.' '.$package->getPrettyString();
} }
public function 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;
}
/** /**
* Checks if the package matches the given constraint directly or through * Checks if the package matches the given constraint directly or through
* provided or replaced packages * provided or replaced packages

View File

@ -0,0 +1,150 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\DependencyResolver;
use Composer\Package\AliasPackage;
use Composer\Package\BasePackage;
use Composer\Package\PackageInterface;
use Composer\Repository\AsyncRepositoryInterface;
use Composer\Repository\ComposerRepository;
use Composer\Repository\InstalledRepositoryInterface;
use Composer\Repository\LockArrayRepository;
use Composer\Repository\PlatformRepository;
/**
* @author Nils Adermann <naderman@naderman.de>
*/
class PoolBuilder
{
private $isPackageAcceptableCallable;
private $filterRequires;
private $rootAliases;
private $loadedNames = array();
private $id = 1;
private $packages = array();
private $priorities = array();
public function __construct($isPackageAcceptableCallable, array $filterRequires = array())
{
$this->isPackageAcceptableCallable = $isPackageAcceptableCallable;
$this->filterRequires = $filterRequires;
}
public function buildPool(array $repositories, array $rootAliases, Request $request)
{
$this->pool = new Pool($this->filterRequires);
$this->rootAliases = $rootAliases;
// TODO do we really want the request here? kind of want a root requirements thingy instead
$loadNames = array();
foreach ($request->getJobs() as $job) {
switch ($job['cmd']) {
case 'install':
$loadNames[$job['packageName']] = true;
break;
}
}
foreach ($repositories as $repository) {
if ($repository instanceof ComposerRepository && $repository->hasProviders()) {
$this->providerRepos[] = $repository;
$repository->setRootAliases($this->rootAliases);
$repository->resetPackageIds();
}
}
while (!empty($loadNames)) {
$loadIds = array();
foreach ($repositories as $key => $repository) {
if ($repository instanceof AsyncRepositoryInterface) {
$loadIds[$key] = $repository->requestPackages($loadNames);
}
}
foreach ($loadNames as $name => $void) {
$this->loadedNames[$name] = true;
}
$newLoadNames = array();
foreach ($repositories as $key => $repository) {
if ($repository instanceof PlatformRepository || $repository instanceof InstalledRepositoryInterface) {
continue;
}
if ($repository instanceof AsyncRepositoryInterface) {
// TODO ispackageacceptablecallable in here?
$packages = $repository->returnPackages($loadIds[$key]);
} else {
// TODO should we really pass the callable into here?
$packages = $repository->loadPackages($loadNames, $this->isPackageAcceptableCallable);
}
foreach ($packages as $package) {
if (call_user_func($this->isPackageAcceptableCallable, $package->getNames(), $package->getStability())) {
$newLoadNames += $this->loadPackage($package, $key);
}
}
}
$loadNames = $newLoadNames;
}
foreach ($repositories as $key => $repository) {
if ($repository instanceof PlatformRepository ||
$repository instanceof InstalledRepositoryInterface) {
foreach ($repository->getPackages() as $package) {
$this->loadPackage($package, $key);
}
}
}
$this->pool->setPackages($this->packages, $this->priorities);
return $this->pool;
}
private function loadPackage(PackageInterface $package, $repoIndex)
{
$package->setId($this->id++);
$this->packages[] = $package;
$this->priorities[$this->id - 2] = -$repoIndex;
// handle root package aliases
$name = $package->getName();
if (isset($this->rootAliases[$name][$package->getVersion()])) {
$alias = $this->rootAliases[$name][$package->getVersion()];
if ($package instanceof AliasPackage) {
$package = $package->getAliasOf();
}
$aliasPackage = new AliasPackage($package, $alias['alias_normalized'], $alias['alias']);
$aliasPackage->setRootPackageAlias(true);
$aliasPackage->setId($this->id++);
$package->getRepository()->addPackage($aliasPackage); // TODO do we need this?
$this->packages[] = $aliasPackage;
}
$loadNames = array();
foreach ($package->getRequires() as $link) {
$require = $link->getTarget();
if (!isset($this->loadedNames[$require])) {
$loadNames[$require] = true;
}
}
return $loadNames;
}
}

View File

@ -71,7 +71,7 @@ class Problem
* @param array $installedMap A map of all installed packages * @param array $installedMap A map of all installed packages
* @return string * @return string
*/ */
public function getPrettyString(array $installedMap = array()) public function getPrettyString(array $installedMap = array(), array $learnedPool = array())
{ {
$reasons = call_user_func_array('array_merge', array_reverse($this->reasons)); $reasons = call_user_func_array('array_merge', array_reverse($this->reasons));
@ -168,7 +168,7 @@ class Problem
$messages[] = $this->jobToText($job); $messages[] = $this->jobToText($job);
} elseif ($rule) { } elseif ($rule) {
if ($rule instanceof Rule) { if ($rule instanceof Rule) {
$messages[] = $rule->getPrettyString($this->pool, $installedMap); $messages[] = $rule->getPrettyString($this->pool, $installedMap, $learnedPool);
} }
} }
} }

View File

@ -126,7 +126,7 @@ abstract class Rule
abstract public function isAssertion(); abstract public function isAssertion();
public function getPrettyString(Pool $pool, array $installedMap = array()) public function getPrettyString(Pool $pool, array $installedMap = array(), array $learnedPool = array())
{ {
$literals = $this->getLiterals(); $literals = $this->getLiterals();
@ -230,7 +230,18 @@ abstract class Rule
case self::RULE_PACKAGE_IMPLICIT_OBSOLETES: case self::RULE_PACKAGE_IMPLICIT_OBSOLETES:
return $ruleText; return $ruleText;
case self::RULE_LEARNED: case self::RULE_LEARNED:
return 'Conclusion: '.$ruleText; // TODO not sure this is a good idea, most of these rules should be listed in the problem anyway
$learnedString = '(learned rule, ';
if (isset($learnedPool[$this->reasonData])) {
foreach ($learnedPool[$this->reasonData] as $learnedRule) {
$learnedString .= $learnedRule->getPrettyString($pool, $installedMap, $learnedPool);
}
} else {
$learnedString .= 'reasoning unavailable';
}
$learnedString .= ')';
return 'Conclusion: '.$ruleText.' '.$learnedString;
case self::RULE_PACKAGE_ALIAS: case self::RULE_PACKAGE_ALIAS:
return $ruleText; return $ruleText;
default: default:

View File

@ -15,6 +15,7 @@ namespace Composer\DependencyResolver;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Repository\RepositoryInterface; use Composer\Repository\RepositoryInterface;
use Composer\Repository\PlatformRepository; use Composer\Repository\PlatformRepository;
use Composer\Repository\RepositorySet;
/** /**
* @author Nils Adermann <naderman@naderman.de> * @author Nils Adermann <naderman@naderman.de>
@ -27,7 +28,7 @@ class Solver
/** @var PolicyInterface */ /** @var PolicyInterface */
protected $policy; protected $policy;
/** @var Pool */ /** @var Pool */
protected $pool; protected $pool = null;
/** @var RepositoryInterface */ /** @var RepositoryInterface */
protected $installed; protected $installed;
/** @var RuleSet */ /** @var RuleSet */
@ -72,7 +73,6 @@ class Solver
$this->policy = $policy; $this->policy = $policy;
$this->pool = $pool; $this->pool = $pool;
$this->installed = $installed; $this->installed = $installed;
$this->ruleSetGenerator = new RuleSetGenerator($policy, $pool);
} }
/** /**
@ -83,6 +83,11 @@ class Solver
return count($this->rules); return count($this->rules);
} }
public function getPool()
{
return $this->pool;
}
// aka solver_makeruledecisions // aka solver_makeruledecisions
private function makeAssertionRuleDecisions() private function makeAssertionRuleDecisions()
@ -211,6 +216,8 @@ class Solver
$this->jobs = $request->getJobs(); $this->jobs = $request->getJobs();
$this->setupInstalledMap(); $this->setupInstalledMap();
$this->ruleSetGenerator = new RuleSetGenerator($this->policy, $this->pool);
$this->rules = $this->ruleSetGenerator->getRulesFor($this->jobs, $this->installedMap, $ignorePlatformReqs); $this->rules = $this->ruleSetGenerator->getRulesFor($this->jobs, $this->installedMap, $ignorePlatformReqs);
$this->checkForRootRequireProblems($ignorePlatformReqs); $this->checkForRootRequireProblems($ignorePlatformReqs);
$this->decisions = new Decisions($this->pool); $this->decisions = new Decisions($this->pool);
@ -237,7 +244,7 @@ class Solver
} }
if ($this->problems) { if ($this->problems) {
throw new SolverProblemsException($this->problems, $this->installedMap); throw new SolverProblemsException($this->problems, $this->installedMap, $this->learnedPool);
} }
$transaction = new Transaction($this->policy, $this->pool, $this->installedMap, $this->decisions); $transaction = new Transaction($this->policy, $this->pool, $this->installedMap, $this->decisions);

View File

@ -21,11 +21,13 @@ class SolverProblemsException extends \RuntimeException
{ {
protected $problems; protected $problems;
protected $installedMap; protected $installedMap;
protected $learnedPool;
public function __construct(array $problems, array $installedMap) public function __construct(array $problems, array $installedMap, array $learnedPool)
{ {
$this->problems = $problems; $this->problems = $problems;
$this->installedMap = $installedMap; $this->installedMap = $installedMap;
$this->learnedPool = $learnedPool;
parent::__construct($this->createMessage(), 2); parent::__construct($this->createMessage(), 2);
} }
@ -35,7 +37,7 @@ class SolverProblemsException extends \RuntimeException
$text = "\n"; $text = "\n";
$hasExtensionProblems = false; $hasExtensionProblems = false;
foreach ($this->problems as $i => $problem) { foreach ($this->problems as $i => $problem) {
$text .= " Problem ".($i + 1).$problem->getPrettyString($this->installedMap)."\n"; $text .= " Problem ".($i + 1).$problem->getPrettyString($this->installedMap, $this->learnedPool)."\n";
if (!$hasExtensionProblems && $this->hasExtensionProblems($problem->getReasons())) { if (!$hasExtensionProblems && $this->hasExtensionProblems($problem->getReasons())) {
$hasExtensionProblems = true; $hasExtensionProblems = true;

View File

@ -13,13 +13,13 @@
namespace Composer\EventDispatcher; namespace Composer\EventDispatcher;
use Composer\DependencyResolver\PolicyInterface; use Composer\DependencyResolver\PolicyInterface;
use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\Request; use Composer\DependencyResolver\Request;
use Composer\Installer\InstallerEvent; use Composer\Installer\InstallerEvent;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Composer; use Composer\Composer;
use Composer\DependencyResolver\Operation\OperationInterface; use Composer\DependencyResolver\Operation\OperationInterface;
use Composer\Repository\CompositeRepository; use Composer\Repository\CompositeRepository;
use Composer\Repository\RepositorySet;
use Composer\Script; use Composer\Script;
use Composer\Installer\PackageEvent; use Composer\Installer\PackageEvent;
use Composer\Installer\BinaryInstaller; use Composer\Installer\BinaryInstaller;
@ -102,7 +102,7 @@ class EventDispatcher
* @param string $eventName The constant in PackageEvents * @param string $eventName The constant in PackageEvents
* @param bool $devMode Whether or not we are in dev mode * @param bool $devMode Whether or not we are in dev mode
* @param PolicyInterface $policy The policy * @param PolicyInterface $policy The policy
* @param Pool $pool The pool * @param RepositorySet $repositorySet The repository set
* @param CompositeRepository $installedRepo The installed repository * @param CompositeRepository $installedRepo The installed repository
* @param Request $request The request * @param Request $request The request
* @param array $operations The list of operations * @param array $operations The list of operations
@ -111,9 +111,9 @@ class EventDispatcher
* @return int return code of the executed script if any, for php scripts a false return * @return int return code of the executed script if any, for php scripts a false return
* value is changed to 1, anything else to 0 * value is changed to 1, anything else to 0
*/ */
public function dispatchPackageEvent($eventName, $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations, OperationInterface $operation) public function dispatchPackageEvent($eventName, $devMode, PolicyInterface $policy, RepositorySet $repositorySet, CompositeRepository $installedRepo, Request $request, array $operations, OperationInterface $operation)
{ {
return $this->doDispatch(new PackageEvent($eventName, $this->composer, $this->io, $devMode, $policy, $pool, $installedRepo, $request, $operations, $operation)); return $this->doDispatch(new PackageEvent($eventName, $this->composer, $this->io, $devMode, $policy, $repositorySet, $installedRepo, $request, $operations, $operation));
} }
/** /**
@ -122,7 +122,7 @@ class EventDispatcher
* @param string $eventName The constant in InstallerEvents * @param string $eventName The constant in InstallerEvents
* @param bool $devMode Whether or not we are in dev mode * @param bool $devMode Whether or not we are in dev mode
* @param PolicyInterface $policy The policy * @param PolicyInterface $policy The policy
* @param Pool $pool The pool * @param RepositorySet $repositorySet The repository set
* @param CompositeRepository $installedRepo The installed repository * @param CompositeRepository $installedRepo The installed repository
* @param Request $request The request * @param Request $request The request
* @param array $operations The list of operations * @param array $operations The list of operations
@ -130,9 +130,9 @@ class EventDispatcher
* @return int return code of the executed script if any, for php scripts a false return * @return int return code of the executed script if any, for php scripts a false return
* value is changed to 1, anything else to 0 * value is changed to 1, anything else to 0
*/ */
public function dispatchInstallerEvent($eventName, $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations = array()) public function dispatchInstallerEvent($eventName, $devMode, PolicyInterface $policy, RepositorySet $repositorySet, CompositeRepository $installedRepo, Request $request, array $operations = array())
{ {
return $this->doDispatch(new InstallerEvent($eventName, $this->composer, $this->io, $devMode, $policy, $pool, $installedRepo, $request, $operations)); return $this->doDispatch(new InstallerEvent($eventName, $this->composer, $this->io, $devMode, $policy, $repositorySet, $installedRepo, $request, $operations));
} }
/** /**
@ -340,7 +340,7 @@ class EventDispatcher
$event->getIO(), $event->getIO(),
$event->isDevMode(), $event->isDevMode(),
$event->getPolicy(), $event->getPolicy(),
$event->getPool(), $event->getRepositorySet(),
$event->getInstalledRepo(), $event->getInstalledRepo(),
$event->getRequest(), $event->getRequest(),
$event->getOperations(), $event->getOperations(),

View File

@ -37,6 +37,7 @@ use Composer\Package\CompletePackage;
use Composer\Package\Link; use Composer\Package\Link;
use Composer\Package\Loader\ArrayLoader; use Composer\Package\Loader\ArrayLoader;
use Composer\Package\Dumper\ArrayDumper; use Composer\Package\Dumper\ArrayDumper;
use Composer\Repository\RepositorySet;
use Composer\Semver\Constraint\Constraint; use Composer\Semver\Constraint\Constraint;
use Composer\Package\Locker; use Composer\Package\Locker;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
@ -126,7 +127,7 @@ class Installer
* @var array|null * @var array|null
*/ */
protected $updateWhitelist = null; protected $updateWhitelist = null;
protected $whitelistDependencies = false; // TODO 2.0 rename to whitelistTransitiveDependencies protected $whitelistTransitiveDependencies = false;
protected $whitelistAllDependencies = false; protected $whitelistAllDependencies = false;
/** /**
@ -368,21 +369,21 @@ class Installer
$this->io->writeError('<info>Loading composer repositories with package information</info>'); $this->io->writeError('<info>Loading composer repositories with package information</info>');
// creating repository pool // creating repository set
$policy = $this->createPolicy(); $policy = $this->createPolicy();
$pool = $this->createPool($this->update ? null : $lockedRepository); $repositorySet = $this->createRepositorySet($aliases, $this->update ? null : $lockedRepository);
$pool->addRepository($installedRepo, $aliases); $repositorySet->addRepository($installedRepo);
if ($this->update) { if ($this->update) {
$repositories = $this->repositoryManager->getRepositories(); $repositories = $this->repositoryManager->getRepositories();
foreach ($repositories as $repository) { foreach ($repositories as $repository) {
$pool->addRepository($repository, $aliases); $repositorySet->addRepository($repository);
} }
} }
// Add the locked repository after the others in case we are doing a // Add the locked repository after the others in case we are doing a
// partial update so missing packages can be found there still. // partial update so missing packages can be found there still.
// For installs from lock it's the only one added so it is first // For installs from lock it's the only one added so it is first
if ($lockedRepository) { if ($lockedRepository) {
$pool->addRepository($lockedRepository, $aliases); $repositorySet->addRepository($lockedRepository);
} }
// creating requirements request // creating requirements request
@ -393,7 +394,7 @@ class Installer
$removedUnstablePackages = array(); $removedUnstablePackages = array();
foreach ($localRepo->getPackages() as $package) { foreach ($localRepo->getPackages() as $package) {
if ( if (
!$pool->isPackageAcceptable($package->getNames(), $package->getStability()) !$repositorySet->isPackageAcceptable($package->getNames(), $package->getStability())
&& $this->installationManager->isPackageInstalled($localRepo, $package) && $this->installationManager->isPackageInstalled($localRepo, $package)
) { ) {
$removedUnstablePackages[$package->getName()] = true; $removedUnstablePackages[$package->getName()] = true;
@ -464,11 +465,14 @@ class Installer
} }
} }
$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $installedRepo, $request);
$pool = $repositorySet->createPool($request);
// force dev packages to have the latest links if we update or install from a (potentially new) lock // force dev packages to have the latest links if we update or install from a (potentially new) lock
$this->processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, 'force-links'); $this->processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, 'force-links');
// solve dependencies // solve dependencies
$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, $this->devMode, $policy, $pool, $installedRepo, $request);
$solver = new Solver($policy, $pool, $installedRepo, $this->io); $solver = new Solver($policy, $pool, $installedRepo, $this->io);
try { try {
$operations = $solver->solve($request, $this->ignorePlatformReqs); $operations = $solver->solve($request, $this->ignorePlatformReqs);
@ -485,9 +489,8 @@ class Installer
// force dev packages to be updated if we update or install from a (potentially new) lock // force dev packages to be updated if we update or install from a (potentially new) lock
$operations = $this->processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, 'force-updates', $operations); $operations = $this->processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, 'force-updates', $operations);
$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $policy, $pool, $installedRepo, $request, $operations); $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, $this->devMode, $policy, $repositorySet, $installedRepo, $request, $operations);
$this->io->writeError("Analyzed ".count($pool)." packages to resolve dependencies", true, IOInterface::VERBOSE);
$this->io->writeError("Analyzed ".$solver->getRuleSetSize()." rules to resolve dependencies", true, IOInterface::VERBOSE); $this->io->writeError("Analyzed ".$solver->getRuleSetSize()." rules to resolve dependencies", true, IOInterface::VERBOSE);
// execute operations // execute operations
@ -581,7 +584,7 @@ class Installer
$event = 'Composer\Installer\PackageEvents::PRE_PACKAGE_'.strtoupper($jobType); $event = 'Composer\Installer\PackageEvents::PRE_PACKAGE_'.strtoupper($jobType);
if (defined($event) && $this->runScripts) { if (defined($event) && $this->runScripts) {
$this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation); $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $repositorySet, $installedRepo, $request, $operations, $operation);
} }
// output non-alias ops when not executing operations (i.e. dry run), output alias ops in debug verbosity // output non-alias ops when not executing operations (i.e. dry run), output alias ops in debug verbosity
@ -612,7 +615,7 @@ class Installer
$event = 'Composer\Installer\PackageEvents::POST_PACKAGE_'.strtoupper($jobType); $event = 'Composer\Installer\PackageEvents::POST_PACKAGE_'.strtoupper($jobType);
if (defined($event) && $this->runScripts) { if (defined($event) && $this->runScripts) {
$this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $pool, $installedRepo, $request, $operations, $operation); $this->eventDispatcher->dispatchPackageEvent(constant($event), $this->devMode, $policy, $repositorySet, $installedRepo, $request, $operations, $operation);
} }
if ($this->executeOperations || $this->writeLock) { if ($this->executeOperations || $this->writeLock) {
@ -685,9 +688,9 @@ class Installer
unset($tempLocalRepo, $loader, $dumper); unset($tempLocalRepo, $loader, $dumper);
$policy = $this->createPolicy(); $policy = $this->createPolicy();
$pool = $this->createPool(); $repositorySet = $this->createRepositorySet($aliases);
$installedRepo = $this->createInstalledRepo($localRepo, $platformRepo); $installedRepo = $this->createInstalledRepo($localRepo, $platformRepo);
$pool->addRepository($installedRepo, $aliases); $repositorySet->addRepository($installedRepo);
// creating requirements request without dev requirements // creating requirements request without dev requirements
$request = $this->createRequest($this->package, $platformRepo); $request = $this->createRequest($this->package, $platformRepo);
@ -697,10 +700,10 @@ class Installer
} }
// solve deps to see which get removed // solve deps to see which get removed
$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request); $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, false, $policy, $repositorySet, $installedRepo, $request);
$solver = new Solver($policy, $pool, $installedRepo, $this->io); $solver = new Solver($policy, $repositorySet->createPool($request), $installedRepo, $this->io);
$ops = $solver->solve($request, $this->ignorePlatformReqs); $ops = $solver->solve($request, $this->ignorePlatformReqs);
$this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, false, $policy, $pool, $installedRepo, $request, $ops); $this->eventDispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, false, $policy, $repositorySet, $installedRepo, $request, $ops);
$devPackages = array(); $devPackages = array();
foreach ($ops as $op) { foreach ($ops as $op) {
@ -845,10 +848,11 @@ class Installer
} }
/** /**
* @param RepositoryInterface|null $lockedRepository * @param array $rootAliases
* @return Pool * @param RepositoryInterface|null $lockedRepository
* @return RepositorySet
*/ */
private function createPool(RepositoryInterface $lockedRepository = null) private function createRepositorySet(array $rootAliases = array(), $lockedRepository = null)
{ {
if ($this->update) { if ($this->update) {
$minimumStability = $this->package->getMinimumStability(); $minimumStability = $this->package->getMinimumStability();
@ -880,7 +884,7 @@ class Installer
} }
} }
return new Pool($minimumStability, $stabilityFlags, $rootConstraints); return new RepositorySet($rootAliases, $minimumStability, $stabilityFlags, $rootConstraints);
} }
/** /**
@ -955,7 +959,7 @@ class Installer
* @param array|null $operations * @param array|null $operations
* @return array * @return array
*/ */
private function processDevPackages($localRepo, $pool, $policy, $repositories, $installedRepo, $lockedRepository, $task, array $operations = null) private function processDevPackages($localRepo, Pool $pool, $policy, $repositories, $installedRepo, $lockedRepository, $task, array $operations = null)
{ {
if ($task === 'force-updates' && null === $operations) { if ($task === 'force-updates' && null === $operations) {
throw new \InvalidArgumentException('Missing operations argument'); throw new \InvalidArgumentException('Missing operations argument');
@ -1010,7 +1014,7 @@ class Installer
} }
// find similar packages (name/version) in all repositories // find similar packages (name/version) in all repositories
$matches = $pool->whatProvides($package->getName(), new Constraint('=', $package->getVersion())); $matches = $pool->whatProvides($package->getName(), new Constraint('=', $package->getVersion()), true);
foreach ($matches as $index => $match) { foreach ($matches as $index => $match) {
// skip local packages // skip local packages
if (!in_array($match->getRepository(), $repositories, true)) { if (!in_array($match->getRepository(), $repositories, true)) {
@ -1018,12 +1022,6 @@ class Installer
continue; continue;
} }
// skip providers/replacers
if ($match->getName() !== $package->getName()) {
unset($matches[$index]);
continue;
}
$matches[$index] = $match->getId(); $matches[$index] = $match->getId();
} }
@ -1130,12 +1128,12 @@ class Installer
} }
/** /**
* @param Pool $pool * @param Pool $pool
* @param PolicyInterface $policy * @param PolicyInterface $policy
* @param WritableRepositoryInterface $localRepo * @param WritableRepositoryInterface $localRepo
* @param array $repositories * @param array $repositories
*/ */
private function processPackageUrls($pool, $policy, $localRepo, $repositories) private function processPackageUrls(Pool $pool, $policy, $localRepo, $repositories)
{ {
if (!$this->update) { if (!$this->update) {
return; return;
@ -1144,8 +1142,8 @@ class Installer
$rootRefs = $this->package->getReferences(); $rootRefs = $this->package->getReferences();
foreach ($localRepo->getCanonicalPackages() as $package) { foreach ($localRepo->getCanonicalPackages() as $package) {
// find similar packages (name/version) in all repositories // find similar packages (name/version) in pool
$matches = $pool->whatProvides($package->getName(), new Constraint('=', $package->getVersion())); $matches = $pool->whatProvides($package->getName(), new Constraint('=', $package->getVersion()), true);
foreach ($matches as $index => $match) { foreach ($matches as $index => $match) {
// skip local packages // skip local packages
if (!in_array($match->getRepository(), $repositories, true)) { if (!in_array($match->getRepository(), $repositories, true)) {
@ -1153,12 +1151,6 @@ class Installer
continue; continue;
} }
// skip providers/replacers
if ($match->getName() !== $package->getName()) {
unset($matches[$index]);
continue;
}
$matches[$index] = $match->getId(); $matches[$index] = $match->getId();
} }
@ -1325,8 +1317,8 @@ class Installer
} }
} }
$pool = new Pool('dev'); $repositorySet = new RepositorySet(array(), 'dev');
$pool->addRepository($localOrLockRepo); $repositorySet->addRepository($localOrLockRepo);
$seen = array(); $seen = array();
@ -1335,7 +1327,7 @@ class Installer
foreach ($this->updateWhitelist as $packageName => $void) { foreach ($this->updateWhitelist as $packageName => $void) {
$packageQueue = new \SplQueue; $packageQueue = new \SplQueue;
$depPackages = $pool->whatProvides($packageName); $depPackages = $repositorySet->findPackages($packageName, null, false);
$nameMatchesRequiredPackage = in_array($packageName, $requiredPackageNames, true); $nameMatchesRequiredPackage = in_array($packageName, $requiredPackageNames, true);
@ -1360,21 +1352,21 @@ class Installer
while (!$packageQueue->isEmpty()) { while (!$packageQueue->isEmpty()) {
$package = $packageQueue->dequeue(); $package = $packageQueue->dequeue();
if (isset($seen[$package->getId()])) { if (isset($seen[spl_object_hash($package)])) {
continue; continue;
} }
$seen[$package->getId()] = true; $seen[spl_object_hash($package)] = true;
$this->updateWhitelist[$package->getName()] = true; $this->updateWhitelist[$package->getName()] = true;
if (!$this->whitelistDependencies && !$this->whitelistAllDependencies) { if (!$this->whitelistTransitiveDependencies && !$this->whitelistAllDependencies) {
continue; continue;
} }
$requires = $package->getRequires(); $requires = $package->getRequires();
foreach ($requires as $require) { foreach ($requires as $require) {
$requirePackages = $pool->whatProvides($require->getTarget()); $requirePackages = $repositorySet->findPackages($require->getTarget(), null, false);
foreach ($requirePackages as $requirePackage) { foreach ($requirePackages as $requirePackage) {
if (isset($this->updateWhitelist[$requirePackage->getName()])) { if (isset($this->updateWhitelist[$requirePackage->getName()])) {
@ -1667,14 +1659,6 @@ class Installer
return $this; return $this;
} }
/**
* @deprecated use setWhitelistTransitiveDependencies instead
*/
public function setWhitelistDependencies($updateDependencies = true)
{
return $this->setWhitelistTransitiveDependencies($updateDependencies);
}
/** /**
* Should dependencies of whitelisted packages (but not direct dependencies) be updated? * Should dependencies of whitelisted packages (but not direct dependencies) be updated?
* *
@ -1686,7 +1670,7 @@ class Installer
*/ */
public function setWhitelistTransitiveDependencies($updateTransitiveDependencies = true) public function setWhitelistTransitiveDependencies($updateTransitiveDependencies = true)
{ {
$this->whitelistDependencies = (bool) $updateTransitiveDependencies; $this->whitelistTransitiveDependencies = (bool) $updateTransitiveDependencies;
return $this; return $this;
} }

View File

@ -15,11 +15,11 @@ namespace Composer\Installer;
use Composer\Composer; use Composer\Composer;
use Composer\DependencyResolver\PolicyInterface; use Composer\DependencyResolver\PolicyInterface;
use Composer\DependencyResolver\Operation\OperationInterface; use Composer\DependencyResolver\Operation\OperationInterface;
use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\Request; use Composer\DependencyResolver\Request;
use Composer\EventDispatcher\Event; use Composer\EventDispatcher\Event;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Repository\CompositeRepository; use Composer\Repository\CompositeRepository;
use Composer\Repository\RepositorySet;
/** /**
* An event for all installer. * An event for all installer.
@ -49,9 +49,9 @@ class InstallerEvent extends Event
private $policy; private $policy;
/** /**
* @var Pool * @var RepositorySet
*/ */
private $pool; private $repositorySet;
/** /**
* @var CompositeRepository * @var CompositeRepository
@ -76,12 +76,12 @@ class InstallerEvent extends Event
* @param IOInterface $io * @param IOInterface $io
* @param bool $devMode * @param bool $devMode
* @param PolicyInterface $policy * @param PolicyInterface $policy
* @param Pool $pool * @param RepositorySet $repositorySet
* @param CompositeRepository $installedRepo * @param CompositeRepository $installedRepo
* @param Request $request * @param Request $request
* @param OperationInterface[] $operations * @param OperationInterface[] $operations
*/ */
public function __construct($eventName, Composer $composer, IOInterface $io, $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations = array()) public function __construct($eventName, Composer $composer, IOInterface $io, $devMode, PolicyInterface $policy, RepositorySet $repositorySet, CompositeRepository $installedRepo, Request $request, array $operations = array())
{ {
parent::__construct($eventName); parent::__construct($eventName);
@ -89,7 +89,7 @@ class InstallerEvent extends Event
$this->io = $io; $this->io = $io;
$this->devMode = $devMode; $this->devMode = $devMode;
$this->policy = $policy; $this->policy = $policy;
$this->pool = $pool; $this->repositorySet = $repositorySet;
$this->installedRepo = $installedRepo; $this->installedRepo = $installedRepo;
$this->request = $request; $this->request = $request;
$this->operations = $operations; $this->operations = $operations;
@ -128,11 +128,11 @@ class InstallerEvent extends Event
} }
/** /**
* @return Pool * @return RepositorySet
*/ */
public function getPool() public function getRepositorySet()
{ {
return $this->pool; return $this->repositorySet;
} }
/** /**

View File

@ -16,9 +16,9 @@ use Composer\Composer;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\DependencyResolver\Operation\OperationInterface; use Composer\DependencyResolver\Operation\OperationInterface;
use Composer\DependencyResolver\PolicyInterface; use Composer\DependencyResolver\PolicyInterface;
use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\Request; use Composer\DependencyResolver\Request;
use Composer\Repository\CompositeRepository; use Composer\Repository\CompositeRepository;
use Composer\Repository\RepositorySet;
/** /**
* The Package Event. * The Package Event.
@ -40,15 +40,15 @@ class PackageEvent extends InstallerEvent
* @param IOInterface $io * @param IOInterface $io
* @param bool $devMode * @param bool $devMode
* @param PolicyInterface $policy * @param PolicyInterface $policy
* @param Pool $pool * @param RepositorySet $repositorySet
* @param CompositeRepository $installedRepo * @param CompositeRepository $installedRepo
* @param Request $request * @param Request $request
* @param OperationInterface[] $operations * @param OperationInterface[] $operations
* @param OperationInterface $operation * @param OperationInterface $operation
*/ */
public function __construct($eventName, Composer $composer, IOInterface $io, $devMode, PolicyInterface $policy, Pool $pool, CompositeRepository $installedRepo, Request $request, array $operations, OperationInterface $operation) public function __construct($eventName, Composer $composer, IOInterface $io, $devMode, PolicyInterface $policy, RepositorySet $repositorySet, CompositeRepository $installedRepo, Request $request, array $operations, OperationInterface $operation)
{ {
parent::__construct($eventName, $composer, $io, $devMode, $policy, $pool, $installedRepo, $request, $operations); parent::__construct($eventName, $composer, $io, $devMode, $policy, $repositorySet, $installedRepo, $request, $operations);
$this->operation = $operation; $this->operation = $operation;
} }

View File

@ -14,9 +14,9 @@ namespace Composer\Package;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Installer\InstallationManager; use Composer\Installer\InstallationManager;
use Composer\Repository\LockArrayRepository;
use Composer\Repository\RepositoryManager; use Composer\Repository\RepositoryManager;
use Composer\Util\ProcessExecutor; use Composer\Util\ProcessExecutor;
use Composer\Repository\ArrayRepository;
use Composer\Package\Dumper\ArrayDumper; use Composer\Package\Dumper\ArrayDumper;
use Composer\Package\Loader\ArrayLoader; use Composer\Package\Loader\ArrayLoader;
use Composer\Util\Git as GitUtil; use Composer\Util\Git as GitUtil;
@ -150,7 +150,7 @@ class Locker
public function getLockedRepository($withDevReqs = false) public function getLockedRepository($withDevReqs = false)
{ {
$lockData = $this->getLockData(); $lockData = $this->getLockData();
$packages = new ArrayRepository(); $packages = new LockArrayRepository();
$lockedPackages = $lockData['packages']; $lockedPackages = $lockData['packages'];
if ($withDevReqs) { if ($withDevReqs) {

View File

@ -17,6 +17,7 @@ use Composer\Package\BasePackage;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Package\Loader\ArrayLoader; use Composer\Package\Loader\ArrayLoader;
use Composer\Package\Dumper\ArrayDumper; use Composer\Package\Dumper\ArrayDumper;
use Composer\Repository\RepositorySet;
use Composer\Semver\Constraint\Constraint; use Composer\Semver\Constraint\Constraint;
/** /**
@ -27,13 +28,13 @@ use Composer\Semver\Constraint\Constraint;
*/ */
class VersionSelector class VersionSelector
{ {
private $pool; private $repositorySet;
private $parser; private $parser;
public function __construct(Pool $pool) public function __construct(RepositorySet $repositorySet)
{ {
$this->pool = $pool; $this->repositorySet = $repositorySet;
} }
/** /**
@ -49,7 +50,7 @@ class VersionSelector
public function findBestCandidate($packageName, $targetPackageVersion = null, $targetPhpVersion = null, $preferredStability = 'stable') public function findBestCandidate($packageName, $targetPackageVersion = null, $targetPhpVersion = null, $preferredStability = 'stable')
{ {
$constraint = $targetPackageVersion ? $this->getParser()->parseConstraints($targetPackageVersion) : null; $constraint = $targetPackageVersion ? $this->getParser()->parseConstraints($targetPackageVersion) : null;
$candidates = $this->pool->whatProvides(strtolower($packageName), $constraint, true); $candidates = $this->repositorySet->findPackages(strtolower($packageName), $constraint);
if ($targetPhpVersion) { if ($targetPhpVersion) {
$phpConstraint = new Constraint('==', $this->getParser()->normalize($targetPhpVersion)); $phpConstraint = new Constraint('==', $this->getParser()->normalize($targetPhpVersion));

View File

@ -27,7 +27,7 @@ interface PluginInterface
* *
* @var string * @var string
*/ */
const PLUGIN_API_VERSION = '1.1.0'; const PLUGIN_API_VERSION = '2.0.0';
/** /**
* Apply plugin modifications to Composer * Apply plugin modifications to Composer

View File

@ -21,8 +21,8 @@ use Composer\Repository\RepositoryInterface;
use Composer\Package\AliasPackage; use Composer\Package\AliasPackage;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Package\Link; use Composer\Package\Link;
use Composer\Repository\RepositorySet;
use Composer\Semver\Constraint\Constraint; use Composer\Semver\Constraint\Constraint;
use Composer\DependencyResolver\Pool;
use Composer\Plugin\Capability\Capability; use Composer\Plugin\Capability\Capability;
/** /**
@ -157,14 +157,14 @@ class PluginManager
$localRepo = $this->composer->getRepositoryManager()->getLocalRepository(); $localRepo = $this->composer->getRepositoryManager()->getLocalRepository();
$globalRepo = $this->globalComposer ? $this->globalComposer->getRepositoryManager()->getLocalRepository() : null; $globalRepo = $this->globalComposer ? $this->globalComposer->getRepositoryManager()->getLocalRepository() : null;
$pool = new Pool('dev'); $repositorySet = new RepositorySet(array(), 'dev');
$pool->addRepository($localRepo); $repositorySet->addRepository($localRepo);
if ($globalRepo) { if ($globalRepo) {
$pool->addRepository($globalRepo); $repositorySet->addRepository($globalRepo);
} }
$autoloadPackages = array($package->getName() => $package); $autoloadPackages = array($package->getName() => $package);
$autoloadPackages = $this->collectDependencies($pool, $autoloadPackages, $package); $autoloadPackages = $this->collectDependencies($repositorySet, $autoloadPackages, $package);
$generator = $this->composer->getAutoloadGenerator(); $generator = $this->composer->getAutoloadGenerator();
$autoloads = array(); $autoloads = array();
@ -269,13 +269,13 @@ class PluginManager
/** /**
* Recursively generates a map of package names to packages for all deps * Recursively generates a map of package names to packages for all deps
* *
* @param Pool $pool Package pool of installed packages * @param RepositorySet $repositorySet Repository set of installed packages
* @param array $collected Current state of the map for recursion * @param array $collected Current state of the map for recursion
* @param PackageInterface $package The package to analyze * @param PackageInterface $package The package to analyze
* *
* @return array Map of package names to packages * @return array Map of package names to packages
*/ */
private function collectDependencies(Pool $pool, array $collected, PackageInterface $package) private function collectDependencies(RepositorySet $repositorySet, array $collected, PackageInterface $package)
{ {
$requires = array_merge( $requires = array_merge(
$package->getRequires(), $package->getRequires(),
@ -283,10 +283,10 @@ class PluginManager
); );
foreach ($requires as $requireLink) { foreach ($requires as $requireLink) {
$requiredPackage = $this->lookupInstalledPackage($pool, $requireLink); $requiredPackage = $this->lookupInstalledPackage($repositorySet, $requireLink);
if ($requiredPackage && !isset($collected[$requiredPackage->getName()])) { if ($requiredPackage && !isset($collected[$requiredPackage->getName()])) {
$collected[$requiredPackage->getName()] = $requiredPackage; $collected[$requiredPackage->getName()] = $requiredPackage;
$collected = $this->collectDependencies($pool, $collected, $requiredPackage); $collected = $this->collectDependencies($repositorySet, $collected, $requiredPackage);
} }
} }
@ -294,18 +294,18 @@ class PluginManager
} }
/** /**
* Resolves a package link to a package in the installed pool * Resolves a package link to a package in the installed repo set
* *
* Since dependencies are already installed this should always find one. * Since dependencies are already installed this should always find one.
* *
* @param Pool $pool Pool of installed packages only * @param RepositorySet $repositorySet Repository set of installed packages only
* @param Link $link Package link to look up * @param Link $link Package link to look up
* *
* @return PackageInterface|null The found package * @return PackageInterface|null The found package
*/ */
private function lookupInstalledPackage(Pool $pool, Link $link) private function lookupInstalledPackage(RepositorySet $repositorySet, Link $link)
{ {
$packages = $pool->whatProvides($link->getTarget(), $link->getConstraint()); $packages = $repositorySet->findPackages($link->getTarget(), $link->getConstraint(), false);
return !empty($packages) ? $packages[0] : null; return !empty($packages) ? $packages[0] : null;
} }

View File

@ -0,0 +1,38 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Repository;
use Composer\Package\PackageInterface;
/**
* Repository interface.
*
* @author Nils Adermann <naderman@naderman.de>
* @author Konstantin Kudryashov <ever.zet@gmail.com>
* @author Jordi Boggiano <j.boggiano@seld.be>
*/
interface AsyncRepositoryInterface
{
/**
* @param array $names Names of packages to retrieve data for
* @return scalar Id to be passed to later loadPackages call
*/
public function requestPackages(array $names);
/**
* @param array $names
* @return scalar id for load call
*/
public function returnPackages($loadId);
}

View File

@ -24,6 +24,21 @@ use Composer\Package\Link;
*/ */
abstract class BaseRepository implements RepositoryInterface abstract class BaseRepository implements RepositoryInterface
{ {
// TODO should this stay here? some repos need a better implementation
public function loadPackages(array $packageNameMap, $isPackageAcceptableCallable)
{
$packages = $this->getPackages();
$result = array();
foreach ($packages as $package) {
if (isset($packageNameMap[$package->getName()]) && call_user_func($isPackageAcceptableCallable, $package->getNames(), $package->getStability())) {
$result[] = $package;
}
}
return $result;
}
/** /**
* Returns a list of links causing the requested needle packages to be installed, as an associative array with the * Returns a list of links causing the requested needle packages to be installed, as an associative array with the
* dependent's name as key, and an array containing in order the PackageInterface and Link describing the relationship * dependent's name as key, and an array containing in order the PackageInterface and Link describing the relationship

View File

@ -16,7 +16,6 @@ use Composer\Package\Loader\ArrayLoader;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Package\AliasPackage; use Composer\Package\AliasPackage;
use Composer\Package\Version\VersionParser; use Composer\Package\Version\VersionParser;
use Composer\DependencyResolver\Pool;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Cache; use Composer\Cache;
use Composer\Config; use Composer\Config;
@ -136,7 +135,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
foreach ($this->getProviderNames() as $providerName) { foreach ($this->getProviderNames() as $providerName) {
if ($name === $providerName) { if ($name === $providerName) {
$packages = $this->whatProvides(new Pool('dev'), $providerName); $packages = $this->whatProvides($providerName);
foreach ($packages as $package) { foreach ($packages as $package) {
if ($name === $package->getName()) { if ($name === $package->getName()) {
$pkgConstraint = new Constraint('==', $package->getVersion()); $pkgConstraint = new Constraint('==', $package->getVersion());
@ -170,7 +169,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
foreach ($this->getProviderNames() as $providerName) { foreach ($this->getProviderNames() as $providerName) {
if ($name === $providerName) { if ($name === $providerName) {
$candidates = $this->whatProvides(new Pool('dev'), $providerName); $candidates = $this->whatProvides($providerName);
foreach ($candidates as $package) { foreach ($candidates as $package) {
if ($name === $package->getName()) { if ($name === $package->getName()) {
$pkgConstraint = new Constraint('==', $package->getVersion()); $pkgConstraint = new Constraint('==', $package->getVersion());
@ -195,6 +194,26 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
return parent::getPackages(); return parent::getPackages();
} }
public function loadPackages(array $packageNameMap, $isPackageAcceptableCallable)
{
if (!$this->hasProviders()) {
// TODO build more efficient version of this
return parent::loadPackages($packageNameMap, $isPackageAcceptableCallable);
}
$packages = array();
foreach ($packageNameMap as $name => $void) {
$matches = array();
foreach ($this->whatProvides($name, false, $isPackageAcceptableCallable) as $match) {
if ($match->getName() === $name) {
$matches[] = $match;
}
}
$packages = array_merge($packages, $matches);
}
return $packages;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -289,12 +308,12 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
} }
/** /**
* @param Pool $pool * @param string $name package name
* @param string $name package name * @param bool $bypassFilters If set to true, this bypasses the stability filtering, and forces a recompute without cache
* @param bool $bypassFilters If set to true, this bypasses the stability filtering, and forces a recompute without cache * @param callable $isPackageAcceptableCallable
* @return array|mixed * @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) { if (isset($this->providers[$name]) && !$bypassFilters) {
return $this->providers[$name]; return $this->providers[$name];
@ -395,7 +414,7 @@ class ComposerRepository extends ArrayRepository implements ConfigurableReposito
} }
} }
} else { } 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; continue;
} }

View File

@ -0,0 +1,25 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Repository;
/**
* Lock array repository.
*
* Regular array repository, only uses a different type to identify the lock file as the source of info
*
* @author Nils Adermann <naderman@naderman.de>
*/
class LockArrayRepository extends ArrayRepository implements RepositoryInterface
{
}

View File

@ -55,6 +55,7 @@ interface RepositoryInterface extends \Countable
*/ */
public function findPackages($name, $constraint = null); public function findPackages($name, $constraint = null);
// TODO this should really not be in this generic interface anymore
/** /**
* Returns list of registered packages. * Returns list of registered packages.
* *
@ -62,6 +63,15 @@ interface RepositoryInterface extends \Countable
*/ */
public function getPackages(); public function getPackages();
/**
* Returns list of registered packages with the supplied name
*
* @param bool[] $packageNameMap
* @param $isPackageAcceptableCallable
* @return PackageInterface[]
*/
public function loadPackages(array $packageNameMap, $isPackageAcceptableCallable);
/** /**
* Searches the repository for packages containing the query * Searches the repository for packages containing the query
* *

View File

@ -0,0 +1,179 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
* Jordi Boggiano <j.boggiano@seld.be>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Repository;
use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\PoolBuilder;
use Composer\DependencyResolver\Request;
use Composer\Package\BasePackage;
use Composer\Package\Version\VersionParser;
use Composer\Repository\CompositeRepository;
use Composer\Repository\PlatformRepository;
use Composer\Semver\Constraint\ConstraintInterface;
use Composer\Test\DependencyResolver\PoolTest;
/**
* @author Nils Adermann <naderman@naderman.de>
*/
class RepositorySet
{
/** @var array */
private $rootAliases;
/** @var RepositoryInterface[] */
private $repositories = array();
private $acceptableStabilities;
private $stabilityFlags;
protected $filterRequires;
/** @var Pool */
private $pool;
public function __construct(array $rootAliases = array(), $minimumStability = 'stable', array $stabilityFlags = array(), array $filterRequires = array())
{
$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]);
}
}
}
/**
* Adds a repository to this repository set
*
* @param RepositoryInterface $repo A package repository
*/
public function addRepository(RepositoryInterface $repo)
{
if ($this->pool) {
throw new \RuntimeException("Pool has already been created from this repository set, it cannot be modified anymore.");
}
if ($repo instanceof CompositeRepository) {
$repos = $repo->getRepositories();
} else {
$repos = array($repo);
}
foreach ($repos as $repo) {
$this->repositories[] = $repo;
}
}
public function 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 providing or matching a name and optionally meeting a constraint in all repositories
*
* @param string $name
* @param ConstraintInterface|null $constraint
* @param bool $exactMatch
* @return array
*/
public function findPackages($name, ConstraintInterface $constraint = null, $exactMatch = 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 ($exactMatch && $candidate->getName() !== $name) {
continue;
}
if ($this->isPackageAcceptable($candidate->getNames(), $candidate->getStability())) {
$result[] = $candidate;
}
}
return $candidates;
}
public function getPriority(RepositoryInterface $repo)
{
$priority = array_search($repo, $this->repositories, true);
if (false === $priority) {
throw new \RuntimeException("Could not determine repository priority. The repository was not registered in the pool.");
}
return -$priority;
}
/**
* Create a pool for dependency resolution from the packages in this repository set.
*
* @return Pool
*/
public function createPool(Request $request)
{
$poolBuilder = new PoolBuilder(array($this, 'isPackageAcceptable'), $this->filterRequires);
return $this->pool = $poolBuilder->buildPool($this->repositories, $this->rootAliases, $request);
}
// TODO unify this with above in some simpler version without "request"?
public function createPoolForPackage($packageName)
{
return $this->createPoolForPackages(array($packageName));
}
public function createPoolForPackages($packageNames)
{
$request = new Request();
foreach ($packageNames as $packageName) {
$request->install($packageName);
}
return $this->createPool($request);
}
/**
* Access the pool object after it has been created, relevant for plugins which need to read info from the pool
* @return Pool
*/
public function getPool()
{
return $this->pool;
}
}

View File

@ -18,13 +18,15 @@ use Composer\DependencyResolver\DefaultPolicy;
use Composer\DependencyResolver\Pool; use Composer\DependencyResolver\Pool;
use Composer\Package\Link; use Composer\Package\Link;
use Composer\Package\AliasPackage; use Composer\Package\AliasPackage;
use Composer\Repository\RepositorySet;
use Composer\Semver\Constraint\Constraint; use Composer\Semver\Constraint\Constraint;
use Composer\TestCase; use Composer\TestCase;
use http\Env\Request;
class DefaultPolicyTest extends TestCase class DefaultPolicyTest extends TestCase
{ {
/** @var Pool */ /** @var RepositorySet */
protected $pool; protected $repositorySet;
/** @var ArrayRepository */ /** @var ArrayRepository */
protected $repo; protected $repo;
/** @var ArrayRepository */ /** @var ArrayRepository */
@ -34,7 +36,7 @@ class DefaultPolicyTest extends TestCase
public function setUp() public function setUp()
{ {
$this->pool = new Pool('dev'); $this->repositorySet = new RepositorySet(array(), 'dev');
$this->repo = new ArrayRepository; $this->repo = new ArrayRepository;
$this->repoInstalled = new ArrayRepository; $this->repoInstalled = new ArrayRepository;
@ -44,12 +46,14 @@ class DefaultPolicyTest extends TestCase
public function testSelectSingle() public function testSelectSingle()
{ {
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0')); $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$this->pool->addRepository($this->repo); $this->repositorySet->addRepository($this->repo);
$pool = $this->repositorySet->createPoolForPackage('A');
$literals = array($packageA->getId()); $literals = array($packageA->getId());
$expected = 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); $this->assertSame($expected, $selected);
} }
@ -58,12 +62,14 @@ class DefaultPolicyTest extends TestCase
{ {
$this->repo->addPackage($packageA1 = $this->getPackage('A', '1.0')); $this->repo->addPackage($packageA1 = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageA2 = $this->getPackage('A', '2.0')); $this->repo->addPackage($packageA2 = $this->getPackage('A', '2.0'));
$this->pool->addRepository($this->repo); $this->repositorySet->addRepository($this->repo);
$pool = $this->repositorySet->createPoolForPackage('A');
$literals = array($packageA1->getId(), $packageA2->getId()); $literals = array($packageA1->getId(), $packageA2->getId());
$expected = array($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); $this->assertSame($expected, $selected);
} }
@ -72,12 +78,14 @@ class DefaultPolicyTest extends TestCase
{ {
$this->repo->addPackage($packageA1 = $this->getPackage('A', '1.0.0')); $this->repo->addPackage($packageA1 = $this->getPackage('A', '1.0.0'));
$this->repo->addPackage($packageA2 = $this->getPackage('A', '1.0.1-alpha')); $this->repo->addPackage($packageA2 = $this->getPackage('A', '1.0.1-alpha'));
$this->pool->addRepository($this->repo); $this->repositorySet->addRepository($this->repo);
$pool = $this->repositorySet->createPoolForPackage('A');
$literals = array($packageA1->getId(), $packageA2->getId()); $literals = array($packageA1->getId(), $packageA2->getId());
$expected = array($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); $this->assertSame($expected, $selected);
} }
@ -86,13 +94,15 @@ class DefaultPolicyTest extends TestCase
{ {
$this->repo->addPackage($packageA1 = $this->getPackage('A', '1.0.0')); $this->repo->addPackage($packageA1 = $this->getPackage('A', '1.0.0'));
$this->repo->addPackage($packageA2 = $this->getPackage('A', '1.0.1-alpha')); $this->repo->addPackage($packageA2 = $this->getPackage('A', '1.0.1-alpha'));
$this->pool->addRepository($this->repo); $this->repositorySet->addRepository($this->repo);
$pool = $this->repositorySet->createPoolForPackage('A');
$literals = array($packageA1->getId(), $packageA2->getId()); $literals = array($packageA1->getId(), $packageA2->getId());
$expected = array($packageA1->getId()); $expected = array($packageA1->getId());
$policy = new DefaultPolicy(true); $policy = new DefaultPolicy(true);
$selected = $policy->selectPreferredPackages($this->pool, array(), $literals); $selected = $policy->selectPreferredPackages($pool, array(), $literals);
$this->assertSame($expected, $selected); $this->assertSame($expected, $selected);
} }
@ -101,12 +111,14 @@ class DefaultPolicyTest extends TestCase
{ {
$this->repo->addPackage($packageA1 = $this->getPackage('A', 'dev-foo')); $this->repo->addPackage($packageA1 = $this->getPackage('A', 'dev-foo'));
$this->repo->addPackage($packageA2 = $this->getPackage('A', '1.0.0')); $this->repo->addPackage($packageA2 = $this->getPackage('A', '1.0.0'));
$this->pool->addRepository($this->repo); $this->repositorySet->addRepository($this->repo);
$pool = $this->repositorySet->createPoolForPackage('A');
$literals = array($packageA1->getId(), $packageA2->getId()); $literals = array($packageA1->getId(), $packageA2->getId());
$expected = array($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); $this->assertSame($expected, $selected);
} }
@ -115,13 +127,15 @@ class DefaultPolicyTest extends TestCase
{ {
$this->repo->addPackage($packageA = $this->getPackage('A', '2.0')); $this->repo->addPackage($packageA = $this->getPackage('A', '2.0'));
$this->repoInstalled->addPackage($packageAInstalled = $this->getPackage('A', '1.0')); $this->repoInstalled->addPackage($packageAInstalled = $this->getPackage('A', '1.0'));
$this->pool->addRepository($this->repoInstalled); $this->repositorySet->addRepository($this->repoInstalled);
$this->pool->addRepository($this->repo); $this->repositorySet->addRepository($this->repo);
$pool = $this->repositorySet->createPoolForPackage('A');
$literals = array($packageA->getId(), $packageAInstalled->getId()); $literals = array($packageA->getId(), $packageAInstalled->getId());
$expected = array($packageA->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); $this->assertSame($expected, $selected);
} }
@ -133,14 +147,16 @@ class DefaultPolicyTest extends TestCase
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0')); $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
$otherRepository->addPackage($packageAImportant = $this->getPackage('A', '1.0')); $otherRepository->addPackage($packageAImportant = $this->getPackage('A', '1.0'));
$this->pool->addRepository($this->repoInstalled); $this->repositorySet->addRepository($this->repoInstalled);
$this->pool->addRepository($otherRepository); $this->repositorySet->addRepository($otherRepository);
$this->pool->addRepository($this->repo); $this->repositorySet->addRepository($this->repo);
$pool = $this->repositorySet->createPoolForPackage('A');
$literals = array($packageA->getId(), $packageAImportant->getId()); $literals = array($packageA->getId(), $packageAImportant->getId());
$expected = array($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); $this->assertSame($expected, $selected);
} }
@ -155,21 +171,25 @@ class DefaultPolicyTest extends TestCase
$repo2->addPackage($package3 = $this->getPackage('A', '1.1')); $repo2->addPackage($package3 = $this->getPackage('A', '1.1'));
$repo2->addPackage($package4 = $this->getPackage('A', '1.2')); $repo2->addPackage($package4 = $this->getPackage('A', '1.2'));
$this->pool->addRepository($repo1); $this->repositorySet->addRepository($repo1);
$this->pool->addRepository($repo2); $this->repositorySet->addRepository($repo2);
$pool = $this->repositorySet->createPoolForPackage('A');
$literals = array($package1->getId(), $package2->getId(), $package3->getId(), $package4->getId()); $literals = array($package1->getId(), $package2->getId(), $package3->getId(), $package4->getId());
$expected = array($package2->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->assertSame($expected, $selected);
$this->pool = new Pool('dev'); $this->repositorySet = new RepositorySet(array(), 'dev');
$this->pool->addRepository($repo2); $this->repositorySet->addRepository($repo2);
$this->pool->addRepository($repo1); $this->repositorySet->addRepository($repo1);
$pool = $this->repositorySet->createPoolForPackage('A');
$expected = array($package4->getId()); $expected = array($package4->getId());
$selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); $selected = $this->policy->selectPreferredPackages($pool, array(), $literals);
$this->assertSame($expected, $selected); $this->assertSame($expected, $selected);
} }
@ -186,11 +206,13 @@ class DefaultPolicyTest extends TestCase
$repoImportant->addPackage($packageA2AliasImportant = new AliasPackage($packageA2Important, '2.1.9999999.9999999-dev', '2.1.x-dev')); $repoImportant->addPackage($packageA2AliasImportant = new AliasPackage($packageA2Important, '2.1.9999999.9999999-dev', '2.1.x-dev'));
$packageAAliasImportant->setRootPackageAlias(true); $packageAAliasImportant->setRootPackageAlias(true);
$this->pool->addRepository($this->repoInstalled); $this->repositorySet->addRepository($this->repoInstalled);
$this->pool->addRepository($repoImportant); $this->repositorySet->addRepository($repoImportant);
$this->pool->addRepository($this->repo); $this->repositorySet->addRepository($this->repo);
$packages = $this->pool->whatProvides('a', new Constraint('=', '2.1.9999999.9999999-dev')); $pool = $this->repositorySet->createPoolForPackage('A');
$packages = $pool->whatProvides('a', new Constraint('=', '2.1.9999999.9999999-dev'));
$literals = array(); $literals = array();
foreach ($packages as $package) { foreach ($packages as $package) {
$literals[] = $package->getId(); $literals[] = $package->getId();
@ -198,7 +220,7 @@ class DefaultPolicyTest extends TestCase
$expected = array($packageAAliasImportant->getId()); $expected = array($packageAAliasImportant->getId());
$selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); $selected = $this->policy->selectPreferredPackages($pool, array(), $literals);
$this->assertSame($expected, $selected); $this->assertSame($expected, $selected);
} }
@ -211,12 +233,14 @@ class DefaultPolicyTest extends TestCase
$packageA->setProvides(array(new Link('A', 'X', new Constraint('==', '1.0'), 'provides'))); $packageA->setProvides(array(new Link('A', 'X', new Constraint('==', '1.0'), 'provides')));
$packageB->setProvides(array(new Link('B', '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->createPoolForPackages(array('A', 'B'));
$literals = array($packageA->getId(), $packageB->getId()); $literals = array($packageA->getId(), $packageB->getId());
$expected = $literals; $expected = $literals;
$selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); $selected = $this->policy->selectPreferredPackages($pool, array(), $literals);
$this->assertSame($expected, $selected); $this->assertSame($expected, $selected);
} }
@ -228,12 +252,14 @@ class DefaultPolicyTest extends TestCase
$packageB->setReplaces(array(new Link('B', 'A', new Constraint('==', '1.0'), 'replaces'))); $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->createPoolForPackages(array('A', 'B'));
$literals = array($packageA->getId(), $packageB->getId()); $literals = array($packageA->getId(), $packageB->getId());
$expected = $literals; $expected = $literals;
$selected = $this->policy->selectPreferredPackages($this->pool, array(), $literals); $selected = $this->policy->selectPreferredPackages($pool, array(), $literals);
$this->assertSame($expected, $selected); $this->assertSame($expected, $selected);
} }
@ -247,12 +273,14 @@ class DefaultPolicyTest extends TestCase
$packageA->setReplaces(array(new Link('vendor-a/replacer', 'vendor-a/package', new Constraint('==', '1.0'), 'replaces'))); $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'))); $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->createPoolForPackages(array('vendor-a/replacer', 'vendor-b/replacer'));
$literals = array($packageA->getId(), $packageB->getId()); $literals = array($packageA->getId(), $packageB->getId());
$expected = $literals; $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); $this->assertEquals($expected, $selected);
// test with reversed order in repo // test with reversed order in repo
@ -260,13 +288,15 @@ class DefaultPolicyTest extends TestCase
$repo->addPackage($packageA = clone $packageA); $repo->addPackage($packageA = clone $packageA);
$repo->addPackage($packageB = clone $packageB); $repo->addPackage($packageB = clone $packageB);
$pool = new Pool('dev'); $repositorySet = new RepositorySet(array(), 'dev');
$pool->addRepository($this->repo); $repositorySet->addRepository($this->repo);
$pool = $this->repositorySet->createPoolForPackages(array('vendor-a/replacer', 'vendor-b/replacer'));
$literals = array($packageA->getId(), $packageB->getId()); $literals = array($packageA->getId(), $packageB->getId());
$expected = $literals; $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); $this->assertSame($expected, $selected);
} }
@ -286,12 +316,14 @@ class DefaultPolicyTest extends TestCase
$this->repo->addPackage($packageA1 = $this->getPackage('A', '1.0')); $this->repo->addPackage($packageA1 = $this->getPackage('A', '1.0'));
$this->repo->addPackage($packageA2 = $this->getPackage('A', '2.0')); $this->repo->addPackage($packageA2 = $this->getPackage('A', '2.0'));
$this->pool->addRepository($this->repo); $this->repositorySet->addRepository($this->repo);
$pool = $this->repositorySet->createPoolForPackage('A');
$literals = array($packageA1->getId(), $packageA2->getId()); $literals = array($packageA1->getId(), $packageA2->getId());
$expected = array($packageA1->getId()); $expected = array($packageA1->getId());
$selected = $policy->selectPreferredPackages($this->pool, array(), $literals); $selected = $policy->selectPreferredPackages($pool, array(), $literals);
$this->assertSame($expected, $selected); $this->assertSame($expected, $selected);
} }

View File

@ -21,91 +21,26 @@ class PoolTest extends TestCase
{ {
public function testPool() public function testPool()
{ {
$pool = new Pool; $pool = $this->createPool();
$repo = new ArrayRepository;
$package = $this->getPackage('foo', '1'); $package = $this->getPackage('foo', '1');
$repo->addPackage($package); $pool->setPackages(array($package));
$pool->addRepository($repo);
$this->assertEquals(array($package), $pool->whatProvides('foo')); $this->assertEquals(array($package), $pool->whatProvides('foo'));
$this->assertEquals(array($package), $pool->whatProvides('foo')); $this->assertEquals(array($package), $pool->whatProvides('foo'));
} }
public function testPoolIgnoresIrrelevantPackages()
{
$pool = new Pool('stable', array('bar' => BasePackage::STABILITY_BETA));
$repo = new ArrayRepository;
$repo->addPackage($package = $this->getPackage('bar', '1'));
$repo->addPackage($betaPackage = $this->getPackage('bar', '1-beta'));
$repo->addPackage($alphaPackage = $this->getPackage('bar', '1-alpha'));
$repo->addPackage($package2 = $this->getPackage('foo', '1'));
$repo->addPackage($rcPackage2 = $this->getPackage('foo', '1rc'));
$pool->addRepository($repo);
$this->assertEquals(array($package, $betaPackage), $pool->whatProvides('bar'));
$this->assertEquals(array($package2), $pool->whatProvides('foo'));
}
/**
* @expectedException \RuntimeException
*/
public function testGetPriorityForNotRegisteredRepository()
{
$pool = new Pool;
$repository = new ArrayRepository;
$pool->getPriority($repository);
}
public function testGetPriorityWhenRepositoryIsRegistered()
{
$pool = new Pool;
$firstRepository = new ArrayRepository;
$pool->addRepository($firstRepository);
$secondRepository = new ArrayRepository;
$pool->addRepository($secondRepository);
$firstPriority = $pool->getPriority($firstRepository);
$secondPriority = $pool->getPriority($secondRepository);
$this->assertEquals(0, $firstPriority);
$this->assertEquals(-1, $secondPriority);
}
public function testWhatProvidesSamePackageForDifferentRepositories()
{
$pool = new Pool;
$firstRepository = new ArrayRepository;
$secondRepository = new ArrayRepository;
$firstPackage = $this->getPackage('foo', '1');
$secondPackage = $this->getPackage('foo', '1');
$thirdPackage = $this->getPackage('foo', '2');
$firstRepository->addPackage($firstPackage);
$secondRepository->addPackage($secondPackage);
$secondRepository->addPackage($thirdPackage);
$pool->addRepository($firstRepository);
$pool->addRepository($secondRepository);
$this->assertEquals(array($firstPackage, $secondPackage, $thirdPackage), $pool->whatProvides('foo'));
}
public function testWhatProvidesPackageWithConstraint() public function testWhatProvidesPackageWithConstraint()
{ {
$pool = new Pool; $pool = $this->createPool();
$repository = new ArrayRepository;
$firstPackage = $this->getPackage('foo', '1'); $firstPackage = $this->getPackage('foo', '1');
$secondPackage = $this->getPackage('foo', '2'); $secondPackage = $this->getPackage('foo', '2');
$repository->addPackage($firstPackage); $pool->setPackages(array(
$repository->addPackage($secondPackage); $firstPackage,
$secondPackage,
$pool->addRepository($repository); ));
$this->assertEquals(array($firstPackage, $secondPackage), $pool->whatProvides('foo')); $this->assertEquals(array($firstPackage, $secondPackage), $pool->whatProvides('foo'));
$this->assertEquals(array($secondPackage), $pool->whatProvides('foo', $this->getVersionConstraint('==', '2'))); $this->assertEquals(array($secondPackage), $pool->whatProvides('foo', $this->getVersionConstraint('==', '2')));
@ -113,20 +48,23 @@ class PoolTest extends TestCase
public function testPackageById() public function testPackageById()
{ {
$pool = new Pool; $pool = $this->createPool();
$repository = new ArrayRepository;
$package = $this->getPackage('foo', '1'); $package = $this->getPackage('foo', '1');
$repository->addPackage($package); $pool->setPackages(array($package));
$pool->addRepository($repository);
$this->assertSame($package, $pool->packageById(1)); $this->assertSame($package, $pool->packageById(1));
} }
public function testWhatProvidesWhenPackageCannotBeFound() public function testWhatProvidesWhenPackageCannotBeFound()
{ {
$pool = new Pool; $pool = $this->createPool();
$this->assertEquals(array(), $pool->whatProvides('foo')); $this->assertEquals(array(), $pool->whatProvides('foo'));
} }
protected function createPool()
{
return new Pool(array('stable' => BasePackage::STABILITY_STABLE));
}
} }

View File

@ -17,6 +17,7 @@ use Composer\DependencyResolver\Rule;
use Composer\DependencyResolver\RuleSet; use Composer\DependencyResolver\RuleSet;
use Composer\DependencyResolver\RuleSetIterator; use Composer\DependencyResolver\RuleSetIterator;
use Composer\DependencyResolver\Pool; use Composer\DependencyResolver\Pool;
use Composer\Package\BasePackage;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class RuleSetIteratorTest extends TestCase class RuleSetIteratorTest extends TestCase
@ -26,7 +27,7 @@ class RuleSetIteratorTest extends TestCase
protected function setUp() protected function setUp()
{ {
$this->pool = new Pool; $this->pool = new Pool(array('stable' => BasePackage::STABILITY_STABLE));
$this->rules = array( $this->rules = array(
RuleSet::TYPE_JOB => array( RuleSet::TYPE_JOB => array(

View File

@ -16,18 +16,12 @@ use Composer\DependencyResolver\GenericRule;
use Composer\DependencyResolver\Rule; use Composer\DependencyResolver\Rule;
use Composer\DependencyResolver\RuleSet; use Composer\DependencyResolver\RuleSet;
use Composer\DependencyResolver\Pool; use Composer\DependencyResolver\Pool;
use Composer\Package\BasePackage;
use Composer\Repository\ArrayRepository; use Composer\Repository\ArrayRepository;
use Composer\TestCase; use Composer\TestCase;
class RuleSetTest extends TestCase class RuleSetTest extends TestCase
{ {
protected $pool;
public function setUp()
{
$this->pool = new Pool;
}
public function testAdd() public function testAdd()
{ {
$rules = array( $rules = array(
@ -145,9 +139,11 @@ class RuleSetTest extends TestCase
public function testPrettyString() public function testPrettyString()
{ {
$repo = new ArrayRepository; $pool = new Pool(array('stable' => BasePackage::STABILITY_STABLE));
$repo->addPackage($p = $this->getPackage('foo', '2.1')); $pool->setPackages(array(
$this->pool->addRepository($repo); $p = $this->getPackage('foo', '2.1'),
));
$p->setId(1);
$ruleSet = new RuleSet; $ruleSet = new RuleSet;
$literal = $p->getId(); $literal = $p->getId();
@ -155,7 +151,7 @@ class RuleSetTest extends TestCase
$ruleSet->add($rule, RuleSet::TYPE_JOB); $ruleSet->add($rule, RuleSet::TYPE_JOB);
$this->assertContains('JOB : Install command rule (install foo 2.1)', $ruleSet->getPrettyString($this->pool)); $this->assertContains('JOB : Install command rule (install foo 2.1)', $ruleSet->getPrettyString($pool));
} }
private function getRuleMock() private function getRuleMock()

View File

@ -16,18 +16,12 @@ use Composer\DependencyResolver\GenericRule;
use Composer\DependencyResolver\Rule; use Composer\DependencyResolver\Rule;
use Composer\DependencyResolver\RuleSet; use Composer\DependencyResolver\RuleSet;
use Composer\DependencyResolver\Pool; use Composer\DependencyResolver\Pool;
use Composer\Package\BasePackage;
use Composer\Repository\ArrayRepository; use Composer\Repository\ArrayRepository;
use Composer\TestCase; use Composer\TestCase;
class RuleTest extends TestCase class RuleTest extends TestCase
{ {
protected $pool;
public function setUp()
{
$this->pool = new Pool;
}
public function testGetHash() public function testGetHash()
{ {
$rule = new GenericRule(array(123), Rule::RULE_JOB_INSTALL, null); $rule = new GenericRule(array(123), Rule::RULE_JOB_INSTALL, null);
@ -99,13 +93,16 @@ class RuleTest extends TestCase
public function testPrettyString() public function testPrettyString()
{ {
$repo = new ArrayRepository; $pool = new Pool(array('stable' => BasePackage::STABILITY_STABLE));
$repo->addPackage($p1 = $this->getPackage('foo', '2.1')); $pool->setPackages(array(
$repo->addPackage($p2 = $this->getPackage('baz', '1.1')); $p1 = $this->getPackage('foo', '2.1'),
$this->pool->addRepository($repo); $p2 = $this->getPackage('baz', '1.1'),
));
$p1->setId(1);
$p2->setId(2);
$rule = new GenericRule(array($p1->getId(), -$p2->getId()), Rule::RULE_JOB_INSTALL, null); $rule = new GenericRule(array($p1->getId(), -$p2->getId()), Rule::RULE_JOB_INSTALL, null);
$this->assertEquals('Install command rule (don\'t install baz 1.1|install foo 2.1)', $rule->getPrettyString($this->pool)); $this->assertEquals('Install command rule (don\'t install baz 1.1|install foo 2.1)', $rule->getPrettyString($pool));
} }
} }

View File

@ -20,26 +20,28 @@ use Composer\DependencyResolver\Request;
use Composer\DependencyResolver\Solver; use Composer\DependencyResolver\Solver;
use Composer\DependencyResolver\SolverProblemsException; use Composer\DependencyResolver\SolverProblemsException;
use Composer\Package\Link; use Composer\Package\Link;
use Composer\Repository\InstalledArrayRepository;
use Composer\Repository\RepositorySet;
use Composer\TestCase; use Composer\TestCase;
use Composer\Semver\Constraint\MultiConstraint; use Composer\Semver\Constraint\MultiConstraint;
class SolverTest extends TestCase class SolverTest extends TestCase
{ {
protected $pool; protected $repoSet;
protected $repo; protected $repo;
protected $repoInstalled; protected $repoInstalled;
protected $request; protected $request;
protected $policy; protected $policy;
protected $solver;
public function setUp() public function setUp()
{ {
$this->pool = new Pool; $this->repoSet = new RepositorySet(array());
$this->repo = new ArrayRepository; $this->repo = new ArrayRepository;
$this->repoInstalled = new ArrayRepository; $this->repoInstalled = new InstalledArrayRepository;
$this->request = new Request($this->pool); $this->request = new Request($this->repoSet);
$this->policy = new DefaultPolicy; $this->policy = new DefaultPolicy;
$this->solver = new Solver($this->policy, $this->pool, $this->repoInstalled, new NullIO());
} }
public function testSolverInstallSingle() public function testSolverInstallSingle()
@ -71,6 +73,7 @@ class SolverTest extends TestCase
$this->request->install('B', $this->getVersionConstraint('==', '1')); $this->request->install('B', $this->getVersionConstraint('==', '1'));
$this->createSolver();
try { try {
$transaction = $this->solver->solve($this->request); $transaction = $this->solver->solve($this->request);
$this->fail('Unsolvable conflict did not result in exception.'); $this->fail('Unsolvable conflict did not result in exception.');
@ -90,9 +93,9 @@ class SolverTest extends TestCase
$repo1->addPackage($foo1 = $this->getPackage('foo', '1')); $repo1->addPackage($foo1 = $this->getPackage('foo', '1'));
$repo2->addPackage($foo2 = $this->getPackage('foo', '1')); $repo2->addPackage($foo2 = $this->getPackage('foo', '1'));
$this->pool->addRepository($this->repoInstalled); $this->repoSet->addRepository($this->repoInstalled);
$this->pool->addRepository($repo1); $this->repoSet->addRepository($repo1);
$this->pool->addRepository($repo2); $this->repoSet->addRepository($repo2);
$this->request->install('foo'); $this->request->install('foo');
@ -445,6 +448,7 @@ class SolverTest extends TestCase
// must explicitly pick the provider, so error in this case // must explicitly pick the provider, so error in this case
$this->setExpectedException('Composer\DependencyResolver\SolverProblemsException'); $this->setExpectedException('Composer\DependencyResolver\SolverProblemsException');
$this->createSolver();
$this->solver->solve($this->request); $this->solver->solve($this->request);
} }
@ -478,6 +482,7 @@ class SolverTest extends TestCase
$this->request->install('A'); $this->request->install('A');
$this->setExpectedException('Composer\DependencyResolver\SolverProblemsException'); $this->setExpectedException('Composer\DependencyResolver\SolverProblemsException');
$this->createSolver();
$this->solver->solve($this->request); $this->solver->solve($this->request);
} }
@ -650,6 +655,7 @@ class SolverTest extends TestCase
$this->setExpectedException('Composer\DependencyResolver\SolverProblemsException'); $this->setExpectedException('Composer\DependencyResolver\SolverProblemsException');
$this->createSolver();
$this->solver->solve($this->request); $this->solver->solve($this->request);
} }
@ -666,6 +672,7 @@ class SolverTest extends TestCase
$this->request->install('A'); $this->request->install('A');
$this->request->install('B'); $this->request->install('B');
$this->createSolver();
try { try {
$transaction = $this->solver->solve($this->request); $transaction = $this->solver->solve($this->request);
$this->fail('Unsolvable conflict did not result in exception.'); $this->fail('Unsolvable conflict did not result in exception.');
@ -695,6 +702,7 @@ class SolverTest extends TestCase
$this->request->install('A'); $this->request->install('A');
$this->createSolver();
try { try {
$transaction = $this->solver->solve($this->request); $transaction = $this->solver->solve($this->request);
$this->fail('Unsolvable conflict did not result in exception.'); $this->fail('Unsolvable conflict did not result in exception.');
@ -742,6 +750,7 @@ class SolverTest extends TestCase
$this->request->install('A'); $this->request->install('A');
$this->createSolver();
try { try {
$transaction = $this->solver->solve($this->request); $transaction = $this->solver->solve($this->request);
$this->fail('Unsolvable conflict did not result in exception.'); $this->fail('Unsolvable conflict did not result in exception.');
@ -839,12 +848,18 @@ class SolverTest extends TestCase
protected function reposComplete() protected function reposComplete()
{ {
$this->pool->addRepository($this->repoInstalled); $this->repoSet->addRepository($this->repoInstalled);
$this->pool->addRepository($this->repo); $this->repoSet->addRepository($this->repo);
}
protected function createSolver()
{
$this->solver = new Solver($this->policy, $this->repoSet->createPool($this->request), $this->repoInstalled, new NullIO());
} }
protected function checkSolverResult(array $expected) protected function checkSolverResult(array $expected)
{ {
$this->createSolver();
$transaction = $this->solver->solve($this->request); $transaction = $this->solver->solve($this->request);
$result = array(); $result = array();

View File

@ -411,12 +411,12 @@ class EventDispatcherTest extends TestCase
->will($this->returnValue(array())); ->will($this->returnValue(array()));
$policy = $this->getMockBuilder('Composer\DependencyResolver\PolicyInterface')->getMock(); $policy = $this->getMockBuilder('Composer\DependencyResolver\PolicyInterface')->getMock();
$pool = $this->getMockBuilder('Composer\DependencyResolver\Pool')->disableOriginalConstructor()->getMock(); $repositorySet = $this->getMockBuilder('Composer\Repository\RepositorySet')->disableOriginalConstructor()->getMock();
$installedRepo = $this->getMockBuilder('Composer\Repository\CompositeRepository')->disableOriginalConstructor()->getMock(); $installedRepo = $this->getMockBuilder('Composer\Repository\CompositeRepository')->disableOriginalConstructor()->getMock();
$request = $this->getMockBuilder('Composer\DependencyResolver\Request')->disableOriginalConstructor()->getMock(); $request = $this->getMockBuilder('Composer\DependencyResolver\Request')->disableOriginalConstructor()->getMock();
$dispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, true, $policy, $pool, $installedRepo, $request); $dispatcher->dispatchInstallerEvent(InstallerEvents::PRE_DEPENDENCIES_SOLVING, true, $policy, $repositorySet, $installedRepo, $request);
$dispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, true, $policy, $pool, $installedRepo, $request, array()); $dispatcher->dispatchInstallerEvent(InstallerEvents::POST_DEPENDENCIES_SOLVING, true, $policy, $repositorySet, $installedRepo, $request, array());
} }
public static function call() public static function call()

View File

@ -22,18 +22,18 @@ class InstallerEventTest extends TestCase
$composer = $this->getMockBuilder('Composer\Composer')->getMock(); $composer = $this->getMockBuilder('Composer\Composer')->getMock();
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); $io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$policy = $this->getMockBuilder('Composer\DependencyResolver\PolicyInterface')->getMock(); $policy = $this->getMockBuilder('Composer\DependencyResolver\PolicyInterface')->getMock();
$pool = $this->getMockBuilder('Composer\DependencyResolver\Pool')->disableOriginalConstructor()->getMock(); $repositorySet = $this->getMockBuilder('Composer\Repository\RepositorySet')->disableOriginalConstructor()->getMock();
$installedRepo = $this->getMockBuilder('Composer\Repository\CompositeRepository')->disableOriginalConstructor()->getMock(); $installedRepo = $this->getMockBuilder('Composer\Repository\CompositeRepository')->disableOriginalConstructor()->getMock();
$request = $this->getMockBuilder('Composer\DependencyResolver\Request')->disableOriginalConstructor()->getMock(); $request = $this->getMockBuilder('Composer\DependencyResolver\Request')->disableOriginalConstructor()->getMock();
$operations = array($this->getMockBuilder('Composer\DependencyResolver\Operation\OperationInterface')->getMock()); $operations = array($this->getMockBuilder('Composer\DependencyResolver\Operation\OperationInterface')->getMock());
$event = new InstallerEvent('EVENT_NAME', $composer, $io, true, $policy, $pool, $installedRepo, $request, $operations); $event = new InstallerEvent('EVENT_NAME', $composer, $io, true, $policy, $repositorySet, $installedRepo, $request, $operations);
$this->assertSame('EVENT_NAME', $event->getName()); $this->assertSame('EVENT_NAME', $event->getName());
$this->assertInstanceOf('Composer\Composer', $event->getComposer()); $this->assertInstanceOf('Composer\Composer', $event->getComposer());
$this->assertInstanceOf('Composer\IO\IOInterface', $event->getIO()); $this->assertInstanceOf('Composer\IO\IOInterface', $event->getIO());
$this->assertTrue($event->isDevMode()); $this->assertTrue($event->isDevMode());
$this->assertInstanceOf('Composer\DependencyResolver\PolicyInterface', $event->getPolicy()); $this->assertInstanceOf('Composer\DependencyResolver\PolicyInterface', $event->getPolicy());
$this->assertInstanceOf('Composer\DependencyResolver\Pool', $event->getPool()); $this->assertInstanceOf('Composer\Repository\RepositorySet', $event->getRepositorySet());
$this->assertInstanceOf('Composer\Repository\CompositeRepository', $event->getInstalledRepo()); $this->assertInstanceOf('Composer\Repository\CompositeRepository', $event->getInstalledRepo());
$this->assertInstanceOf('Composer\DependencyResolver\Request', $event->getRequest()); $this->assertInstanceOf('Composer\DependencyResolver\Request', $event->getRequest());
$this->assertCount(1, $event->getOperations()); $this->assertCount(1, $event->getOperations());

View File

@ -14,6 +14,7 @@ namespace Composer\Test;
use Composer\Installer; use Composer\Installer;
use Composer\Console\Application; use Composer\Console\Application;
use Composer\IO\BufferIO;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Repository\ArrayRepository; use Composer\Repository\ArrayRepository;
@ -30,7 +31,6 @@ use Symfony\Component\Console\Output\StreamOutput;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Formatter\OutputFormatter;
use Composer\TestCase; use Composer\TestCase;
use Composer\IO\BufferIO;
class InstallerTest extends TestCase class InstallerTest extends TestCase
{ {
@ -57,7 +57,7 @@ class InstallerTest extends TestCase
*/ */
public function testInstaller(RootPackageInterface $rootPackage, $repositories, array $options) public function testInstaller(RootPackageInterface $rootPackage, $repositories, array $options)
{ {
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); $io = new BufferIO('', OutputInterface::VERBOSITY_NORMAL, new OutputFormatter(false));
$downloadManager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $downloadManager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($io)) ->setConstructorArgs(array($io))
@ -82,7 +82,9 @@ class InstallerTest extends TestCase
$installer = new Installer($io, $config, clone $rootPackage, $downloadManager, $repositoryManager, $locker, $installationManager, $eventDispatcher, $autoloadGenerator); $installer = new Installer($io, $config, clone $rootPackage, $downloadManager, $repositoryManager, $locker, $installationManager, $eventDispatcher, $autoloadGenerator);
$result = $installer->run(); $result = $installer->run();
$this->assertSame(0, $result);
$output = str_replace("\r", '', $io->getOutput());
$this->assertEquals(0, $result, $output);
$expectedInstalled = isset($options['install']) ? $options['install'] : array(); $expectedInstalled = isset($options['install']) ? $options['install'] : array();
$expectedUpdated = isset($options['update']) ? $options['update'] : array(); $expectedUpdated = isset($options['update']) ? $options['update'] : array();

View File

@ -21,7 +21,7 @@ use PHPUnit\Framework\TestCase;
class VersionSelectorTest extends TestCase class VersionSelectorTest extends TestCase
{ {
// A) multiple versions, get the latest one // A) multiple versions, get the latest one
// B) targetPackageVersion will pass to pool // B) targetPackageVersion will pass to repo set
// C) No results, throw exception // C) No results, throw exception
public function testLatestVersionIsReturned() public function testLatestVersionIsReturned()
@ -33,13 +33,13 @@ class VersionSelectorTest extends TestCase
$package3 = $this->createPackage('1.2.0'); $package3 = $this->createPackage('1.2.0');
$packages = array($package1, $package2, $package3); $packages = array($package1, $package2, $package3);
$pool = $this->createMockPool(); $repositorySet = $this->createMockRepositorySet();
$pool->expects($this->once()) $repositorySet->expects($this->once())
->method('whatProvides') ->method('findPackages')
->with($packageName, null, true) ->with($packageName, null)
->will($this->returnValue($packages)); ->will($this->returnValue($packages));
$versionSelector = new VersionSelector($pool); $versionSelector = new VersionSelector($repositorySet);
$best = $versionSelector->findBestCandidate($packageName); $best = $versionSelector->findBestCandidate($packageName);
// 1.2.2 should be returned because it's the latest of the returned versions // 1.2.2 should be returned because it's the latest of the returned versions
@ -57,13 +57,13 @@ class VersionSelectorTest extends TestCase
$package2->setRequires(array('php' => new Link($packageName, 'php', $parser->parseConstraints('>=5.6'), 'requires', '>=5.6'))); $package2->setRequires(array('php' => new Link($packageName, 'php', $parser->parseConstraints('>=5.6'), 'requires', '>=5.6')));
$packages = array($package1, $package2); $packages = array($package1, $package2);
$pool = $this->createMockPool(); $repositorySet = $this->createMockRepositorySet();
$pool->expects($this->once()) $repositorySet->expects($this->once())
->method('whatProvides') ->method('findPackages')
->with($packageName, null, true) ->with($packageName, null)
->will($this->returnValue($packages)); ->will($this->returnValue($packages));
$versionSelector = new VersionSelector($pool); $versionSelector = new VersionSelector($repositorySet);
$best = $versionSelector->findBestCandidate($packageName, null, '5.5.0'); $best = $versionSelector->findBestCandidate($packageName, null, '5.5.0');
$this->assertSame($package1, $best, 'Latest version supporting php 5.5 should be returned (1.0.0)'); $this->assertSame($package1, $best, 'Latest version supporting php 5.5 should be returned (1.0.0)');
@ -77,13 +77,13 @@ class VersionSelectorTest extends TestCase
$package2 = $this->createPackage('1.1.0-beta'); $package2 = $this->createPackage('1.1.0-beta');
$packages = array($package1, $package2); $packages = array($package1, $package2);
$pool = $this->createMockPool(); $repositorySet = $this->createMockRepositorySet();
$pool->expects($this->once()) $repositorySet->expects($this->once())
->method('whatProvides') ->method('findPackages')
->with($packageName, null, true) ->with($packageName, null)
->will($this->returnValue($packages)); ->will($this->returnValue($packages));
$versionSelector = new VersionSelector($pool); $versionSelector = new VersionSelector($repositorySet);
$best = $versionSelector->findBestCandidate($packageName); $best = $versionSelector->findBestCandidate($packageName);
$this->assertSame($package1, $best, 'Latest most stable version should be returned (1.0.0)'); $this->assertSame($package1, $best, 'Latest most stable version should be returned (1.0.0)');
@ -97,18 +97,18 @@ class VersionSelectorTest extends TestCase
$package2 = $this->createPackage('2.0.0-beta3'); $package2 = $this->createPackage('2.0.0-beta3');
$packages = array($package1, $package2); $packages = array($package1, $package2);
$pool = $this->createMockPool(); $repositorySet = $this->createMockRepositorySet();
$pool->expects($this->at(0)) $repositorySet->expects($this->at(0))
->method('whatProvides') ->method('findPackages')
->with($packageName, null, true) ->with($packageName, null)
->will($this->returnValue($packages)); ->will($this->returnValue($packages));
$pool->expects($this->at(1)) $repositorySet->expects($this->at(1))
->method('whatProvides') ->method('findPackages')
->with($packageName, null, true) ->with($packageName, null)
->will($this->returnValue(array_reverse($packages))); ->will($this->returnValue(array_reverse($packages)));
$versionSelector = new VersionSelector($pool); $versionSelector = new VersionSelector($repositorySet);
$best = $versionSelector->findBestCandidate($packageName, null, null); $best = $versionSelector->findBestCandidate($packageName, null, null);
$this->assertSame($package2, $best, 'Expecting 2.0.0-beta3, cause beta is more stable than dev'); $this->assertSame($package2, $best, 'Expecting 2.0.0-beta3, cause beta is more stable than dev');
@ -124,13 +124,13 @@ class VersionSelectorTest extends TestCase
$package2 = $this->createPackage('1.1.0-beta'); $package2 = $this->createPackage('1.1.0-beta');
$packages = array($package1, $package2); $packages = array($package1, $package2);
$pool = $this->createMockPool(); $repositorySet = $this->createMockRepositorySet();
$pool->expects($this->once()) $repositorySet->expects($this->once())
->method('whatProvides') ->method('findPackages')
->with($packageName, null, true) ->with($packageName, null)
->will($this->returnValue($packages)); ->will($this->returnValue($packages));
$versionSelector = new VersionSelector($pool); $versionSelector = new VersionSelector($repositorySet);
$best = $versionSelector->findBestCandidate($packageName, null, null, 'dev'); $best = $versionSelector->findBestCandidate($packageName, null, null, 'dev');
$this->assertSame($package2, $best, 'Latest version should be returned (1.1.0-beta)'); $this->assertSame($package2, $best, 'Latest version should be returned (1.1.0-beta)');
@ -145,13 +145,13 @@ class VersionSelectorTest extends TestCase
$package3 = $this->createPackage('1.2.0-alpha'); $package3 = $this->createPackage('1.2.0-alpha');
$packages = array($package1, $package2, $package3); $packages = array($package1, $package2, $package3);
$pool = $this->createMockPool(); $repositorySet = $this->createMockRepositorySet();
$pool->expects($this->once()) $repositorySet->expects($this->once())
->method('whatProvides') ->method('findPackages')
->with($packageName, null, true) ->with($packageName, null)
->will($this->returnValue($packages)); ->will($this->returnValue($packages));
$versionSelector = new VersionSelector($pool); $versionSelector = new VersionSelector($repositorySet);
$best = $versionSelector->findBestCandidate($packageName, null, null, 'beta'); $best = $versionSelector->findBestCandidate($packageName, null, null, 'beta');
$this->assertSame($package2, $best, 'Latest version should be returned (1.1.0-beta)'); $this->assertSame($package2, $best, 'Latest version should be returned (1.1.0-beta)');
@ -165,13 +165,13 @@ class VersionSelectorTest extends TestCase
$package3 = $this->createPackage('1.2.0-alpha'); $package3 = $this->createPackage('1.2.0-alpha');
$packages = array($package2, $package3); $packages = array($package2, $package3);
$pool = $this->createMockPool(); $repositorySet = $this->createMockRepositorySet();
$pool->expects($this->once()) $repositorySet->expects($this->once())
->method('whatProvides') ->method('findPackages')
->with($packageName, null, true) ->with($packageName, null)
->will($this->returnValue($packages)); ->will($this->returnValue($packages));
$versionSelector = new VersionSelector($pool); $versionSelector = new VersionSelector($repositorySet);
$best = $versionSelector->findBestCandidate($packageName, null, null, 'stable'); $best = $versionSelector->findBestCandidate($packageName, null, null, 'stable');
$this->assertSame($package2, $best, 'Latest version should be returned (1.1.0-beta)'); $this->assertSame($package2, $best, 'Latest version should be returned (1.1.0-beta)');
@ -179,12 +179,12 @@ class VersionSelectorTest extends TestCase
public function testFalseReturnedOnNoPackages() public function testFalseReturnedOnNoPackages()
{ {
$pool = $this->createMockPool(); $repositorySet = $this->createMockRepositorySet();
$pool->expects($this->once()) $repositorySet->expects($this->once())
->method('whatProvides') ->method('findPackages')
->will($this->returnValue(array())); ->will($this->returnValue(array()));
$versionSelector = new VersionSelector($pool); $versionSelector = new VersionSelector($repositorySet);
$best = $versionSelector->findBestCandidate('foobaz'); $best = $versionSelector->findBestCandidate('foobaz');
$this->assertFalse($best, 'No versions are available returns false'); $this->assertFalse($best, 'No versions are available returns false');
} }
@ -194,8 +194,8 @@ class VersionSelectorTest extends TestCase
*/ */
public function testFindRecommendedRequireVersion($prettyVersion, $isDev, $stability, $expectedVersion, $branchAlias = null) public function testFindRecommendedRequireVersion($prettyVersion, $isDev, $stability, $expectedVersion, $branchAlias = null)
{ {
$pool = $this->createMockPool(); $repositorySet = $this->createMockRepositorySet();
$versionSelector = new VersionSelector($pool); $versionSelector = new VersionSelector($repositorySet);
$versionParser = new VersionParser(); $versionParser = new VersionParser();
$package = $this->getMockBuilder('\Composer\Package\PackageInterface')->getMock(); $package = $this->getMockBuilder('\Composer\Package\PackageInterface')->getMock();
@ -273,8 +273,10 @@ class VersionSelectorTest extends TestCase
return new Package('foo', $parser->normalize($version), $version); return new Package('foo', $parser->normalize($version), $version);
} }
private function createMockPool() private function createMockRepositorySet()
{ {
return $this->getMockBuilder('Composer\DependencyResolver\Pool')->getMock(); return $this->getMockBuilder('Composer\Repository\RepositorySet')
->disableOriginalConstructor()
->getMock();
} }
} }

View File

@ -7,6 +7,6 @@
"class": "Installer\\Plugin" "class": "Installer\\Plugin"
}, },
"require": { "require": {
"composer-plugin-api": "^1.0" "composer-plugin-api": "^2.0"
} }
} }

View File

@ -7,6 +7,6 @@
"class": "Installer\\Plugin2" "class": "Installer\\Plugin2"
}, },
"require": { "require": {
"composer-plugin-api": "^1.0" "composer-plugin-api": "^2.0"
} }
} }

View File

@ -7,6 +7,6 @@
"class": "Installer\\Plugin2" "class": "Installer\\Plugin2"
}, },
"require": { "require": {
"composer-plugin-api": "^1.0" "composer-plugin-api": "^2.0"
} }
} }

View File

@ -10,6 +10,6 @@
] ]
}, },
"require": { "require": {
"composer-plugin-api": "^1.0" "composer-plugin-api": "^2.0"
} }
} }

View File

@ -9,6 +9,6 @@
] ]
}, },
"require": { "require": {
"composer-plugin-api": "1.1.0" "composer-plugin-api": "2.0.0"
} }
} }

View File

@ -7,6 +7,6 @@
"class": "Installer\\Plugin" "class": "Installer\\Plugin"
}, },
"require": { "require": {
"composer-plugin-api": "^1.0" "composer-plugin-api": "^2.0"
} }
} }

View File

@ -130,7 +130,7 @@ class PluginInstallerTest extends TestCase
public function testInstallNewPlugin() public function testInstallNewPlugin()
{ {
$this->repository $this->repository
->expects($this->exactly(2)) ->expects($this->once())
->method('getPackages') ->method('getPackages')
->will($this->returnValue(array())); ->will($this->returnValue(array()));
$installer = new PluginInstaller($this->io, $this->composer); $installer = new PluginInstaller($this->io, $this->composer);
@ -145,7 +145,7 @@ class PluginInstallerTest extends TestCase
public function testInstallMultiplePlugins() public function testInstallMultiplePlugins()
{ {
$this->repository $this->repository
->expects($this->exactly(2)) ->expects($this->once())
->method('getPackages') ->method('getPackages')
->will($this->returnValue(array($this->packages[3]))); ->will($this->returnValue(array($this->packages[3])));
$installer = new PluginInstaller($this->io, $this->composer); $installer = new PluginInstaller($this->io, $this->composer);
@ -163,7 +163,7 @@ class PluginInstallerTest extends TestCase
public function testUpgradeWithNewClassName() public function testUpgradeWithNewClassName()
{ {
$this->repository $this->repository
->expects($this->exactly(3)) ->expects($this->once())
->method('getPackages') ->method('getPackages')
->will($this->returnValue(array($this->packages[0]))); ->will($this->returnValue(array($this->packages[0])));
$this->repository $this->repository
@ -182,7 +182,7 @@ class PluginInstallerTest extends TestCase
public function testUpgradeWithSameClassName() public function testUpgradeWithSameClassName()
{ {
$this->repository $this->repository
->expects($this->exactly(3)) ->expects($this->once())
->method('getPackages') ->method('getPackages')
->will($this->returnValue(array($this->packages[1]))); ->will($this->returnValue(array($this->packages[1])));
$this->repository $this->repository
@ -201,7 +201,7 @@ class PluginInstallerTest extends TestCase
public function testRegisterPluginOnlyOneTime() public function testRegisterPluginOnlyOneTime()
{ {
$this->repository $this->repository
->expects($this->exactly(2)) ->expects($this->once())
->method('getPackages') ->method('getPackages')
->will($this->returnValue(array())); ->will($this->returnValue(array()));
$installer = new PluginInstaller($this->io, $this->composer); $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. // Add the plugins to the repo along with the internal Plugin package on which they all rely.
$this->repository $this->repository
->expects($this->any()) ->expects($this->any())
->method('getPackages') ->method('getPackages')
->will($this->returnCallback(function () use ($plugApiInternalPackage, $plugins) { ->will($this->returnCallback(function () use ($plugApiInternalPackage, $plugins) {
return array_merge(array($plugApiInternalPackage), $plugins); return array_merge(array($plugApiInternalPackage), $plugins);
})); }));
$this->pm->loadInstalledPlugins(); $this->pm->loadInstalledPlugins();
} }
@ -300,7 +300,7 @@ class PluginInstallerTest extends TestCase
public function testCommandProviderCapability() public function testCommandProviderCapability()
{ {
$this->repository $this->repository
->expects($this->exactly(2)) ->expects($this->once())
->method('getPackages') ->method('getPackages')
->will($this->returnValue(array($this->packages[7]))); ->will($this->returnValue(array($this->packages[7])));
$installer = new PluginInstaller($this->io, $this->composer); $installer = new PluginInstaller($this->io, $this->composer);

View File

@ -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(); $versionParser = new VersionParser();
$repo->setRootAliases(array( $repo->setRootAliases(array(
'a' => 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->assertCount(7, $packages);
$this->assertEquals(array('1', '1-alias', '2', '2-alias', '2-root', '3', '3-root'), array_keys($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()); $this->assertSame($packages['2'], $packages['2-alias']->getAliasOf());
} }
public function isPackageAcceptableReturnTrue()
{
return true;
}
public function testSearchWithType() public function testSearchWithType()
{ {
$repoConfig = array( $repoConfig = array(