Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Constraint/MultiConstraint.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,15 @@ private function extractBounds()
$this->lowerBound = $constraint->getLowerBound();
}

if ($constraint->getUpperBound()->compareTo($this->upperBound, $this->isConjunctive() ? '<' : '>')) {
$this->upperBound = $constraint->getUpperBound();
$upperBound = $constraint->getUpperBound();
$cmp = version_compare($upperBound->getVersion(), $this->upperBound->getVersion());
if (0 === $cmp) {
// same version: for upper bounds inclusive is higher (compareTo() assumes lower bounds)
if ($upperBound->isInclusive() === $this->isDisjunctive()) {
$this->upperBound = $upperBound;
}
} elseif ($cmp === ($this->isConjunctive() ? -1 : 1)) {
$this->upperBound = $upperBound;
}
}
}
Expand Down
44 changes: 44 additions & 0 deletions tests/Constraint/MultiConstraintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,35 @@ public static function bounds()
new Bound('1.0.0.0', true),
Bound::positiveInfinity(),
),
'"<" should take precedence "<=" for upper bound when conjunctive' => array(
array(
new Constraint('<', '1.0.0.0'),
new Constraint('<=', '1.0.0.0'),
new Constraint('<', '1.0.0.0'),
),
true,
Bound::zero(),
new Bound('1.0.0.0', false),
),
'"<=" should take precedence "<" for upper bound when disjunctive' => array(
array(
new Constraint('<', '1.0.0.0'),
new Constraint('<=', '1.0.0.0'),
new Constraint('<', '1.0.0.0'),
),
false,
Bound::zero(),
new Bound('1.0.0.0', true),
),
'"==" should extend a "<" upper bound at the same version when disjunctive' => array(
array(
new Constraint('<', '1.0.0.0'),
new Constraint('==', '1.0.0.0'),
),
false,
Bound::zero(),
new Bound('1.0.0.0', true),
),
'Bounds should be limited when conjunctive' => array(
array(
new Constraint('>=', '7.0.0.0'),
Expand Down Expand Up @@ -253,6 +282,21 @@ public static function boundsIntegration()
new Bound('7.2.0.0-dev', true),
new Bound('7.5.0.0-dev', false),
),
'^1.0 || 2.0.0-dev' => array(
'^1.0 || 2.0.0-dev',
new Bound('1.0.0.0-dev', true),
new Bound('2.0.0.0-dev', true),
),
'<=2.0-beta2 || <2.0-beta2' => array(
'<=2.0-beta2 || <2.0-beta2',
Bound::zero(),
new Bound('2.0.0.0-beta2', true),
),
'<2.0-beta2 <=2.0-beta2' => array(
'<2.0-beta2 <=2.0-beta2',
Bound::zero(),
new Bound('2.0.0.0-beta2', false),
),
);
}

Expand Down
Loading