2011-06-26 22:11:57 +00:00
|
|
|
<?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\Test\DependencyResolver;
|
|
|
|
|
2017-02-16 22:00:57 +00:00
|
|
|
use Composer\DependencyResolver\GenericRule;
|
2011-06-26 22:11:57 +00:00
|
|
|
use Composer\DependencyResolver\Rule;
|
|
|
|
use Composer\DependencyResolver\RuleSet;
|
2012-05-19 18:38:56 +00:00
|
|
|
use Composer\DependencyResolver\Pool;
|
2018-09-11 11:33:29 +00:00
|
|
|
use Composer\Package\BasePackage;
|
2012-05-19 18:38:56 +00:00
|
|
|
use Composer\Repository\ArrayRepository;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2011-06-26 22:11:57 +00:00
|
|
|
|
2012-01-22 21:06:09 +00:00
|
|
|
class RuleSetTest extends TestCase
|
2011-06-26 22:11:57 +00:00
|
|
|
{
|
|
|
|
public function testAdd()
|
|
|
|
{
|
|
|
|
$rules = array(
|
|
|
|
RuleSet::TYPE_PACKAGE => array(),
|
|
|
|
RuleSet::TYPE_JOB => array(
|
2017-02-16 22:00:57 +00:00
|
|
|
new GenericRule(array(1), Rule::RULE_JOB_INSTALL, null),
|
|
|
|
new GenericRule(array(2), Rule::RULE_JOB_INSTALL, null),
|
2011-06-26 22:11:57 +00:00
|
|
|
),
|
2012-04-27 16:28:18 +00:00
|
|
|
RuleSet::TYPE_LEARNED => array(
|
2017-02-16 22:00:57 +00:00
|
|
|
new GenericRule(array(), Rule::RULE_INTERNAL_ALLOW_UPDATE, null),
|
2011-06-26 22:11:57 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
$ruleSet = new RuleSet;
|
|
|
|
|
|
|
|
$ruleSet->add($rules[RuleSet::TYPE_JOB][0], RuleSet::TYPE_JOB);
|
2012-04-27 16:28:18 +00:00
|
|
|
$ruleSet->add($rules[RuleSet::TYPE_LEARNED][0], RuleSet::TYPE_LEARNED);
|
2011-06-26 22:11:57 +00:00
|
|
|
$ruleSet->add($rules[RuleSet::TYPE_JOB][1], RuleSet::TYPE_JOB);
|
|
|
|
|
|
|
|
$this->assertEquals($rules, $ruleSet->getRules());
|
|
|
|
}
|
2012-01-22 21:06:09 +00:00
|
|
|
|
2016-09-30 13:06:22 +00:00
|
|
|
public function testAddIgnoresDuplicates()
|
|
|
|
{
|
|
|
|
$rules = array(
|
|
|
|
RuleSet::TYPE_JOB => array(
|
2017-02-16 22:00:57 +00:00
|
|
|
new GenericRule(array(), Rule::RULE_JOB_INSTALL, null),
|
|
|
|
new GenericRule(array(), Rule::RULE_JOB_INSTALL, null),
|
|
|
|
new GenericRule(array(), Rule::RULE_JOB_INSTALL, null),
|
2017-03-08 14:07:29 +00:00
|
|
|
),
|
2016-09-30 13:06:22 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
$ruleSet = new RuleSet;
|
|
|
|
|
|
|
|
$ruleSet->add($rules[RuleSet::TYPE_JOB][0], RuleSet::TYPE_JOB);
|
|
|
|
$ruleSet->add($rules[RuleSet::TYPE_JOB][1], RuleSet::TYPE_JOB);
|
|
|
|
$ruleSet->add($rules[RuleSet::TYPE_JOB][2], RuleSet::TYPE_JOB);
|
|
|
|
|
|
|
|
$this->assertCount(1, $ruleSet->getIteratorFor(array(RuleSet::TYPE_JOB)));
|
|
|
|
}
|
|
|
|
|
2012-01-22 21:06:09 +00:00
|
|
|
/**
|
|
|
|
* @expectedException \OutOfBoundsException
|
|
|
|
*/
|
|
|
|
public function testAddWhenTypeIsNotRecognized()
|
|
|
|
{
|
|
|
|
$ruleSet = new RuleSet;
|
|
|
|
|
2017-02-16 22:00:57 +00:00
|
|
|
$ruleSet->add(new GenericRule(array(), Rule::RULE_JOB_INSTALL, null), 7);
|
2012-01-22 21:06:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testCount()
|
|
|
|
{
|
|
|
|
$ruleSet = new RuleSet;
|
|
|
|
|
2017-02-16 22:00:57 +00:00
|
|
|
$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);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
|
|
|
$this->assertEquals(2, $ruleSet->count());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testRuleById()
|
|
|
|
{
|
|
|
|
$ruleSet = new RuleSet;
|
|
|
|
|
2017-02-16 22:00:57 +00:00
|
|
|
$rule = new GenericRule(array(), Rule::RULE_JOB_INSTALL, null);
|
2012-01-22 21:06:09 +00:00
|
|
|
$ruleSet->add($rule, RuleSet::TYPE_JOB);
|
|
|
|
|
2014-12-01 17:28:45 +00:00
|
|
|
$this->assertSame($rule, $ruleSet->ruleById[0]);
|
2012-01-22 21:06:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetIterator()
|
|
|
|
{
|
|
|
|
$ruleSet = new RuleSet;
|
|
|
|
|
2017-02-16 22:00:57 +00:00
|
|
|
$rule1 = new GenericRule(array(1), Rule::RULE_JOB_INSTALL, null);
|
|
|
|
$rule2 = new GenericRule(array(2), Rule::RULE_JOB_INSTALL, null);
|
2012-01-22 21:06:09 +00:00
|
|
|
$ruleSet->add($rule1, RuleSet::TYPE_JOB);
|
2012-04-27 16:28:18 +00:00
|
|
|
$ruleSet->add($rule2, RuleSet::TYPE_LEARNED);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
|
|
|
$iterator = $ruleSet->getIterator();
|
|
|
|
|
|
|
|
$this->assertSame($rule1, $iterator->current());
|
|
|
|
$iterator->next();
|
|
|
|
$this->assertSame($rule2, $iterator->current());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetIteratorFor()
|
|
|
|
{
|
|
|
|
$ruleSet = new RuleSet;
|
2017-02-16 22:00:57 +00:00
|
|
|
$rule1 = new GenericRule(array(1), Rule::RULE_JOB_INSTALL, null);
|
|
|
|
$rule2 = new GenericRule(array(2), Rule::RULE_JOB_INSTALL, null);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
|
|
|
$ruleSet->add($rule1, RuleSet::TYPE_JOB);
|
2012-04-27 16:28:18 +00:00
|
|
|
$ruleSet->add($rule2, RuleSet::TYPE_LEARNED);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
2012-04-27 16:28:18 +00:00
|
|
|
$iterator = $ruleSet->getIteratorFor(RuleSet::TYPE_LEARNED);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
|
|
|
$this->assertSame($rule2, $iterator->current());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testGetIteratorWithout()
|
|
|
|
{
|
|
|
|
$ruleSet = new RuleSet;
|
2017-02-16 22:00:57 +00:00
|
|
|
$rule1 = new GenericRule(array(1), Rule::RULE_JOB_INSTALL, null);
|
|
|
|
$rule2 = new GenericRule(array(2), Rule::RULE_JOB_INSTALL, null);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
|
|
|
$ruleSet->add($rule1, RuleSet::TYPE_JOB);
|
2012-04-27 16:28:18 +00:00
|
|
|
$ruleSet->add($rule2, RuleSet::TYPE_LEARNED);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
|
|
|
$iterator = $ruleSet->getIteratorWithout(RuleSet::TYPE_JOB);
|
|
|
|
|
|
|
|
$this->assertSame($rule2, $iterator->current());
|
|
|
|
}
|
|
|
|
|
2014-12-01 18:02:50 +00:00
|
|
|
public function testPrettyString()
|
2012-01-22 21:06:09 +00:00
|
|
|
{
|
2020-01-17 14:48:31 +00:00
|
|
|
$pool = new Pool(array(
|
2018-09-12 09:49:09 +00:00
|
|
|
$p = $this->getPackage('foo', '2.1'),
|
|
|
|
));
|
2012-05-19 18:38:56 +00:00
|
|
|
|
2012-01-22 21:06:09 +00:00
|
|
|
$ruleSet = new RuleSet;
|
2012-05-19 18:38:56 +00:00
|
|
|
$literal = $p->getId();
|
2017-02-16 22:00:57 +00:00
|
|
|
$rule = new GenericRule(array($literal), Rule::RULE_JOB_INSTALL, null);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
2012-04-27 16:28:18 +00:00
|
|
|
$ruleSet->add($rule, RuleSet::TYPE_JOB);
|
2012-01-22 21:06:09 +00:00
|
|
|
|
2018-09-12 09:49:09 +00:00
|
|
|
$this->assertContains('JOB : Install command rule (install foo 2.1)', $ruleSet->getPrettyString($pool));
|
2012-01-22 21:06:09 +00:00
|
|
|
}
|
2011-06-26 22:11:57 +00:00
|
|
|
}
|