From 9d69bab0804eb65ad99f01f04377d3e3cf65fdb2 Mon Sep 17 00:00:00 2001 From: Dennis Meckel Date: Mon, 13 Feb 2017 20:40:07 +0100 Subject: [PATCH] Added `isMajorRelease()`, `isMinorRelease()`, `isPatchRelease()` and `isPreRelease()` to `SemanticVersionInterface` --- CHANGELOG.md | 10 +++++++ README.md | 27 ++++++++--------- src/SemanticVersion.php | 32 ++++++++++++++++++++ src/SemanticVersionInterface.php | 26 +++++++++++++++-- tests/Examples/ExamplesTest.php | 5 ++++ tests/SemanticVersionTest.php | 50 ++++++++++++++++++++++++++++++++ 6 files changed, 135 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bf0493..17ce286 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,15 @@ This project *surprisingly* adheres to [Semantic Versioning](http://semver.org). No notable changes. +## [1.1.0] - 2017-02-13 + +### Added + +* `SemanticVersionInterface->isMajorRelease()` +* `SemanticVersionInterface->isMinorRelease()` +* `SemanticVersionInterface->isPatchRelease()` +* `SemanticVersionInterface->isPreRelease()` + ## [1.0.0] - 2016-07-24 ### Removed @@ -35,5 +44,6 @@ No notable changes. * Renamed `NoSemanticVersionException` to `InvalidVersionException` [Unreleased]: https://github.com/Rayne/semantic-versioning.php/compare/1.0.0...HEAD +[1.1.0]: https://github.com/Rayne/semantic-versioning.php/compare/1.0.0...1.1.0 [1.0.0]: https://github.com/Rayne/semantic-versioning.php/compare/1.0.0-rc.3...1.0.0 [1.0.0-rc.3]: https://github.com/Rayne/semantic-versioning.php/compare/1.0.0-rc.2...1.0.0-rc.3 \ No newline at end of file diff --git a/README.md b/README.md index fc4471d..2bc5f4b 100644 --- a/README.md +++ b/README.md @@ -9,29 +9,25 @@ A tiny independent library for parsing and comparing semantic versions which is [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Rayne/semantic-versioning.php/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Rayne/semantic-versioning.php/?branch=master) [![License](https://poser.pugx.org/rayne/semantic-versioning/license)](https://packagist.org/packages/rayne/semantic-versioning) -# Dependencies +## Dependencies -## Production +### Production * PHP 5.6 or better -## Development +### Development * Composer * Git * PHPUnit -# Setup +## Setup [Download Composer](https://getcomposer.org/download) and install `rayne/semantic-versioning`. composer require rayne/semantic-versioning ~1.0 -Set the `@dev` stability flag to install the latest development version. - - composer require rayne/semantic-versioning @dev - -# Tests +## Tests 1. Clone the repository @@ -45,7 +41,7 @@ Set the `@dev` stability flag to install the latest development version. ./vendor/bin/phpunit -# Examples +## Examples The library contains the following classes: @@ -58,7 +54,7 @@ The library contains the following classes: The examples are part of the test suite. Have a look at the `tests` directory for more information. -## Interpret semantic versions +### Interpret semantic versions ```php use Rayne\SemanticVersioning\SemanticVersion; @@ -72,9 +68,14 @@ assert( 0 === $version->getPatch()); assert( 'beta' === $version->getPre()); assert( 'exp.sha.5114f85' === $version->getMeta()); assert('1.0.0-beta+exp.sha.5114f85' === $version->getVersion()); + +assert(true === $version->isMajorRelease()); +assert(false === $version->isMinorRelease()); +assert(false === $version->isPatchRelease()); +assert(true === $version->isPreRelease()); ``` -## Compare semantic versions +### Compare semantic versions ```php use Rayne\SemanticVersioning\SemanticComparator; @@ -100,7 +101,7 @@ assert($comparator($release, $candidate) > 0); assert($comparator->compare($release, $candidate) > 0); ``` -## Sort semantic versions +### Sort semantic versions ```php use Rayne\SemanticVersioning\SemanticComparator; diff --git a/src/SemanticVersion.php b/src/SemanticVersion.php index 0f867d0..25f6e6b 100644 --- a/src/SemanticVersion.php +++ b/src/SemanticVersion.php @@ -191,4 +191,36 @@ public function getVersion() { return $this->version; } + + /** + * @inheritdoc + */ + public function isMajorRelease() + { + return $this->minor == 0 && $this->patch == 0; + } + + /** + * @inheritdoc + */ + public function isMinorRelease() + { + return $this->minor > 0 && $this->patch == 0; + } + + /** + * @inheritdoc + */ + public function isPatchRelease() + { + return $this->patch > 0; + } + + /** + * @inheritdoc + */ + public function isPreRelease() + { + return $this->pre !== ''; + } } diff --git a/src/SemanticVersionInterface.php b/src/SemanticVersionInterface.php index 29258b9..bc2eb5e 100644 --- a/src/SemanticVersionInterface.php +++ b/src/SemanticVersionInterface.php @@ -44,7 +44,6 @@ public function getPre(); /** * @return string[] - * * @since 1.0.0-rc.2 */ public function getPreStack(); @@ -56,7 +55,6 @@ public function getMeta(); /** * @return string[] - * * @since 1.0.0-rc.2 */ public function getMetaStack(); @@ -65,4 +63,28 @@ public function getMetaStack(); * @return string */ public function getVersion(); + + /** + * @return bool + * @since 1.1.0-rc.1 + */ + public function isMajorRelease(); + + /** + * @return bool + * @since 1.1.0-rc.1 + */ + public function isMinorRelease(); + + /** + * @return bool + * @since 1.1.0-rc.1 + */ + public function isPatchRelease(); + + /** + * @return bool + * @since 1.1.0-rc.1 + */ + public function isPreRelease(); } diff --git a/tests/Examples/ExamplesTest.php b/tests/Examples/ExamplesTest.php index 933569d..4b5c15f 100644 --- a/tests/Examples/ExamplesTest.php +++ b/tests/Examples/ExamplesTest.php @@ -32,6 +32,11 @@ public function testAttributes() assert('beta' === $version->getPre()); assert('exp.sha.5114f85' === $version->getMeta()); assert('1.0.0-beta+exp.sha.5114f85' === $version->getVersion()); + + assert(true === $version->isMajorRelease()); + assert(false === $version->isMinorRelease()); + assert(false === $version->isPatchRelease()); + assert(true === $version->isPreRelease()); } public function testCompare() diff --git a/tests/SemanticVersionTest.php b/tests/SemanticVersionTest.php index 88e5fe6..9c1b182 100644 --- a/tests/SemanticVersionTest.php +++ b/tests/SemanticVersionTest.php @@ -149,4 +149,54 @@ public function testInvalidVersion($version) { new SemanticVersion($version); } + + public function provideReleaseTypes() + { + return [ + // Major, Minor, Patch + ['0.0.0', true, false, false, false], + ['0.1.0', false, true, false, false], + ['0.1.1', false, false, true, false], + + ['1.0.0', true, false, false, false], + ['1.1.0', false, true, false, false], + ['1.1.1', false, false, true, false], + + // Major, Minor, Patch + Pre-Release + ['0.0.0-pre', true, false, false, true], + ['0.1.0-pre', false, true, false, true], + ['0.1.1-pre', false, false, true, true], + + ['1.0.0-pre', true, false, false, true], + ['1.1.0-pre', false, true, false, true], + ['1.1.1-pre', false, false, true, true], + + // Major, Minor Patch + Meta-Release + ['0.0.0+meta', true, false, false, false], + ['0.1.0+meta', false, true, false, false], + ['0.1.1+meta', false, false, true, false], + + ['1.0.0+meta', true, false, false, false], + ['1.1.0+meta', false, true, false, false], + ['1.1.1+meta', false, false, true, false], + ]; + } + + /** + * @dataProvider provideReleaseTypes + * @param string $version + * @param bool $isMajorRelease + * @param bool $isMinorRelease + * @param bool $isPatchRelease + * @param bool $isPreRelease + */ + public function testReleaseTypes($version, $isMajorRelease, $isMinorRelease, $isPatchRelease, $isPreRelease) + { + $object = new SemanticVersion($version); + + $this->assertSame($isMajorRelease, $object->isMajorRelease()); + $this->assertSame($isMinorRelease, $object->isMinorRelease()); + $this->assertSame($isPatchRelease, $object->isPatchRelease()); + $this->assertSame($isPreRelease, $object->isPreRelease()); + } }