Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
Semver return nex version logic fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorkmaz committed Dec 3, 2018
1 parent b7724f7 commit 7bb0113
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
26 changes: 20 additions & 6 deletions src/Semver.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,35 @@ public function getCurrent() : string

public function getNextPatchRelease() : string
{
return $this->major . '.' . $this->minor . '.' . (++$this->patch);
$patch = $this->patch;
if ($this->preRelease === null) {
$patch++;
}
return $this->major . '.' . $this->minor . '.' . $patch;
}

public function getNextMinorRelease() : string
{
return $this->major . '.' . (++$this->minor) . '.' . $this->patch;
$minor = $this->minor;
$patch = $this->patch;
if ($this->preRelease === null) {
$minor++;

$patch = 0;
}
return $this->major . '.' . $minor . '.' . $patch;
}

public function getNextMajorRelease() : string
{
$major = $this->major;
$minor = $this->minor;
$patch = $this->patch;
if ($this->preRelease === null) {
$this->major++;
$major++;
$minor = 0;
$patch = 0;
}
return $this->major . '.'
. $this->minor . '.'
. $this->patch;
return $major . '.' . $minor . '.' . $patch;
}
}
8 changes: 5 additions & 3 deletions tests/unit/SemverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function shouldReturnNextMinorVersionSuccessfully() : void
{
$version = '2.0.6';
$semver = Semver::createFromString($version);
$this->assertEquals('2.1.6', $semver->getNextMinorRelease());
$this->assertEquals('2.1.0', $semver->getNextMinorRelease());
}

/**
Expand All @@ -55,18 +55,20 @@ public function shouldReturnNextMajorVersionSuccessfully() : void
{
$version = '2.0.6';
$semver = Semver::createFromString($version);
$this->assertEquals('3.0.6', $semver->getNextMajorRelease());
$this->assertEquals('3.0.0', $semver->getNextMajorRelease());
}

/**
* @test
*/
public function shouldReturnNextMajorVersionWithPreReleaseSuccessfully() : void
public function shouldReturnNextVersionsWithPreReleaseSuccessfully() : void
{
$version = '2.0.6-alpha.1';
$semver = Semver::createFromString($version);
$this->assertEquals('2.0.6-alpha.1', $semver->getCurrent());
$this->assertEquals('2.0.6', $semver->getNextMajorRelease());
$this->assertEquals('2.0.6', $semver->getNextMinorRelease());
$this->assertEquals('2.0.6', $semver->getNextPatchRelease());
}

/**
Expand Down

0 comments on commit 7bb0113

Please sign in to comment.