Skip to content

Commit e130386

Browse files
author
Alexey Prilipko
committed
Add '<>' operator for Version Parser
1 parent a06ebdd commit e130386

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

src/Composer/Package/Version/VersionParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ private function parseConstraint($constraint)
228228
}
229229

230230
// match operators constraints
231-
if (preg_match('{^(>=?|<=?|==?)?\s*(.*)}', $constraint, $matches)) {
231+
if (preg_match('{^(<>|!=|>=?|<=?|==?)?\s*(.*)}', $constraint, $matches)) {
232232
try {
233233
$version = $this->normalize($matches[2]);
234234

tests/Composer/Test/DependencyResolver/SolverTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,30 @@ public function testSolverInstallWithDeps()
115115
));
116116
}
117117

118+
public function testSolverInstallHonoursNotEqualOperator()
119+
{
120+
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
121+
$this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
122+
$this->repo->addPackage($newPackageB11 = $this->getPackage('B', '1.1'));
123+
$this->repo->addPackage($newPackageB12 = $this->getPackage('B', '1.2'));
124+
$this->repo->addPackage($newPackageB13 = $this->getPackage('B', '1.3'));
125+
126+
$packageA->setRequires(array(
127+
new Link('A', 'B', $this->getVersionConstraint('<=', '1.3'), 'requires'),
128+
new Link('A', 'B', $this->getVersionConstraint('<>', '1.3'), 'requires'),
129+
new Link('A', 'B', $this->getVersionConstraint('!=', '1.2'), 'requires'),
130+
));
131+
132+
$this->reposComplete();
133+
134+
$this->request->install('A');
135+
136+
$this->checkSolverResult(array(
137+
array('job' => 'install', 'package' => $newPackageB11),
138+
array('job' => 'install', 'package' => $packageA),
139+
));
140+
}
141+
118142
public function testSolverInstallWithDepsInOrder()
119143
{
120144
$this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));

tests/Composer/Test/Package/Version/VersionParserTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ public function simpleConstraints()
143143
'match any/2' => array('*.*', new MultiConstraint(array())),
144144
'match any/3' => array('*.x.*', new MultiConstraint(array())),
145145
'match any/4' => array('x.x.x.*', new MultiConstraint(array())),
146+
'not equal' => array('<>1.0.0', new VersionConstraint('<>', '1.0.0.0')),
147+
'not equal/2' => array('!=1.0.0', new VersionConstraint('!=', '1.0.0.0')),
146148
'greater than' => array('>1.0.0', new VersionConstraint('>', '1.0.0.0')),
147149
'lesser than' => array('<1.2.3.4', new VersionConstraint('<', '1.2.3.4')),
148150
'less/eq than' => array('<=1.2.3', new VersionConstraint('<=', '1.2.3.0')),

0 commit comments

Comments
 (0)