Ejemplo n.º 1
0
 public function testEquality()
 {
     $compare = array(array("1.2.3", "v1.2.3", true), array("1.2.3", "=1.2.3", true), array("1.2.3", "v 1.2.3", true), array("1.2.3", "= 1.2.3", true), array("1.2.3", " v1.2.3", true), array("1.2.3", " =1.2.3", true), array("1.2.3", " v 1.2.3", true), array("1.2.3", " = 1.2.3", true), array("1.2.3-0", "v1.2.3-0", true), array("1.2.3-0", "=1.2.3-0", true), array("1.2.3-0", "v 1.2.3-0", true), array("1.2.3-0", "= 1.2.3-0", true), array("1.2.3-0", " v1.2.3-0", true), array("1.2.3-0", " =1.2.3-0", true), array("1.2.3-0", " v 1.2.3-0", true), array("1.2.3-0", " = 1.2.3-0", true), array("1.2.3-01", "v1.2.3-1", true), array("1.2.3-01", "=1.2.3-1", true), array("1.2.3-01", "v 1.2.3-1", true), array("1.2.3-01", "= 1.2.3-1", true), array("1.2.3-01", " v1.2.3-1", true), array("1.2.3-01", " =1.2.3-1", true), array("1.2.3-01", " v 1.2.3-1", true), array("1.2.3-01", " = 1.2.3-1", true), array("1.2.3-beta", "v1.2.3-beta", true), array("1.2.3-beta", "=1.2.3-beta", true), array("1.2.3-beta", "v 1.2.3-beta", true), array("1.2.3-beta", "= 1.2.3-beta", true), array("1.2.3-beta", " v1.2.3-beta", true), array("1.2.3-beta", " =1.2.3-beta", true), array("1.2.3-beta", " v 1.2.3-beta", true), array("1.2.3-beta", " = 1.2.3-beta", true), array("1.2.3-beta+build", " = 1.2.3-beta+otherbuild", true), array("1.2.3+build", " = 1.2.3+otherbuild", true), array("1.2.3-beta+build", "1.2.3-beta+otherbuild", true), array("1.2.3+build", "1.2.3+otherbuild"), array("1.2.3+build", '1.2.3+otherbuild'), array("  v1.2.3+build", "1.2.3+otherbuild"));
     foreach ($compare as $set) {
         $a = $set[0];
         $b = $set[1];
         $loose = isset($set[2]) && $set[2];
         try {
             $this->assertTrue(SemVer\G::eq($a, $b, $loose), "%s > eq('" . $a . "', '" . $b . "')");
             $this->assertFalse(SemVer\G::neq($a, $b, $loose), "%s > !neq('" . $a . "', '" . $b . "')");
             $this->assertTrue(SemVer\G::cmp($a, "==", $b, $loose), "%s > cmp(" . $a . "==" . $b . ")");
             $this->assertFalse(SemVer\G::cmp($a, "!=", $b, $loose), "%s > !cmp(" . $a . "!=" . $b . ")");
             $this->assertFalse(SemVer\G::cmp($a, "===", $b, $loose), "%s > !cmp(" . $a . "===" . $b . ")");
             $this->assertTrue(SemVer\G::cmp($a, "!==", $b, $loose), "%s > cmp(" . $a . "!==" . $b . ")");
             $this->assertFalse(SemVer\G::gt($a, $b, $loose), "%s > !gt('" . $a . "', '" . $b . "')");
             $this->assertTrue(SemVer\G::gte($a, $b, $loose), "%s > gte('" . $a . "', '" . $b . "')");
             $this->assertFalse(SemVer\G::lt($a, $b, $loose), "%s > !lt('" . $a . "', '" . $b . "')");
             $this->assertTrue(SemVer\G::lte($a, $b, $loose), "%s > lte('" . $a . "', '" . $b . "')");
         } catch (\Exception $e) {
             $this->fail("Exception while comparing {$set['0']} and {$set['1']}");
         }
     }
 }
 /**
  * Compare two versions
  * @param  string                   $v1  The first version
  * @param  string                   $cmp The comparator, one of '==', '!=', '>', '>=', '<', '<=', '===', '!=='
  * @param  string                   $v2  The second version
  * @param  bool                     $loose
  * @return bool
  * @throws LogicException
  */
 public static function cmp($v1, $cmp, $v2, $loose = false)
 {
     if ($v1 instanceof self) {
         $v1 = $v1->getVersion();
     }
     if ($v2 instanceof self) {
         $v2 = $v2->getVersion();
     }
     try {
         return G::cmp($v1, $cmp, $v2, $loose);
     } catch (\LogicException $e) {
         throw new \UnexpectedValueException($e->getMessage(), $e->getCode(), $e);
     }
 }