mirror of
https://github.com/composer/composer
synced 2025-05-09 00:22:53 +00:00
Reduce calls on Rule::getHash()
This commit is contained in:
parent
00c1b601c8
commit
4a769a785c
3 changed files with 42 additions and 58 deletions
|
@ -32,8 +32,8 @@ class RuleSetTest extends TestCase
|
|||
$rules = array(
|
||||
RuleSet::TYPE_PACKAGE => array(),
|
||||
RuleSet::TYPE_JOB => array(
|
||||
new Rule(array(), Rule::RULE_JOB_INSTALL, null),
|
||||
new Rule(array(), Rule::RULE_JOB_INSTALL, null),
|
||||
new Rule(array(1), Rule::RULE_JOB_INSTALL, null),
|
||||
new Rule(array(2), Rule::RULE_JOB_INSTALL, null),
|
||||
),
|
||||
RuleSet::TYPE_LEARNED => array(
|
||||
new Rule(array(), Rule::RULE_INTERNAL_ALLOW_UPDATE, null),
|
||||
|
@ -49,6 +49,25 @@ class RuleSetTest extends TestCase
|
|||
$this->assertEquals($rules, $ruleSet->getRules());
|
||||
}
|
||||
|
||||
public function testAddIgnoresDuplicates()
|
||||
{
|
||||
$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),
|
||||
)
|
||||
);
|
||||
|
||||
$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)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OutOfBoundsException
|
||||
*/
|
||||
|
@ -63,8 +82,8 @@ class RuleSetTest extends TestCase
|
|||
{
|
||||
$ruleSet = new RuleSet;
|
||||
|
||||
$ruleSet->add(new Rule(array(), Rule::RULE_JOB_INSTALL, null), RuleSet::TYPE_JOB);
|
||||
$ruleSet->add(new Rule(array(), Rule::RULE_JOB_INSTALL, null), RuleSet::TYPE_JOB);
|
||||
$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);
|
||||
|
||||
$this->assertEquals(2, $ruleSet->count());
|
||||
}
|
||||
|
@ -83,8 +102,8 @@ class RuleSetTest extends TestCase
|
|||
{
|
||||
$ruleSet = new RuleSet;
|
||||
|
||||
$rule1 = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule1 = new Rule(array(1), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new Rule(array(2), Rule::RULE_JOB_INSTALL, null);
|
||||
$ruleSet->add($rule1, RuleSet::TYPE_JOB);
|
||||
$ruleSet->add($rule2, RuleSet::TYPE_LEARNED);
|
||||
|
||||
|
@ -98,8 +117,8 @@ class RuleSetTest extends TestCase
|
|||
public function testGetIteratorFor()
|
||||
{
|
||||
$ruleSet = new RuleSet;
|
||||
$rule1 = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule1 = new Rule(array(1), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new Rule(array(2), Rule::RULE_JOB_INSTALL, null);
|
||||
|
||||
$ruleSet->add($rule1, RuleSet::TYPE_JOB);
|
||||
$ruleSet->add($rule2, RuleSet::TYPE_LEARNED);
|
||||
|
@ -112,8 +131,8 @@ class RuleSetTest extends TestCase
|
|||
public function testGetIteratorWithout()
|
||||
{
|
||||
$ruleSet = new RuleSet;
|
||||
$rule1 = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule1 = new Rule(array(1), Rule::RULE_JOB_INSTALL, null);
|
||||
$rule2 = new Rule(array(2), Rule::RULE_JOB_INSTALL, null);
|
||||
|
||||
$ruleSet->add($rule1, RuleSet::TYPE_JOB);
|
||||
$ruleSet->add($rule2, RuleSet::TYPE_LEARNED);
|
||||
|
@ -123,38 +142,6 @@ class RuleSetTest extends TestCase
|
|||
$this->assertSame($rule2, $iterator->current());
|
||||
}
|
||||
|
||||
public function testContainsEqual()
|
||||
{
|
||||
$ruleSet = new RuleSet;
|
||||
|
||||
$rule = $this->getRuleMock();
|
||||
$rule->expects($this->any())
|
||||
->method('getHash')
|
||||
->will($this->returnValue('rule_1_hash'));
|
||||
$rule->expects($this->any())
|
||||
->method('equals')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$rule2 = $this->getRuleMock();
|
||||
$rule2->expects($this->any())
|
||||
->method('getHash')
|
||||
->will($this->returnValue('rule_2_hash'));
|
||||
|
||||
$rule3 = $this->getRuleMock();
|
||||
$rule3->expects($this->any())
|
||||
->method('getHash')
|
||||
->will($this->returnValue('rule_1_hash'));
|
||||
$rule3->expects($this->any())
|
||||
->method('equals')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$ruleSet->add($rule, RuleSet::TYPE_LEARNED);
|
||||
|
||||
$this->assertTrue($ruleSet->containsEqual($rule));
|
||||
$this->assertFalse($ruleSet->containsEqual($rule2));
|
||||
$this->assertFalse($ruleSet->containsEqual($rule3));
|
||||
}
|
||||
|
||||
public function testPrettyString()
|
||||
{
|
||||
$repo = new ArrayRepository;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue