1
0
Fork 0

Import initial partial port of the libzypp satsolver.

pull/1/head
Nils Adermann 2011-04-05 17:37:19 +02:00
parent ea13ad7669
commit 933cc6179b
23 changed files with 3149 additions and 0 deletions

39
PORTING_INFO Normal file
View File

@ -0,0 +1,39 @@
* add rule
* p = direct literal; always < 0 for installed rpm rules
* d, if < 0 direct literal, if > 0 offset into whatprovides, if == 0 rule is assertion (look at p only)
*
*
* A requires b, b provided by B1,B2,B3 => (-A|B1|B2|B3)
*
* p < 0 : pkg id of A
* d > 0 : Offset in whatprovidesdata (list of providers of b)
*
* A conflicts b, b provided by B1,B2,B3 => (-A|-B1), (-A|-B2), (-A|-B3)
* p < 0 : pkg id of A
* d < 0 : Id of solvable (e.g. B1)
*
* d == 0: unary rule, assertion => (A) or (-A)
*
* Install: p > 0, d = 0 (A) user requested install
* Remove: p < 0, d = 0 (-A) user requested remove (also: uninstallable)
* Requires: p < 0, d > 0 (-A|B1|B2|...) d: <list of providers for requirement of p>
* Updates: p > 0, d > 0 (A|B1|B2|...) d: <list of updates for solvable p>
* Conflicts: p < 0, d < 0 (-A|-B) either p (conflict issuer) or d (conflict provider) (binary rule)
* also used for obsoletes
* ?: p > 0, d < 0 (A|-B)
* No-op ?: p = 0, d = 0 (null) (used as policy rule placeholder)
*
* resulting watches:
* ------------------
* Direct assertion (no watch needed)( if d <0 ) --> d = 0, w1 = p, w2 = 0
* Binary rule: p = first literal, d = 0, w2 = second literal, w1 = p
* every other : w1 = p, w2 = whatprovidesdata[d];
* Disabled rule: w1 = 0
*
* always returns a rule for non-rpm rules
p > 0, d = 0, (A), w1 = p, w2 = 0
p < 0, d = 0, (-A), w1 = p, w2 = 0
p !=0, d = 0, (p|q), w1 = p, w2 = q

25
phpunit.xml.dist Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
<testsuite name="Composer Test Suite">
<directory>./tests/Composer/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>./src/Composer/</directory>
</whitelist>
</filter>
</phpunit>

View File

@ -0,0 +1,62 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\DependencyResolver;
/**
* A repository implementation that simply stores packages in an array
*
* @author Nils Adermann <naderman@naderman.de>
*/
class ArrayRepository implements RepositoryInterface
{
protected $packages = array();
/**
* Adds a new package to the repository
*
* @param Package $package
*/
public function addPackage(Package $package)
{
$this->packages[$package->getId()] = $package;
}
/**
* Returns all contained packages
*
* @return array All packages
*/
public function getPackages()
{
return $this->packages;
}
/**
* Checks if a package is contained in this repository
*
* @return bool
*/
public function contains(Package $package)
{
return isset($this->packages[$package->getId()]);
}
/**
* Returns the number of packages in this repository
*
* @return int Number of packages
*/
public function count()
{
return count($this->packages);
}
}

View File

@ -0,0 +1,63 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\DependencyResolver;
/**
* @author Nils Adermann <naderman@naderman.de>
*/
class DefaultPolicy implements PolicyInterface
{
public function allowUninstall()
{
return false;
}
public function allowDowngrade()
{
return false;
}
public function versionCompare(Package $a, Package $b, $operator)
{
return version_compare($a->getVersion(), $b->getVersion(), $operator);
}
public function findUpdatePackages(Solver $solver, Pool $pool, RepositoryInterface $repo, Package $package, $allowAll = false)
{
$packages = array();
foreach ($pool->whatProvides($package->getName()) as $candidate) {
// skip old packages unless downgrades are an option
if (!$allowAll && !$this->allowDowngrade() && $this->versionCompare($package, $candidate, '>')) {
continue;
}
if ($candidate != $package) {
$packages[] = $candidate;
}
}
return $packages;
}
public function installable(Solver $solver, Pool $pool, RepositoryInterface $repo, Package $package)
{
// todo: package blacklist?
return true;
}
public function selectPreferedPackages(array $literals)
{
// todo: prefer installed, recommended, highest priority repository, ...
return array($literals[0]);
}
}

View File

@ -0,0 +1,61 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\DependencyResolver;
/**
* @author Nils Adermann <naderman@naderman.de>
*/
class Literal
{
protected $wanted;
public function __construct(Package $package, $wanted)
{
$this->package = $package;
$this->wanted = $wanted;
}
public function isWanted()
{
return $this->wanted;
}
public function getPackage()
{
return $this->package;
}
public function getPackageId()
{
return $this->package->getId();
}
public function getId()
{
return (($this->wanted) ? 1 : -1) * $this->package->getId();
}
public function __toString()
{
return ($this->isWanted() ? '+' : '-').$this->getPackage();
}
public function inverted()
{
return new Literal($this->getPackage(), !$this->isWanted());
}
public function equals(Literal $b)
{
return $this->getId() === $b->getId();
}
}

View File

@ -0,0 +1,190 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\DependencyResolver;
/**
* A package with setters for all members to create it dynamically in memory
*
* @author Nils Adermann <naderman@naderman.de>
*/
class MemoryPackage extends Package
{
protected $releaseType;
protected $version;
protected $requires = array();
protected $conflicts = array();
protected $provides = array();
protected $replaces = array();
protected $recommends = array();
protected $suggests = array();
/**
* Creates a new in memory package.
*
* @param string $name The package's name
* @param string $version The package's version
* @param string $releaseType The package's release type (beta/rc/stable)
* @param int $id A positive unique id, zero to auto generate
*/
public function __construct($name, $version, $releaseType = 'stable', $id = 0)
{
parent::__construct($name, $id);
$this->releaseType = $releaseType;
$this->version = $version;
}
/**
* Set the release type
*
* @param string $releaseType
*/
public function setReleaseType($releaseType)
{
$this->releaseType = $releaseType;
}
/**
* {@inheritDoc}
*/
public function getReleaseType()
{
return $this->releaseType;
}
/**
* Set the version
*
* @param string $version
*/
public function setVersion($version)
{
$this->version = $version;
}
/**
* {@inheritDoc}
*/
public function getVersion()
{
return $this->version;
}
/**
* Set the required packages
*
* @param array $requires A set of package relations
*/
public function setRequires(array $requires)
{
$this->requires = $requires;
}
/**
* {@inheritDoc}
*/
public function getRequires()
{
return $this->requires;
}
/**
* Set the conflicting packages
*
* @param array $conflicts A set of package relations
*/
public function setConflicts(array $conflicts)
{
$this->conflicts = $conflicts;
}
/**
* {@inheritDoc}
*/
public function getConflicts()
{
return $this->conflicts;
}
/**
* Set the provided virtual packages
*
* @param array $conflicts A set of package relations
*/
public function setProvides(array $provides)
{
$this->provides = $provides;
}
/**
* {@inheritDoc}
*/
public function getProvides()
{
return $this->provides;
}
/**
* Set the packages this one replaces
*
* @param array $conflicts A set of package relations
*/
public function setReplaces(array $replaces)
{
$this->replaces = $replaces;
}
/**
* {@inheritDoc}
*/
public function getReplaces()
{
return $this->replaces;
}
/**
* Set the recommended packages
*
* @param array $conflicts A set of package relations
*/
public function setRecommends(array $recommends)
{
$this->recommends = $recommends;
}
/**
* {@inheritDoc}
*/
public function getRecommends()
{
return $this->recommends;
}
/**
* Set the suggested packages
*
* @param array $conflicts A set of package relations
*/
public function setSuggests(array $suggests)
{
$this->suggests = $suggests;
}
/**
* {@inheritDoc}
*/
public function getSuggests()
{
return $this->suggests;
}
}

View File

@ -0,0 +1,189 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\DependencyResolver;
use Composer\DependencyResolver\RelationConstraint\RelationConstraintInterface;
/**
* @author Nils Adermann <naderman@naderman.de>
*/
abstract class Package
{
protected $name;
protected $id;
static public $incremental_id = 1;
/**
* All descendents' constructors should call this parent constructor
*
* @param string $name The package's name
* @param int $id A positive unique id, zero to auto generate
*/
public function __construct($name, $id = 0)
{
$this->name = $name;
if (!$id) {
$this->id = self::$incremental_id++;
} else {
$this->id = $id;
self::$incremental_id = $id + 1;
}
}
/**
* Returns the package's identifier
*
* @return int Package id - a unique positive number
*/
public function getId()
{
return $this->id;
}
/**
* Returns the package's name without version info, thus not a unique identifier
*
* @return string package name
*/
public function getName()
{
return $this->name;
}
/**
* Returns a set of names that could refer to this package
*
* No version or release type information should be included in any of the
* names. Provided or replaced package names need to be returned as well.
*
* @return array An array of strings refering to this package
*/
public function getNames()
{
$names = array(
$this->getName(),
);
foreach ($this->getProvides() as $relation) {
$names[] = $relation->getToPackageName();
}
foreach ($this->getReplaces() as $relation) {
$names[] = $relation->getToPackageName();
}
return $names;
}
/**
* Checks if the package matches the given constraint directly or through
* provided or replaced packages
*
* @param string $name Name of the package to be matched
* @param RelationConstraintInterface $constraint The constraint to verify
* @return bool Whether this package matches the name and constraint
*/
public function matches($name, RelationConstraintInterface $constraint)
{
if ($this->name === $name) {
return $constraint->matches($this->getReleaseType(), $this->getVersion());
}
foreach ($this->getProvides() as $relation) {
if ($relation->getToPackageName() === $name) {
return $constraint->matches($relation->getToReleaseType(), $relation->getToVersion());
}
}
foreach ($this->getReplaces() as $relation) {
if ($relation->getToPackageName() === $name) {
return $constraint->matches($relation->getToReleaseType(), $relation->getToVersion());
}
}
return false;
}
/**
* Returns the release type of this package, e.g. stable or beta
*
* @return string The release type
*/
abstract public function getReleaseType();
/**
* Returns the version of this package
*
* @return string version
*/
abstract public function getVersion();
/**
* Returns a set of relations to packages which need to be installed before
* this package can be installed
*
* @return array An array of package relations defining required packages
*/
abstract public function getRequires();
/**
* Returns a set of relations to packages which must not be installed at the
* same time as this package
*
* @return array An array of package relations defining conflicting packages
*/
abstract public function getConflicts();
/**
* Returns a set of relations to virtual packages that are provided through
* this package
*
* @return array An array of package relations defining provided packages
*/
abstract public function getProvides();
/**
* Returns a set of relations to packages which can alternatively be
* satisfied by installing this package
*
* @return array An array of package relations defining replaced packages
*/
abstract public function getReplaces();
/**
* Returns a set of relations to packages which are recommended in
* combination with this package.
*
* @return array An array of package relations defining recommended packages
*/
abstract public function getRecommends();
/**
* Returns a set of relations to packages which are suggested in combination
* with this package.
*
* @return array An array of package relations defining suggested packages
*/
abstract public function getSuggests();
/**
* Converts the package into a readable and unique string
*
* @return string
*/
public function __toString()
{
return $this->getName().'-'.$this->getReleaseType().'-'.$this->getVersion();
}
}

View File

@ -0,0 +1,53 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\DependencyResolver;
use Composer\DependencyResolver\RelationConstraint\RelationConstraintInterface;
/**
* @author Nils Adermann <naderman@naderman.de>
*/
class PackageRelation
{
protected $fromPackageName;
protected $toPackageName;
protected $constraint;
protected $description;
public function __construct($fromPackageName, $toPackageName, RelationConstraintInterface $constraint, $description = 'relates to')
{
$this->fromPackageName = $fromPackageName;
$this->toPackageName = $toPackageName;
$this->constraint = $constraint;
$this->description = $description;
}
public function getToPackageName()
{
return $this->toPackageName;
}
public function getFromPackageName()
{
return $this->fromPackageName;
}
public function getConstraint()
{
return $this->constraint;
}
public function __toString()
{
return $this->fromPackageName.' '.$this->description.' '.$this->toPackageName.' ('.$this->constraint.')';
}
}

View File

@ -0,0 +1,25 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\DependencyResolver;
/**
* @author Nils Adermann <naderman@naderman.de>
*/
interface PolicyInterface
{
function allowUninstall();
function allowDowngrade();
function versionCompare(Package $a, Package $b, $operator);
function findUpdatePackages(Solver $solver, Pool $pool, RepositoryInterface $repo, Package $package, $allowAll);
function installable(Solver $solver, Pool $pool, RepositoryInterface $repo, Package $package);
function selectPreferedPackages(array $literals);
}

View File

@ -0,0 +1,79 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\DependencyResolver;
use Composer\DependencyResolver\RelationConstraint\RelationConstraintInterface;
/**
* A package pool contains repositories that provide packages.
*
* @author Nils Adermann <naderman@naderman.de>
*/
class Pool
{
protected $repositories = array();
protected $packages = array();
protected $packageByName = array();
/**
* Adds a repository and its packages to this package pool
*
* @param RepositoryInterface $repo A package repository
*/
public function addRepository(RepositoryInterface $repo)
{
$this->repositories[] = $repo;
foreach ($repo->getPackages() as $package) {
$this->packages[$package->getId()] = $package;
foreach ($package->getNames() as $name) {
if (!isset($this->packageByName[$name])) {
$this->packageByNameByName[$name] = array();
}
$this->packageByName[$name][] = $package;
}
}
}
/**
* Searches all packages providing the given package name and match the constraint
*
* @param string $name The package name to be searched for
* @param RelationConstraintInterface $constraint A constraint that all returned
* packages must match or null to return all
* @return array A set of packages
*/
public function whatProvides($name, RelationConstraintInterface $constraint = null)
{
if (!isset($this->packageByName[$name])) {
return array();
}
$candidates = $this->packageByName[$name];
if (null === $constraint) {
return $candidates;
}
$result = array();
foreach ($candidates as $candidate) {
if ($candidate->matches($name, $constraint)) {
$result[] = $candidate;
}
}
return $result;
}
}

View File

@ -0,0 +1,21 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\DependencyResolver\RelationConstraint;
/**
* @author Nils Adermann <naderman@naderman.de>
*/
interface RelationConstraintInterface
{
function matches($releaseType, $version);
function __toString();
}

View File

@ -0,0 +1,47 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\DependencyResolver\RelationConstraint;
/**
* Constrains a package relation based on package version
*
* Version numbers must be compatible with version_compare
*
* @author Nils Adermann <naderman@naderman.de>
*/
class VersionConstraint implements RelationConstraintInterface
{
private $operator;
private $version;
/**
* Sets operator and version to compare a package with
*
* @param string $operator A comparison operator
* @param string $version A version to compare to
*/
public function __construct($operator, $version)
{
$this->operator = $operator;
$this->version = $version;
}
public function matches($releaseType, $version)
{
return version_compare($version, $this->version, $this->operator);
}
public function __toString()
{
return $this->operator.' '.$this->version;
}
}

View File

@ -0,0 +1,21 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\DependencyResolver;
/**
* @author Nils Adermann <naderman@naderman.de>
*/
interface RepositoryInterface extends \Countable
{
function getPackages();
function contains(Package $package);
}

View File

@ -0,0 +1,57 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\DependencyResolver;
/**
* @author Nils Adermann <naderman@naderman.de>
*/
class Request
{
protected $jobs;
protected $pool;
public function __construct(Pool $pool)
{
$this->pool = $pool;
}
public function install($packageName)
{
$this->addJob($packageName, 'install');
}
public function update($packageName)
{
$this->addJob($packageName, 'update');
}
public function remove($packageName)
{
$this->addJob($packageName, 'remove');
}
protected function addJob($packageName, $cmd)
{
$packages = $this->pool->whatProvides($packageName);
$this->jobs[] = array(
'packages' => $packages,
'cmd' => $cmd,
'packageName' => $packageName,
);
}
public function getJobs()
{
return $this->jobs;
}
}

View File

@ -0,0 +1,161 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\DependencyResolver;
/**
* @author Nils Adermann <naderman@naderman.de>
*/
class Rule
{
protected $disabled;
protected $literals;
protected $type;
public $watch1;
public $watch2;
public $next1;
public $next2;
public function __construct(array $literals, $reason, $reasonData)
{
// sort all packages ascending by id
usort($literals, array($this, 'compareLiteralsById'));
$this->literals = $literals;
$this->reason = $reason;
$this->reasonData = $reasonData;
$this->disabled = false;
$this->watch1 = (count($this->literals) > 0) ? $literals[0]->getId() : 0;
$this->watch2 = (count($this->literals) > 1) ? $literals[1]->getId() : 0;
$this->type = -1;
}
/**
* Checks if this rule is equal to another one
*
* Ignores whether either of the rules is disabled.
*
* @param Rule $rule The rule to check against
* @return bool Whether the rules are equal
*/
public function equals(Rule $rule)
{
if (count($this->literals) != count($rule->literals)) {
return false;
}
for ($i = 0, $n = count($this->literals); $i < $n; $i++) {
if (!$this->literals[$i]->equals($rule->literals[$i])) {
return false;
}
}
return true;
}
public function setType($type)
{
$this->type = $type;
}
public function getType($type)
{
}
public function disable()
{
$this->disabled = true;
}
public function enable()
{
$this->disabled = false;
}
public function isDisabled()
{
return $this->disabled;
}
public function isEnabled()
{
return !$this->disabled;
}
public function getLiterals()
{
return $this->literals;
}
public function isAssertion()
{
return 1 === count($this->literals);
}
public function getNext(Literal $literal)
{
if ($this->watch1->equals($literal)) {
return $this->next1;
} else {
return $this->next2;
}
}
public function getOtherWatch(Literal $literal)
{
if ($this->watch1->equals($literal)) {
return $this->watch2;
} else {
return $this->watch1;
}
}
/**
* Formats a rule as a string of the format (Literal1|Literal2|...)
*
* @return string
*/
public function __toString()
{
$result = '(';
foreach ($this->literals as $i => $literal) {
if ($i != 0) {
$result .= '|';
}
$result .= $literal;
}
$result .= ')';
return $result;
}
/**
* Comparison function for sorting literals by their id
*
* @param Literal $a
* @param Literal $b
* @return int 0 if the literals are equal, 1 if b is larger than a, -1 else
*/
private function compareLiteralsById(Literal $a, Literal $b)
{
if ($a->getId() === $b->getId()) {
return 0;
}
return $a->getId() < $b->getId() ? -1 : 1;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,26 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test\DependencyResolver;
use Composer\DependencyResolver\ArrayRepository;
use Composer\DependencyResolver\MemoryPackage;
class ArrayRepositoryTest extends \PHPUnit_Framework_TestCase
{
public function testAddLiteral()
{
$repo = new ArrayRepository;
$repo->addPackage(new MemoryPackage('foo', '1'));
$this->assertEquals(1, count($repo));
}
}

View File

@ -0,0 +1,23 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test\DependencyResolver;
use Composer\DependencyResolver\Literal;
use Composer\DependencyResolver\MemoryPackage;
class SolvableTest extends \PHPUnit_Framework_TestCase
{
public function testSolvable()
{
$literal = new Literal(new MemoryPackage('foo', '1'), true);
}
}

View File

@ -0,0 +1,29 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test\DependencyResolver;
use Composer\DependencyResolver\MemoryPackage;
class PackageTest extends \PHPUnit_Framework_TestCase
{
public function testPackage()
{
$package = new MemoryPackage('foo', '1', 'beta', 21);
$this->assertEquals('foo', $package->getName());
$this->assertEquals('1', $package->getVersion());
$this->assertEquals('beta', $package->getReleaseType());
$this->assertEquals(21, $package->getId());
$this->assertEquals('foo-beta-1', (string) $package);
}
}

View File

@ -0,0 +1,32 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test\DependencyResolver;
use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\ArrayRepository;
use Composer\DependencyResolver\MemoryPackage;
class PoolTest extends \PHPUnit_Framework_TestCase
{
public function testPool()
{
$pool = new Pool;
$repo = new ArrayRepository;
$package = new MemoryPackage('foo', '1');
$repo->addPackage($package);
$pool->addRepository($repo);
$this->assertEquals(array($package), $pool->whatProvides('foo'));
$this->assertEquals(array($package), $pool->whatProvides('foo'));
}
}

View File

@ -0,0 +1,48 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test\DependencyResolver;
use Composer\DependencyResolver\Request;
use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\ArrayRepository;
use Composer\DependencyResolver\Literal;
use Composer\DependencyResolver\MemoryPackage;
class RequestTest extends \PHPUnit_Framework_TestCase
{
public function testRequestInstallAndRemove()
{
$pool = new Pool;
$repo = new ArrayRepository;
$foo = new MemoryPackage('foo', '1');
$bar = new MemoryPackage('bar', '1');
$foobar = new MemoryPackage('foobar', '1');
$repo->addPackage($foo);
$repo->addPackage($bar);
$repo->addPackage($foobar);
$pool->addRepository($repo);
$request = new Request($pool);
$request->install('foo');
$request->install('bar');
$request->remove('foobar');
$this->assertEquals(
array(
array('packages' => array($foo), 'cmd' => 'install', 'packageName' => 'foo'),
array('packages' => array($bar), 'cmd' => 'install', 'packageName' => 'bar'),
array('packages' => array($foobar), 'cmd' => 'remove', 'packageName' => 'foobar'),
),
$request->getJobs());
}
}

View File

@ -0,0 +1,61 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Composer\Test\DependencyResolver;
use Composer\DependencyResolver\ArrayRepository;
use Composer\DependencyResolver\DefaultPolicy;
use Composer\DependencyResolver\Pool;
use Composer\DependencyResolver\Request;
use Composer\DependencyResolver\MemoryPackage;
use Composer\DependencyResolver\PackageRelation;
use Composer\DependencyResolver\Solver;
use Composer\DependencyResolver\RelationConstraint\VersionConstraint;
class SolverTest extends \PHPUnit_Framework_TestCase
{
public function testSolver()
{
$this->markTestIncomplete('incomplete');
return;
$pool = new Pool;
$repoInstalled = new ArrayRepository;
$repoInstalled->addPackage(new MemoryPackage('old', '1.0'));
$repoInstalled->addPackage(new MemoryPackage('C', '1.0'));
$repo = new ArrayRepository;
$repo->addPackage($packageA = new MemoryPackage('A', '2.0'));
$repo->addPackage($packageB = new MemoryPackage('B', '1.0'));
$repo->addPackage($newPackageB = new MemoryPackage('B', '1.1'));
$repo->addPackage($packageC = new MemoryPackage('C', '1.0'));
$repo->addPackage($oldPackage = new MemoryPackage('old', '1.0'));
$packageA->setRequires(array(new PackageRelation('A', 'B', new VersionConstraint('<', '1.1'), 'requires')));
$pool->addRepository($repoInstalled);
$pool->addRepository($repo);
$request = new Request($pool);
$request->install('A');
$request->update('C');
$request->remove('old');
$policy = new DefaultPolicy;
$solver = new Solver($policy, $pool, $repoInstalled);
$result = $solver->solve($request);
$this->assertTrue($result, 'Request could be solved');
//$transaction = $solver->getTransaction();
// assert ...
}
}

20
tests/bootstrap.php Normal file
View File

@ -0,0 +1,20 @@
<?php
/*
* This file is part of Composer.
*
* (c) Nils Adermann <naderman@naderman.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
spl_autoload_register(function($class)
{
$file = __DIR__.'/../src/'.strtr($class, '\\', '/').'.php';
if (file_exists($file)) {
require $file;
return true;
}
});