From 9f08764e9a2d8e070639eb7a3e5895b9fb07ff7a Mon Sep 17 00:00:00 2001 From: Alexey Prilipko Date: Tue, 19 Jun 2012 23:37:29 +1100 Subject: [PATCH] Add '!=' handling to VersionConstraint::matchSpecific --- .../Package/LinkConstraint/VersionConstraint.php | 16 ++++++++++++++++ .../LinkConstraint/VersionConstraintTest.php | 8 ++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Composer/Package/LinkConstraint/VersionConstraint.php b/src/Composer/Package/LinkConstraint/VersionConstraint.php index 2590aa3df..e88c418b3 100644 --- a/src/Composer/Package/LinkConstraint/VersionConstraint.php +++ b/src/Composer/Package/LinkConstraint/VersionConstraint.php @@ -36,6 +36,10 @@ class VersionConstraint extends SpecificConstraint $operator = '=='; } + if ('<>' === $operator) { + $operator = '!='; + } + $this->operator = $operator; $this->version = $version; } @@ -49,6 +53,18 @@ class VersionConstraint extends SpecificConstraint $noEqualOp = str_replace('=', '', $this->operator); $providerNoEqualOp = str_replace('=', '', $provider->operator); + $isEqualOp = '==' === $this->operator; + $isNonEqualOp = '!=' === $this->operator; + $isProviderEqualOp = '==' === $provider->operator; + $isProviderNonEqualOp = '!=' === $provider->operator; + + // '!=' operator is match when other operator is not '==' operator or version is not match + // these kinds of comparisons always have a solution + if ($isNonEqualOp || $isProviderNonEqualOp) { + return !$isEqualOp && !$isProviderEqualOp + || version_compare($provider->version, $this->version, '!='); + } + // an example for the condition is <= 2.0 & < 1.0 // these kinds of comparisons always have a solution if ($this->operator != '==' && $noEqualOp == $providerNoEqualOp) { diff --git a/tests/Composer/Test/Package/LinkConstraint/VersionConstraintTest.php b/tests/Composer/Test/Package/LinkConstraint/VersionConstraintTest.php index 15c66c8e7..cdd6e67f5 100644 --- a/tests/Composer/Test/Package/LinkConstraint/VersionConstraintTest.php +++ b/tests/Composer/Test/Package/LinkConstraint/VersionConstraintTest.php @@ -27,6 +27,12 @@ class VersionConstraintTest extends \PHPUnit_Framework_TestCase array('<=', '2', '>=', '1'), array('>=', '1', '<=', '2'), array('==', '2', '>=', '2'), + array('!=', '1', '!=', '1'), + array('!=', '1', '==', '2'), + array('!=', '1', '<', '1'), + array('!=', '1', '<=', '1'), + array('!=', '1', '>', '1'), + array('!=', '1', '>=', '1'), ); } @@ -53,6 +59,8 @@ class VersionConstraintTest extends \PHPUnit_Framework_TestCase array('<=', '1', '>=', '2'), array('>=', '2', '<=', '1'), array('==', '2', '<', '2'), + array('!=', '1', '==', '1'), + array('==', '1', '!=', '1'), ); }