/** * Checks ifa given string is equal to another * @param string|version $v1 The first version * @param string|version $v2 The second version * @param bool $loose * @return boolean */ public static function eq($v1, $v2, $loose = false) { if ($v1 instanceof self) { $v1 = $v1->getVersion(); } if ($v2 instanceof self) { $v2 = $v2->getVersion(); } return G::eq($v1, $v2, $loose); }
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"); } }