Skip to content

Commit

Permalink
bug #11 Fix loosing minor version with beta to stable (sstok)
Browse files Browse the repository at this point in the history
This PR was merged into the 1.0-dev branch.

Discussion
----------

Getting the next 'stable' for 1.2.0-BETA5 should produce 1.2.0 but produced 1.0


Commits
-------

311313d Fix loosing minor version with beta to stable
  • Loading branch information
sstok committed Apr 29, 2024
2 parents bea90d8 + 311313d commit 8cff16f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,15 +257,20 @@ private function getIncreaseOfMetaver(string $stability): self
return new self($this->major, $this->minor, 0, self::$stabilityIndexes[$stability], 1);
}

// Lower stability than current.
return new self($this->major, $this->minor + 1, 0, self::$stabilityIndexes[$stability], 1);
}

private function getIncreaseOfStable(): self
{
if ($this->stability < self::STABILITY_STABLE) {
return new self(max($this->major, 1), 0, 0, self::STABILITY_STABLE);
if ($this->stability === self::STABILITY_STABLE) {
return new self($this->major, $this->minor + 1, 0, self::STABILITY_STABLE);
}

return new self($this->major, $this->minor + 1, 0, self::STABILITY_STABLE);
if ($this->major === 0) {
return new self(1, 0, 0, self::STABILITY_STABLE);
}

return new self($this->major, $this->minor, 0, self::STABILITY_STABLE);
}
}
2 changes: 2 additions & 0 deletions tests/VersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ public function provideExpectedIncreasedVersion(): array
'new next from 0.1.0' => ['0.1.0', '0.2.0', 'next'],
'new next from 0.1.1' => ['0.1.1', '0.2.0', 'next'],
'new next from alpha' => ['1.0.0-alpha6', '1.0.0-alpha7', 'next'],
'new next from alpha 2' => ['1.2.0-alpha6', '1.2.0-alpha7', 'next'],
'new next from beta' => ['1.0.0-beta1', '1.0.0-beta2', 'next'],
'new next from current stable' => ['1.0.0', '1.1.0', 'next'],

Expand All @@ -203,6 +204,7 @@ public function provideExpectedIncreasedVersion(): array
'new stable from 0.0' => ['0.1.0', '1.0.0', 'stable'],
'new stable from alpha' => ['1.0.0-alpha6', '1.0.0', 'stable'],
'new stable from beta' => ['1.0.0-beta1', '1.0.0', 'stable'],
'new stable from beta 2' => ['1.2.0-beta1', '1.2.0', 'stable'],
'new stable from current stable' => ['1.0.0', '1.1.0', 'stable'],
];
}
Expand Down

0 comments on commit 8cff16f

Please sign in to comment.