/**
  * Find the maximum satisfying version
  * @param  array|string                        $versions An array of version objects or version strings, one version string
  * @return \vierbergenlars\SemVer\version|null
  */
 public function maxSatisfying($versions, $loose = false)
 {
     if (!is_array($versions)) {
         $versions = array($versions);
     }
     return new version((string) G::maxSatisfying(new JSArray($versions), $this->range, $loose));
 }
 /**
  * Compares two versions, can be used with usort()
  * @param  string|version $v1 The first version
  * @param  string|version $v2 The second version
  * @param  bool           $loose
  * @return int            0 when they are equal, -1 ifthe second version is smaller, 1 ifthe second version is greater
  */
 public static function compare($v1, $v2, $loose = false)
 {
     if ($v1 instanceof self) {
         $v1 = $v1->getVersion();
     }
     if ($v2 instanceof self) {
         $v2 = $v2->getVersion();
     }
     return G::compare($v1, $v2, $loose);
 }
示例#3
0
 public function testStrictVsLoose()
 {
     $compare = array(array('=1.2.3', '1.2.3'), array('01.02.03', '1.2.3'), array('1.2.3-beta.01', '1.2.3-beta.1'), array('   =1.2.3', '1.2.3'), array('1.2.3foo', '1.2.3-foo'));
     foreach ($compare as $set) {
         $ex = false;
         try {
             new SemVer\SemVer($set[0]);
         } catch (\Exception $e) {
             $ex = true;
         }
         $this->assertTrue($ex, "%s > Creating version with loose version {$set['0']}, without loose flag set should throw exception.");
         $vers = new SemVer\SemVer($set[0], true);
         $this->assertEquals($vers->version->valueOf(), $set[1], "%s > (new version({$set['0']}, true))->getVersion() == {$set['1']}");
         $this->assertTrue(SemVer\G::eq($set[0], $set[1], true), "%s > eq({$set['0']}, {$set['1']}, true)");
         $ex = false;
         try {
             SemVer\G::eq($set[0], $set[1]);
         } catch (\Exception $e) {
             $ex = true;
         }
         $this->assertTrue($ex, "%s > eq({$set['0']}, {$set['1']}) should throw");
     }
 }