Merge pull request #6168 from rubenrua/blackfire_phpvigo
Improve memory usage resolving dependenciespull/5537/merge
commit
667f1d7815
|
@ -0,0 +1,91 @@
|
|||
<?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\PackageInterface;
|
||||
use Composer\Package\Link;
|
||||
|
||||
/**
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
*/
|
||||
class GenericRule extends Rule
|
||||
{
|
||||
protected $literals;
|
||||
|
||||
/**
|
||||
* @param array $literals
|
||||
* @param int $reason A RULE_* constant describing the reason for generating this rule
|
||||
* @param Link|PackageInterface $reasonData
|
||||
* @param array $job The job this rule was created from
|
||||
*/
|
||||
public function __construct(array $literals, $reason, $reasonData, $job = null)
|
||||
{
|
||||
parent::__construct($reason, $reasonData, $job);
|
||||
|
||||
// sort all packages ascending by id
|
||||
sort($literals);
|
||||
|
||||
$this->literals = $literals;
|
||||
}
|
||||
|
||||
public function getLiterals()
|
||||
{
|
||||
return $this->literals;
|
||||
}
|
||||
|
||||
public function getHash()
|
||||
{
|
||||
$data = unpack('ihash', md5(implode(',', $this->literals), true));
|
||||
|
||||
return $data['hash'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
return $this->literals === $rule->getLiterals();
|
||||
}
|
||||
|
||||
public function isAssertion()
|
||||
{
|
||||
return 1 === count($this->literals);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a rule as a string of the format (Literal1|Literal2|...)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$result = ($this->isDisabled()) ? 'disabled(' : '(';
|
||||
|
||||
foreach ($this->literals as $i => $literal) {
|
||||
if ($i != 0) {
|
||||
$result .= '|';
|
||||
}
|
||||
$result .= $literal;
|
||||
}
|
||||
|
||||
$result .= ')';
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
|
@ -13,13 +13,12 @@
|
|||
namespace Composer\DependencyResolver;
|
||||
|
||||
use Composer\Package\CompletePackage;
|
||||
use Composer\Package\PackageInterface;
|
||||
use Composer\Package\Link;
|
||||
|
||||
/**
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
* @author Ruben Gonzalez <rubenrua@gmail.com>
|
||||
*/
|
||||
class Rule
|
||||
abstract class Rule
|
||||
{
|
||||
// reason constants
|
||||
const RULE_INTERNAL_ALLOW_UPDATE = 1;
|
||||
|
@ -39,27 +38,16 @@ class Rule
|
|||
const BITFIELD_REASON = 8;
|
||||
const BITFIELD_DISABLED = 16;
|
||||
|
||||
/**
|
||||
* READ-ONLY: The literals this rule consists of.
|
||||
* @var array
|
||||
*/
|
||||
public $literals;
|
||||
|
||||
protected $bitfield;
|
||||
protected $reasonData;
|
||||
|
||||
/**
|
||||
* @param array $literals
|
||||
* @param int $reason A RULE_* constant describing the reason for generating this rule
|
||||
* @param Link|PackageInterface $reasonData
|
||||
* @param array $job The job this rule was created from
|
||||
*/
|
||||
public function __construct(array $literals, $reason, $reasonData, $job = null)
|
||||
public function __construct($reason, $reasonData, $job = null)
|
||||
{
|
||||
// sort all packages ascending by id
|
||||
sort($literals);
|
||||
|
||||
$this->literals = $literals;
|
||||
$this->reasonData = $reasonData;
|
||||
|
||||
if ($job) {
|
||||
|
@ -71,18 +59,17 @@ class Rule
|
|||
(255 << self::BITFIELD_TYPE);
|
||||
}
|
||||
|
||||
public function getHash()
|
||||
{
|
||||
$data = unpack('ihash', md5(implode(',', $this->literals), true));
|
||||
abstract public function getLiterals();
|
||||
|
||||
return $data['hash'];
|
||||
}
|
||||
abstract public function getHash();
|
||||
|
||||
public function getJob()
|
||||
{
|
||||
return isset($this->job) ? $this->job : null;
|
||||
}
|
||||
|
||||
abstract public function equals(Rule $rule);
|
||||
|
||||
public function getReason()
|
||||
{
|
||||
return ($this->bitfield & (255 << self::BITFIELD_REASON)) >> self::BITFIELD_REASON;
|
||||
|
@ -104,29 +91,6 @@ class Rule
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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] !== $rule->literals[$i]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function setType($type)
|
||||
{
|
||||
$this->bitfield = ($this->bitfield & ~(255 << self::BITFIELD_TYPE)) | ((255 & $type) << self::BITFIELD_TYPE);
|
||||
|
@ -157,15 +121,14 @@ class Rule
|
|||
return !(($this->bitfield & (255 << self::BITFIELD_DISABLED)) >> self::BITFIELD_DISABLED);
|
||||
}
|
||||
|
||||
public function isAssertion()
|
||||
{
|
||||
return 1 === count($this->literals);
|
||||
}
|
||||
abstract public function isAssertion();
|
||||
|
||||
public function getPrettyString(Pool $pool, array $installedMap = array())
|
||||
{
|
||||
$literals = $this->getLiterals();
|
||||
|
||||
$ruleText = '';
|
||||
foreach ($this->literals as $i => $literal) {
|
||||
foreach ($literals as $i => $literal) {
|
||||
if ($i != 0) {
|
||||
$ruleText .= '|';
|
||||
}
|
||||
|
@ -183,13 +146,12 @@ class Rule
|
|||
return "Remove command rule ($ruleText)";
|
||||
|
||||
case self::RULE_PACKAGE_CONFLICT:
|
||||
$package1 = $pool->literalToPackage($this->literals[0]);
|
||||
$package2 = $pool->literalToPackage($this->literals[1]);
|
||||
$package1 = $pool->literalToPackage($literals[0]);
|
||||
$package2 = $pool->literalToPackage($literals[1]);
|
||||
|
||||
return $package1->getPrettyString().' conflicts with '.$this->formatPackagesUnique($pool, array($package2)).'.';
|
||||
|
||||
case self::RULE_PACKAGE_REQUIRES:
|
||||
$literals = $this->literals;
|
||||
$sourceLiteral = array_shift($literals);
|
||||
$sourcePackage = $pool->literalToPackage($sourceLiteral);
|
||||
|
||||
|
@ -261,7 +223,7 @@ class Rule
|
|||
case self::RULE_INSTALLED_PACKAGE_OBSOLETES:
|
||||
return $ruleText;
|
||||
case self::RULE_PACKAGE_SAME_NAME:
|
||||
return 'Can only install one of: ' . $this->formatPackagesUnique($pool, $this->literals) . '.';
|
||||
return 'Can only install one of: ' . $this->formatPackagesUnique($pool, $literals) . '.';
|
||||
case self::RULE_PACKAGE_IMPLICIT_OBSOLETES:
|
||||
return $ruleText;
|
||||
case self::RULE_LEARNED:
|
||||
|
@ -289,25 +251,4 @@ class Rule
|
|||
|
||||
return implode(', ', $prepared);
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a rule as a string of the format (Literal1|Literal2|...)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$result = ($this->isDisabled()) ? 'disabled(' : '(';
|
||||
|
||||
foreach ($this->literals as $i => $literal) {
|
||||
if ($i != 0) {
|
||||
$result .= '|';
|
||||
}
|
||||
$result .= $literal;
|
||||
}
|
||||
|
||||
$result .= ')';
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
<?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\PackageInterface;
|
||||
use Composer\Package\Link;
|
||||
|
||||
/**
|
||||
* @author Nils Adermann <naderman@naderman.de>
|
||||
*/
|
||||
class Rule2Literals extends Rule
|
||||
{
|
||||
protected $literal1;
|
||||
protected $literal2;
|
||||
|
||||
/**
|
||||
* @param int $literal1
|
||||
* @param int $literal2
|
||||
* @param int $reason A RULE_* constant describing the reason for generating this rule
|
||||
* @param Link|PackageInterface $reasonData
|
||||
* @param array $job The job this rule was created from
|
||||
*/
|
||||
public function __construct($literal1, $literal2, $reason, $reasonData, $job = null)
|
||||
{
|
||||
parent::__construct($reason, $reasonData, $job);
|
||||
|
||||
if ($literal1 < $literal2) {
|
||||
$this->literal1 = $literal1;
|
||||
$this->literal2 = $literal2;
|
||||
} else {
|
||||
$this->literal1 = $literal2;
|
||||
$this->literal2 = $literal1;
|
||||
}
|
||||
}
|
||||
|
||||
public function getLiterals()
|
||||
{
|
||||
return array($this->literal1, $this->literal2);
|
||||
}
|
||||
|
||||
public function getHash()
|
||||
{
|
||||
$data = unpack('ihash', md5($this->literal1.','.$this->literal2, true));
|
||||
|
||||
return $data['hash'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
$literals = $rule->getLiterals();
|
||||
if (2 != count($literals)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->literal1 !== $literals[0]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->literal2 !== $literals[1]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isAssertion()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a rule as a string of the format (Literal1|Literal2|...)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$result = ($this->isDisabled()) ? 'disabled(' : '(';
|
||||
|
||||
$result .= $this->literal1 . '|' . $this->literal2 . ')';
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
|
@ -63,11 +63,17 @@ class RuleSet implements \IteratorAggregate, \Countable
|
|||
// Do not add if rule already exists
|
||||
if (isset($this->rulesByHash[$hash])) {
|
||||
$potentialDuplicates = $this->rulesByHash[$hash];
|
||||
if (is_array($potentialDuplicates)) {
|
||||
foreach ($potentialDuplicates as $potentialDuplicate) {
|
||||
if ($rule->equals($potentialDuplicate)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($rule->equals($potentialDuplicates)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($this->rules[$type])) {
|
||||
|
@ -81,9 +87,12 @@ class RuleSet implements \IteratorAggregate, \Countable
|
|||
$this->nextRuleId++;
|
||||
|
||||
if (!isset($this->rulesByHash[$hash])) {
|
||||
$this->rulesByHash[$hash] = array($rule);
|
||||
} else {
|
||||
$this->rulesByHash[$hash] = $rule;
|
||||
} elseif (is_array($this->rulesByHash[$hash])) {
|
||||
$this->rulesByHash[$hash][] = $rule;
|
||||
} else {
|
||||
$originalRule = $this->rulesByHash[$hash];
|
||||
$this->rulesByHash[$hash] = array($originalRule, $rule);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ class RuleSetGenerator
|
|||
$literals[] = $provider->id;
|
||||
}
|
||||
|
||||
return new Rule($literals, $reason, $reasonData);
|
||||
return new GenericRule($literals, $reason, $reasonData);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -83,7 +83,7 @@ class RuleSetGenerator
|
|||
$literals[] = $package->id;
|
||||
}
|
||||
|
||||
return new Rule($literals, $reason, $job['packageName'], $job);
|
||||
return new GenericRule($literals, $reason, $job['packageName'], $job);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -99,7 +99,7 @@ class RuleSetGenerator
|
|||
*/
|
||||
protected function createRemoveRule(PackageInterface $package, $reason, $job)
|
||||
{
|
||||
return new Rule(array(-$package->id), $reason, $job['packageName'], $job);
|
||||
return new GenericRule(array(-$package->id), $reason, $job['packageName'], $job);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -116,14 +116,14 @@ class RuleSetGenerator
|
|||
* goes with the reason
|
||||
* @return Rule The generated rule
|
||||
*/
|
||||
protected function createConflictRule(PackageInterface $issuer, PackageInterface $provider, $reason, $reasonData = null)
|
||||
protected function createRule2Literals(PackageInterface $issuer, PackageInterface $provider, $reason, $reasonData = null)
|
||||
{
|
||||
// ignore self conflict
|
||||
if ($issuer === $provider) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return new Rule(array(-$issuer->id, -$provider->id), $reason, $reasonData);
|
||||
return new Rule2Literals(-$issuer->id, -$provider->id, $reason, $reasonData);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -210,7 +210,7 @@ class RuleSetGenerator
|
|||
$possibleConflicts = $this->pool->whatProvides($link->getTarget(), $link->getConstraint());
|
||||
|
||||
foreach ($possibleConflicts as $conflict) {
|
||||
$this->addRule(RuleSet::TYPE_PACKAGE, $this->createConflictRule($package, $conflict, Rule::RULE_PACKAGE_CONFLICT, $link));
|
||||
$this->addRule(RuleSet::TYPE_PACKAGE, $this->createRule2Literals($package, $conflict, Rule::RULE_PACKAGE_CONFLICT, $link));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -227,7 +227,7 @@ class RuleSetGenerator
|
|||
|
||||
if (!$this->obsoleteImpossibleForAlias($package, $provider)) {
|
||||
$reason = ($isInstalled) ? Rule::RULE_INSTALLED_PACKAGE_OBSOLETES : Rule::RULE_PACKAGE_OBSOLETES;
|
||||
$this->addRule(RuleSet::TYPE_PACKAGE, $this->createConflictRule($package, $provider, $reason, $link));
|
||||
$this->addRule(RuleSet::TYPE_PACKAGE, $this->createRule2Literals($package, $provider, $reason, $link));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ class RuleSetGenerator
|
|||
$this->addRule(RuleSet::TYPE_PACKAGE, $rule = $this->createRequireRule($package, array($provider), Rule::RULE_PACKAGE_ALIAS, $package));
|
||||
} elseif (!$this->obsoleteImpossibleForAlias($package, $provider)) {
|
||||
$reason = ($package->getName() == $provider->getName()) ? Rule::RULE_PACKAGE_SAME_NAME : Rule::RULE_PACKAGE_IMPLICIT_OBSOLETES;
|
||||
$this->addRule(RuleSet::TYPE_PACKAGE, $rule = $this->createConflictRule($package, $provider, $reason, $package));
|
||||
$this->addRule(RuleSet::TYPE_PACKAGE, $rule = $this->createRule2Literals($package, $provider, $reason, $package));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ class RuleWatchGraph
|
|||
$otherWatch = $node->getOtherWatch($literal);
|
||||
|
||||
if (!$node->getRule()->isDisabled() && !$decisions->satisfy($otherWatch)) {
|
||||
$ruleLiterals = $node->getRule()->literals;
|
||||
$ruleLiterals = $node->getRule()->getLiterals();
|
||||
|
||||
$alternativeLiterals = array_filter($ruleLiterals, function ($ruleLiteral) use ($literal, $otherWatch, $decisions) {
|
||||
return $literal !== $ruleLiteral &&
|
||||
|
|
|
@ -35,7 +35,7 @@ class RuleWatchNode
|
|||
{
|
||||
$this->rule = $rule;
|
||||
|
||||
$literals = $rule->literals;
|
||||
$literals = $rule->getLiterals();
|
||||
|
||||
$this->watch1 = count($literals) > 0 ? $literals[0] : 0;
|
||||
$this->watch2 = count($literals) > 1 ? $literals[1] : 0;
|
||||
|
@ -51,7 +51,7 @@ class RuleWatchNode
|
|||
*/
|
||||
public function watch2OnHighest(Decisions $decisions)
|
||||
{
|
||||
$literals = $this->rule->literals;
|
||||
$literals = $this->rule->getLiterals();
|
||||
|
||||
// if there are only 2 elements, both are being watched anyway
|
||||
if (count($literals) < 3) {
|
||||
|
|
|
@ -97,7 +97,7 @@ class Solver
|
|||
continue;
|
||||
}
|
||||
|
||||
$literals = $rule->literals;
|
||||
$literals = $rule->getLiterals();
|
||||
$literal = $literals[0];
|
||||
|
||||
if (!$this->decisions->decided(abs($literal))) {
|
||||
|
@ -139,7 +139,7 @@ class Solver
|
|||
continue;
|
||||
}
|
||||
|
||||
$assertRuleLiterals = $assertRule->literals;
|
||||
$assertRuleLiterals = $assertRule->getLiterals();
|
||||
$assertRuleLiteral = $assertRuleLiterals[0];
|
||||
|
||||
if (abs($literal) !== abs($assertRuleLiteral)) {
|
||||
|
@ -193,7 +193,7 @@ class Solver
|
|||
|
||||
if (!$this->pool->whatProvides($job['packageName'], $job['constraint'])) {
|
||||
$problem = new Problem($this->pool);
|
||||
$problem->addRule(new Rule(array(), null, null, $job));
|
||||
$problem->addRule(new GenericRule(array(), null, null, $job));
|
||||
$this->problems[] = $problem;
|
||||
}
|
||||
break;
|
||||
|
@ -413,7 +413,7 @@ class Solver
|
|||
while (true) {
|
||||
$this->learnedPool[count($this->learnedPool) - 1][] = $rule;
|
||||
|
||||
foreach ($rule->literals as $literal) {
|
||||
foreach ($rule->getLiterals() as $literal) {
|
||||
// skip the one true literal
|
||||
if ($this->decisions->satisfy($literal)) {
|
||||
continue;
|
||||
|
@ -498,7 +498,7 @@ class Solver
|
|||
);
|
||||
}
|
||||
|
||||
$newRule = new Rule($learnedLiterals, Rule::RULE_LEARNED, $why);
|
||||
$newRule = new GenericRule($learnedLiterals, Rule::RULE_LEARNED, $why);
|
||||
|
||||
return array($learnedLiterals[0], $ruleLevel, $newRule, $why);
|
||||
}
|
||||
|
@ -546,7 +546,7 @@ class Solver
|
|||
$this->problems[] = $problem;
|
||||
|
||||
$seen = array();
|
||||
$literals = $conflictRule->literals;
|
||||
$literals = $conflictRule->getLiterals();
|
||||
|
||||
foreach ($literals as $literal) {
|
||||
// skip the one true literal
|
||||
|
@ -569,7 +569,7 @@ class Solver
|
|||
$problem->addRule($why);
|
||||
$this->analyzeUnsolvableRule($problem, $why);
|
||||
|
||||
$literals = $why->literals;
|
||||
$literals = $why->getLiterals();
|
||||
|
||||
foreach ($literals as $literal) {
|
||||
// skip the one true literal
|
||||
|
@ -703,7 +703,7 @@ class Solver
|
|||
$decisionQueue = array();
|
||||
$noneSatisfied = true;
|
||||
|
||||
foreach ($rule->literals as $literal) {
|
||||
foreach ($rule->getLiterals() as $literal) {
|
||||
if ($this->decisions->satisfy($literal)) {
|
||||
$noneSatisfied = false;
|
||||
break;
|
||||
|
@ -766,7 +766,7 @@ class Solver
|
|||
}
|
||||
|
||||
$rule = $this->rules->ruleById[$i];
|
||||
$literals = $rule->literals;
|
||||
$literals = $rule->getLiterals();
|
||||
|
||||
if ($rule->isDisabled()) {
|
||||
continue;
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
namespace Composer\Test\DependencyResolver;
|
||||
|
||||
use Composer\DependencyResolver\GenericRule;
|
||||
use Composer\DependencyResolver\Rule;
|
||||
use Composer\DependencyResolver\RuleSet;
|
||||
use Composer\DependencyResolver\RuleSetIterator;
|
||||
|
@ -27,11 +28,11 @@ class RuleSetIteratorTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$this->rules = array(
|
||||
RuleSet::TYPE_JOB => array(
|
||||
new Rule(array(), Rule::RULE_JOB_INSTALL, null),
|
||||
new Rule(array(), Rule::RULE_JOB_INSTALL, null),
|
||||
new GenericRule(array(), Rule::RULE_JOB_INSTALL, null),
|
||||
new GenericRule(array(), Rule::RULE_JOB_INSTALL, null),
|
||||
),
|
||||
RuleSet::TYPE_LEARNED => array(
|
||||
new Rule(array(), Rule::RULE_INTERNAL_ALLOW_UPDATE, null),
|
||||
new GenericRule(array(), Rule::RULE_INTERNAL_ALLOW_UPDATE, null),
|
||||
),
|
||||
RuleSet::TYPE_PACKAGE => array(),
|
||||
);
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
namespace Composer\Test\DependencyResolver;
|
||||
|
||||
use Composer\DependencyResolver\GenericRule;
|
||||
use Composer\DependencyResolver\Rule;
|
||||
use Composer\DependencyResolver\RuleSet;
|
||||
use Composer\DependencyResolver\Pool;
|
||||
|
@ -32,11 +33,11 @@ class RuleSetTest extends TestCase
|
|||
$rules = array(
|
||||
RuleSet::TYPE_PACKAGE => array(),
|
||||
RuleSet::TYPE_JOB => array(
|
||||
new Rule(array(1), Rule::RULE_JOB_INSTALL, null),
|
||||
new Rule(array(2), Rule::RULE_JOB_INSTALL, null),
|
||||
new GenericRule(array(1), Rule::RULE_JOB_INSTALL, null),
|
||||
new GenericRule(array(2), Rule::RULE_JOB_INSTALL, null),
|
||||
),
|
||||
RuleSet::TYPE_LEARNED => array(
|
||||
new Rule(array(), Rule::RULE_INTERNAL_ALLOW_UPDATE, null),
|
||||
new GenericRule(array(), Rule::RULE_INTERNAL_ALLOW_UPDATE, null),
|
||||
),
|
||||
);
|
||||
|
||||
|
@ -53,9 +54,9 @@ class RuleSetTest extends TestCase
|
|||
{
|
||||
$rules = array(
|
||||
RuleSet::TYPE_JOB => array(
|
||||
new Rule(array(), Rule::RULE_JOB_INSTALL, null),
|
||||
new Rule(array(), Rule::RULE_JOB_INSTALL, null),
|
||||
new Rule(array(), Rule::RULE_JOB_INSTALL, null),
|
||||
new GenericRule(array(), Rule::RULE_JOB_INSTALL, null),
|
||||
new GenericRule(array(), Rule::RULE_JOB_INSTALL, null),
|
||||
new GenericRule(array(), Rule::RULE_JOB_INSTALL, null),
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -75,15 +76,15 @@ class RuleSetTest extends TestCase
|
|||
{
|
||||
$ruleSet = new RuleSet;
|
||||
|
||||
$ruleSet->add(new Rule(array(), Rule::RULE_JOB_INSTALL, null), 7);
|
||||
$ruleSet->add(new GenericRule(array(), Rule::RULE_JOB_INSTALL, null), 7);
|
||||
}
|
||||
|
||||
public function testCount()
|
||||
{
|
||||
$ruleSet = new RuleSet;
|
||||
|
||||
$ruleSet->add(new Rule(array(1), Rule::RULE_JOB_INSTALL, null), RuleSet::TYPE_JOB);
|
||||
$ruleSet->add(new Rule(array(2), Rule::RULE_JOB_INSTALL, null), RuleSet::TYPE_JOB);
|
||||
$ruleSet->add(new GenericRule(array(1), Rule::RULE_JOB_INSTALL, null), RuleSet::TYPE_JOB);
|
||||
$ruleSet->add(new GenericRule(array(2), Rule::RULE_JOB_INSTALL, null), RuleSet::TYPE_JOB);
|
||||
|
||||
$this->assertEquals(2, $ruleSet->count());
|
||||
}
|
||||
|
@ -92,7 +93,7 @@ class RuleSetTest extends TestCase
|
|||
{
|
||||
$ruleSet = new RuleSet;
|
||||
|
||||
$rule = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule = new GenericRule(array(), Rule::RULE_JOB_INSTALL, null);
|
||||
$ruleSet->add($rule, RuleSet::TYPE_JOB);
|
||||
|
||||
$this->assertSame($rule, $ruleSet->ruleById[0]);
|
||||
|
@ -102,8 +103,8 @@ class RuleSetTest extends TestCase
|
|||
{
|
||||
$ruleSet = new RuleSet;
|
||||
|
||||
$rule1 = new Rule(array(1), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new Rule(array(2), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule1 = new GenericRule(array(1), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new GenericRule(array(2), Rule::RULE_JOB_INSTALL, null);
|
||||
$ruleSet->add($rule1, RuleSet::TYPE_JOB);
|
||||
$ruleSet->add($rule2, RuleSet::TYPE_LEARNED);
|
||||
|
||||
|
@ -117,8 +118,8 @@ class RuleSetTest extends TestCase
|
|||
public function testGetIteratorFor()
|
||||
{
|
||||
$ruleSet = new RuleSet;
|
||||
$rule1 = new Rule(array(1), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new Rule(array(2), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule1 = new GenericRule(array(1), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new GenericRule(array(2), Rule::RULE_JOB_INSTALL, null);
|
||||
|
||||
$ruleSet->add($rule1, RuleSet::TYPE_JOB);
|
||||
$ruleSet->add($rule2, RuleSet::TYPE_LEARNED);
|
||||
|
@ -131,8 +132,8 @@ class RuleSetTest extends TestCase
|
|||
public function testGetIteratorWithout()
|
||||
{
|
||||
$ruleSet = new RuleSet;
|
||||
$rule1 = new Rule(array(1), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new Rule(array(2), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule1 = new GenericRule(array(1), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new GenericRule(array(2), Rule::RULE_JOB_INSTALL, null);
|
||||
|
||||
$ruleSet->add($rule1, RuleSet::TYPE_JOB);
|
||||
$ruleSet->add($rule2, RuleSet::TYPE_LEARNED);
|
||||
|
@ -150,7 +151,7 @@ class RuleSetTest extends TestCase
|
|||
|
||||
$ruleSet = new RuleSet;
|
||||
$literal = $p->getId();
|
||||
$rule = new Rule(array($literal), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule = new GenericRule(array($literal), Rule::RULE_JOB_INSTALL, null);
|
||||
|
||||
$ruleSet->add($rule, RuleSet::TYPE_JOB);
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
namespace Composer\Test\DependencyResolver;
|
||||
|
||||
use Composer\DependencyResolver\GenericRule;
|
||||
use Composer\DependencyResolver\Rule;
|
||||
use Composer\DependencyResolver\RuleSet;
|
||||
use Composer\DependencyResolver\Pool;
|
||||
|
@ -29,7 +30,7 @@ class RuleTest extends TestCase
|
|||
|
||||
public function testGetHash()
|
||||
{
|
||||
$rule = new Rule(array(123), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule = new GenericRule(array(123), Rule::RULE_JOB_INSTALL, null);
|
||||
|
||||
$hash = unpack('ihash', md5('123', true));
|
||||
$this->assertEquals($hash['hash'], $rule->getHash());
|
||||
|
@ -37,31 +38,31 @@ class RuleTest extends TestCase
|
|||
|
||||
public function testEqualsForRulesWithDifferentHashes()
|
||||
{
|
||||
$rule = new Rule(array(1, 2), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new Rule(array(1, 3), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule = new GenericRule(array(1, 2), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new GenericRule(array(1, 3), Rule::RULE_JOB_INSTALL, null);
|
||||
|
||||
$this->assertFalse($rule->equals($rule2));
|
||||
}
|
||||
|
||||
public function testEqualsForRulesWithDifferLiteralsQuantity()
|
||||
{
|
||||
$rule = new Rule(array(1, 12), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new Rule(array(1), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule = new GenericRule(array(1, 12), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new GenericRule(array(1), Rule::RULE_JOB_INSTALL, null);
|
||||
|
||||
$this->assertFalse($rule->equals($rule2));
|
||||
}
|
||||
|
||||
public function testEqualsForRulesWithSameLiterals()
|
||||
{
|
||||
$rule = new Rule(array(1, 12), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new Rule(array(1, 12), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule = new GenericRule(array(1, 12), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new GenericRule(array(1, 12), Rule::RULE_JOB_INSTALL, null);
|
||||
|
||||
$this->assertTrue($rule->equals($rule2));
|
||||
}
|
||||
|
||||
public function testSetAndGetType()
|
||||
{
|
||||
$rule = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule = new GenericRule(array(), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule->setType(RuleSet::TYPE_JOB);
|
||||
|
||||
$this->assertEquals(RuleSet::TYPE_JOB, $rule->getType());
|
||||
|
@ -69,7 +70,7 @@ class RuleTest extends TestCase
|
|||
|
||||
public function testEnable()
|
||||
{
|
||||
$rule = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule = new GenericRule(array(), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule->disable();
|
||||
$rule->enable();
|
||||
|
||||
|
@ -79,7 +80,7 @@ class RuleTest extends TestCase
|
|||
|
||||
public function testDisable()
|
||||
{
|
||||
$rule = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule = new GenericRule(array(), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule->enable();
|
||||
$rule->disable();
|
||||
|
||||
|
@ -89,8 +90,8 @@ class RuleTest extends TestCase
|
|||
|
||||
public function testIsAssertions()
|
||||
{
|
||||
$rule = new Rule(array(1, 12), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new Rule(array(1), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule = new GenericRule(array(1, 12), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new GenericRule(array(1), Rule::RULE_JOB_INSTALL, null);
|
||||
|
||||
$this->assertFalse($rule->isAssertion());
|
||||
$this->assertTrue($rule2->isAssertion());
|
||||
|
@ -103,7 +104,7 @@ class RuleTest extends TestCase
|
|||
$repo->addPackage($p2 = $this->getPackage('baz', '1.1'));
|
||||
$this->pool->addRepository($repo);
|
||||
|
||||
$rule = new Rule(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));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue