Skip to content

Commit

Permalink
Introduce Version::equals
Browse files Browse the repository at this point in the history
  • Loading branch information
theseer committed Nov 30, 2020
1 parent c6bb682 commit 240404b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ public function hasPreReleaseSuffix(): bool {
return $this->preReleaseSuffix !== null;
}

public function equals(Version $other): bool {
return $this->getVersionString() === $other->getVersionString();
}

public function isGreaterThan(Version $version): bool {
if ($version->getMajor()->getValue() > $this->getMajor()->getValue()) {
return false;
Expand Down
15 changes: 15 additions & 0 deletions tests/Unit/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,19 @@ public function versionStringProvider() {
['v0.1', '0.1.0']
];
}

public function testIdenticalVersionsAreConsideredEqual() {
$a = new Version('1.0.0-rc1');
$b = new Version('1.0.0-rc1');

$this->assertTrue($a->equals($b));
}

public function testNonIdenticalVersionsAreNotConsideredEqual() {
$a = new Version('1.0.0-rc1');
$b = new Version('1.0.0-rc2');

$this->assertFalse($a->equals($b));
}

}

0 comments on commit 240404b

Please sign in to comment.