1
0
Fork 0

Fix strings being passed to an int arg, fixes 7.1 build

pull/5144/head
Jordi Boggiano 2016-04-01 11:52:19 +01:00
parent 870dcece1f
commit c74e6df65d
3 changed files with 28 additions and 18 deletions

View File

@ -13,12 +13,15 @@
namespace Composer\DependencyResolver; namespace Composer\DependencyResolver;
use Composer\Package\CompletePackage; use Composer\Package\CompletePackage;
use Composer\Package\PackageInterface;
use Composer\Package\Link;
/** /**
* @author Nils Adermann <naderman@naderman.de> * @author Nils Adermann <naderman@naderman.de>
*/ */
class Rule class Rule
{ {
// reason constants
const RULE_INTERNAL_ALLOW_UPDATE = 1; const RULE_INTERNAL_ALLOW_UPDATE = 1;
const RULE_JOB_INSTALL = 2; const RULE_JOB_INSTALL = 2;
const RULE_JOB_REMOVE = 3; const RULE_JOB_REMOVE = 3;
@ -31,6 +34,7 @@ class Rule
const RULE_LEARNED = 12; const RULE_LEARNED = 12;
const RULE_PACKAGE_ALIAS = 13; const RULE_PACKAGE_ALIAS = 13;
// bitfield defs
const BITFIELD_TYPE = 0; const BITFIELD_TYPE = 0;
const BITFIELD_REASON = 8; const BITFIELD_REASON = 8;
const BITFIELD_DISABLED = 16; const BITFIELD_DISABLED = 16;
@ -44,6 +48,12 @@ class Rule
protected $bitfield; protected $bitfield;
protected $reasonData; 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(array $literals, $reason, $reasonData, $job = null)
{ {
// sort all packages ascending by id // sort all packages ascending by id

View File

@ -27,11 +27,11 @@ class RuleSetIteratorTest extends \PHPUnit_Framework_TestCase
$this->rules = array( $this->rules = array(
RuleSet::TYPE_JOB => array( RuleSet::TYPE_JOB => array(
new Rule(array(), 'job1', null), new Rule(array(), Rule::RULE_JOB_INSTALL, null),
new Rule(array(), 'job2', null), new Rule(array(), Rule::RULE_JOB_INSTALL, null),
), ),
RuleSet::TYPE_LEARNED => array( RuleSet::TYPE_LEARNED => array(
new Rule(array(), 'update1', null), new Rule(array(), Rule::RULE_INTERNAL_ALLOW_UPDATE, null),
), ),
RuleSet::TYPE_PACKAGE => array(), RuleSet::TYPE_PACKAGE => array(),
); );

View File

@ -32,11 +32,11 @@ class RuleSetTest extends TestCase
$rules = array( $rules = array(
RuleSet::TYPE_PACKAGE => array(), RuleSet::TYPE_PACKAGE => array(),
RuleSet::TYPE_JOB => array( RuleSet::TYPE_JOB => array(
new Rule(array(), 'job1', null), new Rule(array(), Rule::RULE_JOB_INSTALL, null),
new Rule(array(), 'job2', null), new Rule(array(), Rule::RULE_JOB_INSTALL, null),
), ),
RuleSet::TYPE_LEARNED => array( RuleSet::TYPE_LEARNED => array(
new Rule(array(), 'update1', null), new Rule(array(), Rule::RULE_INTERNAL_ALLOW_UPDATE, null),
), ),
); );
@ -56,15 +56,15 @@ class RuleSetTest extends TestCase
{ {
$ruleSet = new RuleSet; $ruleSet = new RuleSet;
$ruleSet->add(new Rule(array(), 'job1', null), 7); $ruleSet->add(new Rule(array(), Rule::RULE_JOB_INSTALL, null), 7);
} }
public function testCount() public function testCount()
{ {
$ruleSet = new RuleSet; $ruleSet = new RuleSet;
$ruleSet->add(new Rule(array(), 'job1', null), RuleSet::TYPE_JOB); $ruleSet->add(new Rule(array(), Rule::RULE_JOB_INSTALL, null), RuleSet::TYPE_JOB);
$ruleSet->add(new Rule(array(), 'job2', null), RuleSet::TYPE_JOB); $ruleSet->add(new Rule(array(), Rule::RULE_JOB_INSTALL, null), RuleSet::TYPE_JOB);
$this->assertEquals(2, $ruleSet->count()); $this->assertEquals(2, $ruleSet->count());
} }
@ -73,7 +73,7 @@ class RuleSetTest extends TestCase
{ {
$ruleSet = new RuleSet; $ruleSet = new RuleSet;
$rule = new Rule(array(), 'job1', null); $rule = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
$ruleSet->add($rule, RuleSet::TYPE_JOB); $ruleSet->add($rule, RuleSet::TYPE_JOB);
$this->assertSame($rule, $ruleSet->ruleById[0]); $this->assertSame($rule, $ruleSet->ruleById[0]);
@ -83,8 +83,8 @@ class RuleSetTest extends TestCase
{ {
$ruleSet = new RuleSet; $ruleSet = new RuleSet;
$rule1 = new Rule(array(), 'job1', null); $rule1 = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
$rule2 = new Rule(array(), 'job1', null); $rule2 = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
$ruleSet->add($rule1, RuleSet::TYPE_JOB); $ruleSet->add($rule1, RuleSet::TYPE_JOB);
$ruleSet->add($rule2, RuleSet::TYPE_LEARNED); $ruleSet->add($rule2, RuleSet::TYPE_LEARNED);
@ -98,8 +98,8 @@ class RuleSetTest extends TestCase
public function testGetIteratorFor() public function testGetIteratorFor()
{ {
$ruleSet = new RuleSet; $ruleSet = new RuleSet;
$rule1 = new Rule(array(), 'job1', null); $rule1 = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
$rule2 = new Rule(array(), 'job1', null); $rule2 = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
$ruleSet->add($rule1, RuleSet::TYPE_JOB); $ruleSet->add($rule1, RuleSet::TYPE_JOB);
$ruleSet->add($rule2, RuleSet::TYPE_LEARNED); $ruleSet->add($rule2, RuleSet::TYPE_LEARNED);
@ -112,8 +112,8 @@ class RuleSetTest extends TestCase
public function testGetIteratorWithout() public function testGetIteratorWithout()
{ {
$ruleSet = new RuleSet; $ruleSet = new RuleSet;
$rule1 = new Rule(array(), 'job1', null); $rule1 = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
$rule2 = new Rule(array(), 'job1', null); $rule2 = new Rule(array(), Rule::RULE_JOB_INSTALL, null);
$ruleSet->add($rule1, RuleSet::TYPE_JOB); $ruleSet->add($rule1, RuleSet::TYPE_JOB);
$ruleSet->add($rule2, RuleSet::TYPE_LEARNED); $ruleSet->add($rule2, RuleSet::TYPE_LEARNED);
@ -163,11 +163,11 @@ class RuleSetTest extends TestCase
$ruleSet = new RuleSet; $ruleSet = new RuleSet;
$literal = $p->getId(); $literal = $p->getId();
$rule = new Rule(array($literal), 'job1', null); $rule = new Rule(array($literal), Rule::RULE_JOB_INSTALL, null);
$ruleSet->add($rule, RuleSet::TYPE_JOB); $ruleSet->add($rule, RuleSet::TYPE_JOB);
$this->assertContains('JOB : (install foo 2.1)', $ruleSet->getPrettyString($this->pool)); $this->assertContains('JOB : Install command rule (install foo 2.1)', $ruleSet->getPrettyString($this->pool));
} }
private function getRuleMock() private function getRuleMock()